; LLVM IR from rgolubtsov/nonlinear-optimization-algorithms-multilang :: nlp-unconstrained-cli/nelder-mead/c/src (nelmin)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.optimum = type { [20 x double], double, [3 x i32] }

@.str = external hidden unnamed_addr constant [47 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @nelmin(i32 noundef, ptr noundef, double noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare double @f(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [20 x double], align 16
  %10 = alloca double, align 8
  %11 = alloca [20 x double], align 16
  %12 = alloca double, align 8
  %13 = alloca [20 x double], align 16
  %14 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %15 = call i32 @puts(ptr noundef @.str)
  store i32 2, ptr %2, align 4, !tbaa !5
  %16 = getelementptr inbounds [20 x double], ptr %9, i64 0, i64 0
  store double -1.200000e+00, ptr %16, align 16, !tbaa !9
  %17 = getelementptr inbounds [20 x double], ptr %9, i64 0, i64 1
  store double 1.000000e+00, ptr %17, align 8, !tbaa !9
  store double 1.000000e-08, ptr %10, align 8, !tbaa !9
  %18 = getelementptr inbounds [20 x double], ptr %11, i64 0, i64 0
  store double 1.000000e+00, ptr %18, align 16, !tbaa !9
  %19 = getelementptr inbounds [20 x double], ptr %11, i64 0, i64 1
  store double 1.000000e+00, ptr %19, align 8, !tbaa !9
  store i32 10, ptr %3, align 4, !tbaa !5
  store i32 500, ptr %4, align 4, !tbaa !5
  %20 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %35, %0
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp ult i32 %22, %23
  br i1 %24, label %25, label %38

25:                                               ; preds = %21
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [20 x double], ptr %9, i64 0, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [20 x double], ptr %9, i64 0, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %29, double noundef %33)
  br label %35

35:                                               ; preds = %25
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = add i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !5
  br label %21, !llvm.loop !11

38:                                               ; preds = %21
  %39 = getelementptr inbounds [20 x double], ptr %9, i64 0, i64 0
  %40 = call double @f(ptr noundef %39)
  store double %40, ptr %12, align 8, !tbaa !9
  %41 = load double, ptr %12, align 8, !tbaa !9
  %42 = load double, ptr %12, align 8, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %41, double noundef %42)
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = getelementptr inbounds [20 x double], ptr %9, i64 0, i64 0
  %46 = load double, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds [20 x double], ptr %11, i64 0, i64 0
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = call ptr @nelmin(i32 noundef %44, ptr noundef %45, double noundef %46, ptr noundef %47, i32 noundef %48, i32 noundef %49)
  store ptr %50, ptr %14, align 8, !tbaa !13
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %65, %38
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = icmp ult i32 %52, %53
  br i1 %54, label %55, label %68

55:                                               ; preds = %51
  %56 = load ptr, ptr %14, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.optimum, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [20 x double], ptr %57, i64 0, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds [20 x double], ptr %13, i64 0, i64 %63
  store double %61, ptr %64, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %55
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = add i32 %66, 1
  store i32 %67, ptr %5, align 4, !tbaa !5
  br label %51, !llvm.loop !15

68:                                               ; preds = %51
  %69 = load ptr, ptr %14, align 8, !tbaa !13
  %70 = getelementptr inbounds %struct.optimum, ptr %69, i32 0, i32 1
  %71 = load double, ptr %70, align 8, !tbaa !16
  store double %71, ptr %12, align 8, !tbaa !9
  %72 = load ptr, ptr %14, align 8, !tbaa !13
  %73 = getelementptr inbounds %struct.optimum, ptr %72, i32 0, i32 2
  %74 = getelementptr inbounds [3 x i32], ptr %73, i64 0, i64 0
  %75 = load i32, ptr %74, align 8, !tbaa !5
  store i32 %75, ptr %6, align 4, !tbaa !5
  %76 = load ptr, ptr %14, align 8, !tbaa !13
  %77 = getelementptr inbounds %struct.optimum, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds [3 x i32], ptr %77, i64 0, i64 1
  %79 = load i32, ptr %78, align 4, !tbaa !5
  store i32 %79, ptr %7, align 4, !tbaa !5
  %80 = load ptr, ptr %14, align 8, !tbaa !13
  %81 = getelementptr inbounds %struct.optimum, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds [3 x i32], ptr %81, i64 0, i64 2
  %83 = load i32, ptr %82, align 8, !tbaa !5
  store i32 %83, ptr %8, align 4, !tbaa !5
  %84 = load ptr, ptr %14, align 8, !tbaa !13
  call void @free(ptr noundef %84) #4
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %85)
  %87 = call i32 @puts(ptr noundef @.str.5)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %102, %68
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = load i32, ptr %2, align 4, !tbaa !5
  %91 = icmp ult i32 %89, %90
  br i1 %91, label %92, label %105

92:                                               ; preds = %88
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds [20 x double], ptr %13, i64 0, i64 %94
  %96 = load double, ptr %95, align 8, !tbaa !9
  %97 = load i32, ptr %5, align 4, !tbaa !5
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds [20 x double], ptr %13, i64 0, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !9
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %96, double noundef %100)
  br label %102

102:                                              ; preds = %92
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = add i32 %103, 1
  store i32 %104, ptr %5, align 4, !tbaa !5
  br label %88, !llvm.loop !18

105:                                              ; preds = %88
  %106 = load double, ptr %12, align 8, !tbaa !9
  %107 = load double, ptr %12, align 8, !tbaa !9
  %108 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, double noundef %106, double noundef %107)
  %109 = load i32, ptr %6, align 4, !tbaa !5
  %110 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %109)
  %111 = load i32, ptr %7, align 4, !tbaa !5
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %111)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

declare i32 @puts(ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = !{!17, !10, i64 160}
!17 = !{!"optimum", !7, i64 0, !10, i64 160, !7, i64 168}
!18 = distinct !{!18, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [47 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @nelmin(i32 noundef, ptr noundef, double noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare double @f(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [20 x double], align 16
  %2 = alloca [20 x double], align 16
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %2) #5
  %3 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  store <2 x double> <double -1.200000e+00, double 1.000000e+00>, ptr %1, align 16, !tbaa !5
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %2, align 16, !tbaa !5
  %4 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef -1.200000e+00, double noundef -1.200000e+00)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef 1.000000e+00, double noundef 1.000000e+00)
  %7 = call double @f(ptr noundef nonnull %1) #5
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %7, double noundef %7)
  %9 = call ptr @nelmin(i32 noundef 2, ptr noundef nonnull %1, double noundef 1.000000e-08, ptr noundef nonnull %2, i32 noundef 10, i32 noundef 500)
  %.sroa.0.0.copyload = load double, ptr %9, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 8
  %.sroa.4.0.copyload = load double, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 160
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %9, i64 168
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %9, i64 172
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %9, i64 176
  %17 = load i32, ptr %16, align 8, !tbaa !11
  call void @free(ptr noundef %9) #5
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %17)
  %19 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %.sroa.0.0.copyload, double noundef %.sroa.0.0.copyload)
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %.sroa.4.0.copyload, double noundef %.sroa.4.0.copyload)
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, double noundef %11, double noundef %11)
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %13)
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %15)
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %1) #5
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 160}
!10 = !{!"optimum", !7, i64 0, !6, i64 160, !7, i64 168}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass