; ModuleID = 'LFortran'
source_filename = "LFortran"
target datalayout = "..."

%string_descriptor = type <{ i8*, i64 }>

@__Wrong_allocation = private unnamed_addr constant [51 x i8] c"Attempting to allocate already allocated variable!\00", align 1
@string_const_data = private constant [1 x i8] c" "
@string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([1 x i8], [1 x i8]* @string_const_data, i32 0, i32 0), i64 1 }>
@string_const_data.1 = private constant [12 x i8] c"--empty-read"
@string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([12 x i8], [12 x i8]* @string_const_data.1, i32 0, i32 0), i64 12 }>
@0 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@string_const_data.3 = private constant [58 x i8] c"Starting empty read. All input to stdin will be discarded."
@string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([58 x i8], [58 x i8]* @string_const_data.3, i32 0, i32 0), i64 58 }>
@1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1
@2 = private unnamed_addr constant [4 x i8] c"yes\00", align 1
@3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@string_const_data.5 = private constant [92 x i8] c"Empty read 1 completed successfully. Starting empty read 2 with unit=5 (stdin), fmt='(I10)'."
@string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([92 x i8], [92 x i8]* @string_const_data.5, i32 0, i32 0), i64 92 }>
@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1
@5 = private unnamed_addr constant [4 x i8] c"yes\00", align 1
@6 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@string_const_data.7 = private constant [78 x i8] c"Empty read 2 completed successfully. Starting empty read 3 with unit=*, fmt=*."
@string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([78 x i8], [78 x i8]* @string_const_data.7, i32 0, i32 0), i64 78 }>
@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1
@8 = private unnamed_addr constant [4 x i8] c"yes\00", align 1
@9 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@string_const_data.9 = private constant [77 x i8] c"Empty read 3 completed successfully. Starting empty read 4 with format label."
@string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([77 x i8], [77 x i8]* @string_const_data.9, i32 0, i32 0), i64 77 }>
@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1
@11 = private unnamed_addr constant [4 x i8] c"yes\00", align 1
@12 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@string_const_data.11 = private constant [93 x i8] c"Empty read 4 completed successfully. Starting empty read 5 with unit passed through variable."
@string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([93 x i8], [93 x i8]* @string_const_data.11, i32 0, i32 0), i64 93 }>
@13 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1
@14 = private unnamed_addr constant [4 x i8] c"yes\00", align 1
@15 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@string_const_data.13 = private constant [77 x i8] c"Empty read 5 completed successfully. All empty reads completed without error."
@string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([77 x i8], [77 x i8]* @string_const_data.13, i32 0, i32 0), i64 77 }>
@16 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1

define void @_lcompilers_get_command_argument_(i32* %number, %string_descriptor* %value) {
.entry:
  %0 = call i8* @_lfortran_get_default_allocator()
  %command_argument_holder = alloca %string_descriptor, align 8
  store %string_descriptor zeroinitializer, %string_descriptor* %command_argument_holder, align 1
  %length_to_allocate = alloca i32, align 4
  store i32 0, i32* %length_to_allocate, align 4
  %1 = load i32, i32* %number, align 4
  %2 = call i32 @_lfortran_get_command_argument_length(i32 %1)
  store i32 %2, i32* %length_to_allocate, align 4
  %3 = load i32, i32* %length_to_allocate, align 4
  %4 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 0
  %5 = load i8*, i8** %4, align 8
  %6 = icmp ne i8* %5, null
  br i1 %6, label %then, label %else

then:                                             ; preds = %.entry
  call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @__Wrong_allocation, i32 0, i32 0))
  call void @exit(i32 1)
  br label %ifcont

else:                                             ; preds = %.entry
  br label %ifcont

ifcont:                                           ; preds = %else, %then
  %7 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 0
  %8 = sext i32 %3 to i64
  %9 = call i8* @_lfortran_get_default_allocator()
  %10 = call i8* @_lfortran_string_malloc_alloc(i8* %9, i64 %8)
  store i8* %10, i8** %7, align 8
  %11 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 1
  %12 = sext i32 %3 to i64
  store i64 %12, i64* %11, align 8
  %13 = load i32, i32* %number, align 4
  %14 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 0
  %15 = load i8*, i8** %14, align 8
  %16 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 0
  %17 = load i8*, i8** %16, align 8
  call void @_lfortran_get_command_argument_value(i32 %13, i8* %17)
  %18 = getelementptr %string_descriptor, %string_descriptor* %value, i32 0, i32 0
  %19 = getelementptr %string_descriptor, %string_descriptor* %value, i32 0, i32 1
  %20 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 0
  %21 = load i8*, i8** %20, align 8
  %22 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 1
  %23 = load i64, i64* %22, align 8
  call void @_lfortran_strcpy_alloc(i8* %0, i8** %18, i64* %19, i8 0, i8 0, i8* %21, i64 %23, i32 1)
  br label %return

return:                                           ; preds = %ifcont
  br label %FINALIZE_SYMTABLE__lcompilers_get_command_argument_

FINALIZE_SYMTABLE__lcompilers_get_command_argument_: ; preds = %return
  br label %Finalize_Variable_command_argument_holder

Finalize_Variable_command_argument_holder:        ; preds = %FINALIZE_SYMTABLE__lcompilers_get_command_argument_
  %24 = getelementptr %string_descriptor, %string_descriptor* %command_argument_holder, i32 0, i32 0
  %25 = load i8*, i8** %24, align 8
  call void @_lfortran_free_alloc(i8* %0, i8* %25)
  ret void
}

declare i32 @_lfortran_get_command_argument_length(i32)

declare void @_lfortran_get_command_argument_value(i32, i8*)

define i32 @_lcompilers_len_trim_str(%string_descriptor* %str) {
.entry:
  %StringItem = alloca %string_descriptor, align 8
  %result = alloca i32, align 4
  %0 = getelementptr %string_descriptor, %string_descriptor* %str, i32 0, i32 1
  %1 = load i64, i64* %0, align 8
  %2 = trunc i64 %1 to i32
  store i32 %2, i32* %result, align 4
  %3 = load i32, i32* %result, align 4
  %4 = icmp ne i32 %3, 0
  br i1 %4, label %then, label %else2

then:                                             ; preds = %.entry
  br label %loop.head

loop.head:                                        ; preds = %ifcont, %then
  %5 = load i32, i32* %result, align 4
  %6 = getelementptr %string_descriptor, %string_descriptor* %str, i32 0, i32 0
  %7 = load i8*, i8** %6, align 8
  %8 = sext i32 %5 to i64
  %9 = sub i64 %8, 1
  %10 = getelementptr i8, i8* %7, i64 %9
  %11 = getelementptr %string_descriptor, %string_descriptor* %StringItem, i32 0, i32 0
  store i8* %10, i8** %11, align 8
  %12 = getelementptr %string_descriptor, %string_descriptor* %StringItem, i32 0, i32 1
  store i64 1, i64* %12, align 8
  %13 = getelementptr %string_descriptor, %string_descriptor* %StringItem, i32 0, i32 0
  %14 = load i8*, i8** %13, align 8
  %15 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8
  %16 = load i8, i8* %14, align 1
  %17 = load i8, i8* %15, align 1
  %18 = icmp eq i8 %16, %17
  br i1 %18, label %loop.body, label %loop.end

loop.body:                                        ; preds = %loop.head
  %19 = load i32, i32* %result, align 4
  %20 = sub i32 %19, 1
  store i32 %20, i32* %result, align 4
  %21 = load i32, i32* %result, align 4
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %then1, label %else

then1:                                            ; preds = %loop.body
  br label %loop.end

unreachable_after_exit:                           ; No predecessors!
  br label %ifcont

else:                                             ; preds = %loop.body
  br label %ifcont

ifcont:                                           ; preds = %else, %unreachable_after_exit
  br label %loop.head

loop.end:                                         ; preds = %then1, %loop.head
  br label %ifcont3

else2:                                            ; preds = %.entry
  br label %ifcont3

ifcont3:                                          ; preds = %else2, %loop.end
  br label %return

return:                                           ; preds = %ifcont3
  br label %FINALIZE_SYMTABLE__lcompilers_len_trim_str

FINALIZE_SYMTABLE__lcompilers_len_trim_str:       ; preds = %return
  %23 = load i32, i32* %result, align 4
  ret i32 %23
}

define void @_lcompilers_trim_str(%string_descriptor* %str, %string_descriptor* %result) {
.entry:
  %0 = call i8* @_lfortran_get_default_allocator()
  %StrSlice_StrView = alloca %string_descriptor, align 8
  %1 = call i32 @_lcompilers_len_trim_str(%string_descriptor* %str)
  %2 = sext i32 %1 to i64
  %3 = sub i64 %2, 1
  %4 = add i64 %3, 1
  %5 = icmp slt i64 %4, 0
  %6 = select i1 %5, i64 0, i64 %4
  %7 = getelementptr %string_descriptor, %string_descriptor* %str, i32 0, i32 0
  %8 = load i8*, i8** %7, align 8
  %StrSliceGEP = getelementptr i8, i8* %8, i64 0
  %9 = getelementptr %string_descriptor, %string_descriptor* %StrSlice_StrView, i32 0, i32 0
  store i8* %StrSliceGEP, i8** %9, align 8
  %10 = getelementptr %string_descriptor, %string_descriptor* %StrSlice_StrView, i32 0, i32 1
  store i64 %6, i64* %10, align 8
  %11 = getelementptr %string_descriptor, %string_descriptor* %result, i32 0, i32 0
  %12 = getelementptr %string_descriptor, %string_descriptor* %result, i32 0, i32 1
  %13 = getelementptr %string_descriptor, %string_descriptor* %StrSlice_StrView, i32 0, i32 0
  %14 = load i8*, i8** %13, align 8
  %15 = getelementptr %string_descriptor, %string_descriptor* %StrSlice_StrView, i32 0, i32 1
  %16 = load i64, i64* %15, align 8
  call void @_lfortran_strcpy_alloc(i8* %0, i8** %11, i64* %12, i8 0, i8 0, i8* %14, i64 %16, i32 1)
  br label %return

return:                                           ; preds = %.entry
  br label %FINALIZE_SYMTABLE__lcompilers_trim_str

FINALIZE_SYMTABLE__lcompilers_trim_str:           ; preds = %return
  ret void
}

declare void @_lcompilers_print_error(i8*, ...)

declare void @exit(i32)

declare i8* @_lfortran_string_malloc_alloc(i8*, i64)

declare i8* @_lfortran_get_default_allocator()

declare void @_lfortran_strcpy_alloc(i8*, i8**, i64*, i8, i8, i8*, i64, i32)

declare void @_lfortran_free_alloc(i8*, i8*)

define i32 @main(i32 %0, i8** %1) {
.entry:
  %2 = call i8* @_lfortran_get_default_allocator()
  %call_arg_value = alloca i32, align 4
  %empty_read = alloca %string_descriptor, align 8
  %__libasr__created__var__0_return_slot = alloca %string_descriptor, align 8
  call void @_lpython_call_initial_functions(i32 %0, i8** %1)
  store %string_descriptor zeroinitializer, %string_descriptor* %__libasr__created__var__0_return_slot, align 1
  store %string_descriptor zeroinitializer, %string_descriptor* %empty_read, align 1
  %3 = getelementptr %string_descriptor, %string_descriptor* %empty_read, i32 0, i32 1
  store i64 32, i64* %3, align 8
  %4 = getelementptr %string_descriptor, %string_descriptor* %empty_read, i32 0, i32 0
  %5 = call i8* @_lfortran_get_default_allocator()
  %6 = call i8* @_lfortran_malloc_alloc(i8* %5, i64 32)
  store i8* %6, i8** %4, align 8
  %unit_num = alloca i32, align 4
  store i32 1, i32* %call_arg_value, align 4
  call void @_lcompilers_get_command_argument_(i32* %call_arg_value, %string_descriptor* %empty_read)
  %7 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 0
  %8 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 1
  %9 = load i8*, i8** %7, align 8
  call void @_lfortran_free_alloc(i8* %2, i8* %9)
  store i8* null, i8** %7, align 8
  store i64 0, i64* %8, align 8
  %10 = call i32 @_lcompilers_len_trim_str(%string_descriptor* %empty_read)
  %11 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 0
  %12 = load i8*, i8** %11, align 8
  %13 = icmp ne i8* %12, null
  br i1 %13, label %then, label %else

then:                                             ; preds = %.entry
  call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @__Wrong_allocation, i32 0, i32 0))
  call void @exit(i32 1)
  br label %ifcont

