; ModuleID = 'LFortran'
source_filename = "LFortran"

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

@0 = private unnamed_addr constant [2 x i8] c" \00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [5 x i8] c"(g0)\00", align 1
@3 = private unnamed_addr constant [3 x i8] c"%s\00", align 1
@4 = private unnamed_addr constant [2 x i8] c" \00", align 1
@5 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1
@7 = private unnamed_addr constant [19 x i8] c"10.000000000000000\00", align 1
@8 = private unnamed_addr constant [11 x i8] c"ERROR STOP\00", align 1
@9 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1

define i32 @_lcompilers_len_trim_str(i8** %str) {
.entry:
  %result = alloca i32, align 4
  %0 = load i8*, i8** %str, align 8
  %1 = alloca i8*, align 8
  store i8* %0, i8** %1, align 8
  %2 = call i32 @_lfortran_str_len(i8** %1)
  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 = load i8*, i8** %str, align 8
  %7 = sext i32 %5 to i64
  %8 = call i8* @_lfortran_str_item(i8* %6, i64 %7)
  %9 = alloca i8*, align 8
  store i8* %8, i8** %9, align 8
  %10 = alloca i8*, align 8
  store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i8** %10, align 8
  %11 = call i1 @_lpython_str_compare_eq(i8** %9, i8** %10)
  br i1 %11, label %loop.body, label %loop.end

loop.body:                                        ; preds = %loop.head
  %12 = load i32, i32* %result, align 4
  %13 = sub i32 %12, 1
  store i32 %13, i32* %result, align 4
  %14 = load i32, i32* %result, align 4
  %15 = icmp eq i32 %14, 0
  br i1 %15, 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
  %16 = load i32, i32* %result, align 4
  ret i32 %16
}

define i8* @_lcompilers_trim_str(i8** %str) {
.entry:
  %result = alloca i8*, align 8
  %0 = call i32 @_lcompilers_len_trim_str(i8** %str)
  %1 = add i32 %0, 1
  %2 = call i8* @_lfortran_malloc(i32 %1)
  call void @_lfortran_string_init(i32 %1, i8* %2)
  store i8* %2, i8** %result, align 8
  %3 = load i8*, i8** %str, align 8
  %4 = call i32 @_lcompilers_len_trim_str(i8** %str)
  %5 = call i8* @_lfortran_str_slice(i8* %3, i32 0, i32 %4, i32 1, i1 true, i1 true)
  call void @_lfortran_strcpy_pointer_string(i8** %result, i8* %5)
  br label %return

return:                                           ; preds = %.entry
  %6 = load i8*, i8** %result, align 8
  ret i8* %6
}

define void @__module_testdrive_derived_types_32_real_dp_to_string(double* %val, %string_descriptor* %string) {
.entry:
  %buffer = alloca i8*, align 8
  %0 = call i8* @_lfortran_malloc(i32 129)
  call void @_lfortran_string_init(i32 129, i8* %0)
  store i8* %0, i8** %buffer, align 8
  %1 = load i8*, i8** %buffer, align 8
  %buffer_len = alloca i32, align 4
  store i32 128, i32* %buffer_len, align 4
  %negative_one_constant = alloca i64, align 8
  store i64 -1, i64* %negative_one_constant, align 4
  %2 = alloca i32*, align 8
  store i32* null, i32** %2, align 8
  %3 = load i32*, i32** %2, align 8
  %4 = load double, double* %val, align 8
  %5 = call i8* (i32, i8*, ...) @_lcompilers_string_format_fortran(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i32 5, double %4)
  call void (i8**, i64*, i64*, i32*, i8*, ...) @_lfortran_string_write(i8** %buffer, i64* %negative_one_constant, i64* %negative_one_constant, i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @3, i32 0, i32 0), i8* %5)
  %casted_string_ptr_to_desc = alloca %string_descriptor, align 8
  %6 = getelementptr %string_descriptor, %string_descriptor* %casted_string_ptr_to_desc, i32 0, i32 0
  %7 = getelementptr %string_descriptor, %string_descriptor* %casted_string_ptr_to_desc, i32 0, i32 1
  %8 = getelementptr %string_descriptor, %string_descriptor* %casted_string_ptr_to_desc, i32 0, i32 2
  %9 = call i8* @_lcompilers_trim_str(i8** %buffer)
  store i8* %9, i8** %6, align 8
  store i64 -1, i64* %7, align 4
  store i64 -1, i64* %8, align 4
  %10 = getelementptr %string_descriptor, %string_descriptor* %string, i32 0, i32 0
  %11 = getelementptr %string_descriptor, %string_descriptor* %string, i32 0, i32 1
  %12 = getelementptr %string_descriptor, %string_descriptor* %string, i32 0, i32 2
  %13 = getelementptr %string_descriptor, %string_descriptor* %casted_string_ptr_to_desc, i32 0, i32 0
  %14 = load i8*, i8** %13, align 8
  call void @_lfortran_strcpy_descriptor_string(i8** %10, i8* %14, i64* %11, i64* %12)
  br label %return

