; LLVM IR from Amoiensis/Optimization-Algorithm :: [Direct_Method]直接法/[Univariate_Search_Method]坐标轮换法 (main)

; 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._Matrix = type { i32, i32, ptr }

@.str.16 = external hidden unnamed_addr constant [6 x i8], align 1
@__const.main._mat_X = external hidden unnamed_addr constant [1 x [3 x double]], align 16
@.str.27 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

; 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
declare dso_local ptr @Matrix_copy(ptr noundef) #0

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

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

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

declare i32 @system(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [1 x [3 x double]], align 16
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca double, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca double, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr @Function, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 16 @__const.main._mat_X, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 1.800000e-03, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 1.000000e-02, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 1.000000e-02, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 1, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 3, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = load i32, ptr %12, align 4, !tbaa !5
  %24 = getelementptr inbounds [1 x [3 x double]], ptr %7, i64 0, i64 0
  %25 = call ptr @Matrix_gen(i32 noundef %22, i32 noundef %23, ptr noundef %24)
  store ptr %25, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %26 = load double, ptr %8, align 8, !tbaa !11
  %27 = fmul double 1.000000e+01, %26
  store double %27, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store ptr null, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store ptr null, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store ptr null, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %28 = load ptr, ptr %13, align 8, !tbaa !9
  %29 = call ptr @Matrix_copy(ptr noundef %28)
  store ptr %29, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  store double 0.000000e+00, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  store i32 0, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %61, %2
  %31 = load double, ptr %14, align 8, !tbaa !11
  %32 = load double, ptr %8, align 8, !tbaa !11
  %33 = fcmp ogt double %31, %32
  br i1 %33, label %34, label %83

34:                                               ; preds = %30
  %35 = load i32, ptr %20, align 4, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = srem i32 %35, %36
  store i32 %37, ptr %21, align 4, !tbaa !5
  %38 = load i32, ptr %20, align 4, !tbaa !5
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %34
  %41 = load ptr, ptr %18, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct._Matrix, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = load i32, ptr %21, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  store double 1.000000e+00, ptr %46, align 8, !tbaa !11
  br label %61

47:                                               ; preds = %34
  %48 = load ptr, ptr %18, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct._Matrix, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i32, ptr %21, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %50, i64 %53
  store double 0.000000e+00, ptr %54, align 8, !tbaa !11
  %55 = load ptr, ptr %18, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct._Matrix, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = load i32, ptr %21, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %57, i64 %59
  store double 1.000000e+00, ptr %60, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %47, %40
  %62 = load ptr, ptr %13, align 8, !tbaa !9
  %63 = load ptr, ptr %18, align 8, !tbaa !9
  %64 = call double @Bisection_Method(ptr noundef %62, ptr noundef %63)
  store double %64, ptr %10, align 8, !tbaa !11
  %65 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %65, ptr %17, align 8, !tbaa !9
  %66 = load ptr, ptr %13, align 8, !tbaa !9
  %67 = call i32 @M_print(ptr noundef %66)
  %68 = load ptr, ptr %17, align 8, !tbaa !9
  %69 = load double, ptr %10, align 8, !tbaa !11
  %70 = load ptr, ptr %18, align 8, !tbaa !9
  %71 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %68, double noundef %69, ptr noundef %70)
  store ptr %71, ptr %13, align 8, !tbaa !9
  %72 = load ptr, ptr %13, align 8, !tbaa !9
  %73 = call i32 @M_print(ptr noundef %72)
  %74 = load ptr, ptr %13, align 8, !tbaa !9
  %75 = load ptr, ptr %17, align 8, !tbaa !9
  %76 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %74, double noundef 1.000000e+00, ptr noundef %75)
  store ptr %76, ptr %16, align 8, !tbaa !9
  %77 = load ptr, ptr %16, align 8, !tbaa !9
  %78 = call double @M_norm(ptr noundef %77, i32 noundef 2)
  store double %78, ptr %14, align 8, !tbaa !11
  %79 = load ptr, ptr %17, align 8, !tbaa !9
  %80 = call i32 @M_free(ptr noundef %79)
  %81 = load i32, ptr %20, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %20, align 4, !tbaa !5
  br label %30, !llvm.loop !15