else:                                             ; preds = %.entry
  br label %ifcont

ifcont:                                           ; preds = %else, %then
  %14 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 0
  %15 = sext i32 %10 to i64
  %16 = call i8* @_lfortran_get_default_allocator()
  %17 = call i8* @_lfortran_string_malloc_alloc(i8* %16, i64 %15)
  store i8* %17, i8** %14, align 8
  %18 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 1
  %19 = sext i32 %10 to i64
  store i64 %19, i64* %18, align 8
  call void @_lcompilers_trim_str(%string_descriptor* %empty_read, %string_descriptor* %__libasr__created__var__0_return_slot)
  %20 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 0
  %21 = load i8*, i8** %20, align 8
  %22 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 1
  %23 = load i64, i64* %22, align 8
  %24 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8
  %25 = call i32 @str_compare(i8* %21, i64 %23, i8* %24, i64 12)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %then1, label %else2

then1:                                            ; preds = %ifcont
  %27 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8
  call void @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %27, i32 58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 1)
  %28 = alloca i32, align 4
  store i32 0, i32* %28, align 4
  %29 = alloca i32, align 4
  call void @_lfortran_empty_read(i32 -2, i32* %28, i32 1)
  %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8
  call void @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %30, i32 92, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @3, i32 0, i32 0), i32 1)
  %31 = alloca i32, align 4
  store i32 0, i32* %31, align 4
  %32 = alloca i32, align 4
  call void @_lfortran_empty_read(i32 -2, i32* %31, i32 1)
  %33 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8
  call void @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %33, i32 78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0), i32 1)
  %34 = alloca i32, align 4
  store i32 0, i32* %34, align 4
  %35 = alloca i32, align 4
  call void @_lfortran_empty_read(i32 -2, i32* %34, i32 1)
  %36 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8
  call void @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %36, i32 77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0), i32 1)
  br label %goto_target

goto_target:                                      ; preds = %then1
  %37 = alloca i32, align 4
  store i32 0, i32* %37, align 4
  %38 = alloca i32, align 4
  call void @_lfortran_empty_read(i32 -2, i32* %37, i32 1)
  %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8
  call void @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %39, i32 93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @12, i32 0, i32 0), i32 1)
  store i32 5, i32* %unit_num, align 4
  %40 = load i32, i32* %unit_num, align 4
  %41 = icmp eq i32 %40, 5
  %42 = select i1 %41, i32 -2, i32 %40
  %43 = alloca i32, align 4
  store i32 0, i32* %43, align 4
  %44 = alloca i32, align 4
  call void @_lfortran_empty_read(i32 %42, i32* %43, i32 1)
  %45 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8
  call void @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @16, i32 0, i32 0), i8* %45, i32 77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1)
  br label %ifcont3

else2:                                            ; preds = %ifcont
  br label %ifcont3

ifcont3:                                          ; preds = %else2, %goto_target
  br label %return

return:                                           ; preds = %ifcont3
  br label %FINALIZE_SYMTABLE_read_83

FINALIZE_SYMTABLE_read_83:                        ; preds = %return
  br label %Finalize_Variable___libasr__created__var__0_return_slot

Finalize_Variable___libasr__created__var__0_return_slot: ; preds = %FINALIZE_SYMTABLE_read_83
  %46 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0_return_slot, i32 0, i32 0
  %47 = load i8*, i8** %46, align 8
  call void @_lfortran_free_alloc(i8* %2, i8* %47)
  br label %Finalize_Variable_empty_read

Finalize_Variable_empty_read:                     ; preds = %Finalize_Variable___libasr__created__var__0_return_slot
  %48 = getelementptr %string_descriptor, %string_descriptor* %empty_read, i32 0, i32 0
  %49 = load i8*, i8** %48, align 8
  call void @_lfortran_free_alloc(i8* %2, i8* %49)
  call void @_lfortran_internal_alloc_finalize()
  ret i32 0
}

declare void @_lpython_call_initial_functions(i32, i8**)

declare i8* @_lfortran_malloc_alloc(i8*, i64)

declare i32 @str_compare(i8*, i64, i8*, i64)

declare void @_lfortran_printf(i8*, i8*, i32, i8*, i32)

declare void @_lfortran_empty_read(i32, i32*, i32)

declare void @_lfortran_internal_alloc_finalize()