return:                                           ; preds = %.entry
  ret void
}

declare i8* @_lfortran_malloc(i32)

declare void @_lfortran_string_init(i32, i8*)

declare i8* @_lcompilers_string_format_fortran(i32, i8*, ...)

declare void @_lfortran_string_write(i8**, i64*, i64*, i32*, i8*, ...)

declare void @_lfortran_strcpy_descriptor_string(i8**, i8*, i64*, i64*)

declare i32 @_lfortran_str_len(i8**)

declare i8* @_lfortran_str_item(i8*, i64)

declare i1 @_lpython_str_compare_eq(i8**, i8**)

declare i8* @_lfortran_str_slice(i8*, i32, i32, i32, i1, i1)

declare void @_lfortran_strcpy_pointer_string(i8**, i8*)

define i32 @main(i32 %0, i8** %1) {
.entry:
  call void @_lpython_call_initial_functions(i32 %0, i8** %1)
  %__libasr__created__var__0__func_call_res = alloca %string_descriptor, align 8
  %2 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 0
  store i8* null, i8** %2, align 8
  %3 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 1
  store i64 0, i64* %3, align 4
  %4 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 2
  store i64 0, i64* %4, align 4
  %__libasr__created__var__1__func_call_res = alloca %string_descriptor, align 8
  %5 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 0
  store i8* null, i8** %5, align 8
  %6 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 1
  store i64 0, i64* %6, align 4
  %7 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 2
  store i64 0, i64* %7, align 4
  %value = alloca double, align 8
  store double 1.000000e+01, double* %value, align 8
  %8 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 0
  %9 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 1
  %10 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 2
  %11 = load i8*, i8** %8, align 8
  call void @_lfortran_free(i8* %11)
  store i8* null, i8** %8, align 8
  store i64 0, i64* %9, align 4
  store i64 0, i64* %10, align 4
  call void @__module_testdrive_derived_types_32_real_dp_to_string(double* %value, %string_descriptor* %__libasr__created__var__0__func_call_res)
  %12 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 0
  %13 = load i8*, i8** %12, align 8
  %14 = call i8* (i32, i8*, ...) @_lcompilers_string_format_fortran(i32 2, i8* null, i32 7, i8* %13)
  call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0))
  %15 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 0
  %16 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 1
  %17 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 2
  %18 = load i8*, i8** %15, align 8
  call void @_lfortran_free(i8* %18)
  store i8* null, i8** %15, align 8
  store i64 0, i64* %16, align 4
  store i64 0, i64* %17, align 4
  call void @__module_testdrive_derived_types_32_real_dp_to_string(double* %value, %string_descriptor* %__libasr__created__var__1__func_call_res)
  %19 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 0
  %20 = load i8*, i8** %19, align 8
  %21 = alloca i8*, align 8
  store i8* %20, i8** %21, align 8
  %22 = alloca i8*, align 8
  store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @7, i32 0, i32 0), i8** %22, align 8
  %23 = call i1 @_lpython_str_compare_noteq(i8** %21, i8** %22)
  br i1 %23, label %then, label %else

then:                                             ; preds = %.entry
  call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @8, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0))
  call void @exit(i32 1)
  br label %ifcont

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

ifcont:                                           ; preds = %else, %then
  %24 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 0
  %25 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 1
  %26 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__0__func_call_res, i32 0, i32 2
  %27 = load i8*, i8** %24, align 8
  call void @_lfortran_free(i8* %27)
  store i8* null, i8** %24, align 8
  store i64 0, i64* %25, align 4
  store i64 0, i64* %26, align 4
  %28 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 0
  %29 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 1
  %30 = getelementptr %string_descriptor, %string_descriptor* %__libasr__created__var__1__func_call_res, i32 0, i32 2
  %31 = load i8*, i8** %28, align 8
  call void @_lfortran_free(i8* %31)
  store i8* null, i8** %28, align 8
  store i64 0, i64* %29, align 4
  store i64 0, i64* %30, align 4
  call void @_lpython_free_argv()
  br label %return

return:                                           ; preds = %ifcont
  ret i32 0
}

declare void @_lpython_call_initial_functions(i32, i8**)

declare void @_lfortran_free(i8*)

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

declare i1 @_lpython_str_compare_noteq(i8**, i8**)

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

declare void @exit(i32)

declare void @_lpython_free_argv()