83:                                               ; preds = %30
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.27)
  %85 = load ptr, ptr %13, align 8, !tbaa !9
  %86 = call i32 @M_print(ptr noundef %85)
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = load ptr, ptr %13, align 8, !tbaa !9
  %89 = call double %87(ptr noundef %88)
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.28, double noundef %89)
  %91 = call i32 @system(ptr noundef @.str.16)
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_Matrix", !6, i64 0, !6, i64 4, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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.16 = external hidden unnamed_addr constant [6 x i8], align 1
@__const.main._mat_X = external hidden unnamed_addr constant [1 x [3 x double]], align 16
@.str.27 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @Matrix_gen(i32 noundef, i32 noundef, ptr 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

; 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
declare dso_local ptr @Matrix_copy(ptr noundef) local_unnamed_addr #0

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca [1 x [3 x double]], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %3, ptr noundef nonnull align 16 dereferenceable(24) @__const.main._mat_X, i64 24, i1 false)
  %4 = call ptr @Matrix_gen(i32 noundef 1, i32 noundef 3, ptr noundef nonnull %3)
  %5 = call ptr @Matrix_copy(ptr noundef %4)
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  store double 1.000000e+00, ptr %7, align 8, !tbaa !11
  %8 = call double @Bisection_Method(ptr noundef %4, ptr noundef nonnull %5)
  %9 = call i32 @M_print(ptr noundef %4)
  %10 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %4, double noundef %8, ptr noundef nonnull %5)
  %11 = call i32 @M_print(ptr noundef %10)
  %12 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %10, double noundef 1.000000e+00, ptr noundef %4)
  %13 = call double @M_norm(ptr noundef %12, i32 noundef 2)
  %14 = call i32 @M_free(ptr noundef %4)
  %15 = fcmp ogt double %13, 1.800000e-03
  br i1 %15, label %.peel.next, label %.loopexit

.peel.next:                                       ; preds = %2, %.peel.next
  %.033 = phi i32 [ %28, %.peel.next ], [ 1, %2 ]
  %.03032 = phi ptr [ %23, %.peel.next ], [ %10, %2 ]
  %16 = urem i32 %.033, 3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = zext nneg i32 %16 to i64
  %19 = getelementptr double, ptr %17, i64 %18
  %20 = getelementptr i8, ptr %19, i64 -8
  store <2 x double> <double 0.000000e+00, double 1.000000e+00>, ptr %20, align 8, !tbaa !11
  %21 = call double @Bisection_Method(ptr noundef %.03032, ptr noundef nonnull %5)
  %22 = call i32 @M_print(ptr noundef %.03032)
  %23 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %.03032, double noundef %21, ptr noundef nonnull %5)
  %24 = call i32 @M_print(ptr noundef %23)
  %25 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %23, double noundef 1.000000e+00, ptr noundef %.03032)
  %26 = call double @M_norm(ptr noundef %25, i32 noundef 2)
  %27 = call i32 @M_free(ptr noundef %.03032)
  %28 = add nuw nsw i32 %.033, 1
  %29 = fcmp ogt double %26, 1.800000e-03
  br i1 %29, label %.peel.next, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.peel.next, %2
  %.lcssa = phi ptr [ %10, %2 ], [ %23, %.peel.next ]
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.27)
  %31 = call i32 @M_print(ptr noundef %.lcssa)
  %32 = call double @Function(ptr noundef %.lcssa)
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.28, double noundef %32)
  %34 = call i32 @system(ptr noundef nonnull @.str.16) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

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 = { 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 #3 = { nofree "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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!6 = !{!"_Matrix", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass