; 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 }

@__const.Function_sub._mat_B = external hidden unnamed_addr constant [3 x [1 x double]], align 16

; 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 @M_add_sub(double noundef, ptr noundef, double noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @M_free(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) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local double @Function_sub(double noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [3 x [3 x double]], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca [3 x [1 x double]], align 16
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = load double, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %17, double noundef %18, ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 72, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 72, i1 false)
  %21 = getelementptr inbounds [3 x [3 x double]], ptr %8, i32 0, i32 0
  %22 = getelementptr inbounds [3 x double], ptr %21, i32 0, i32 0
  store double 2.000000e+00, ptr %22, align 16
  %23 = getelementptr inbounds [3 x double], ptr %21, i32 0, i32 1
  store double -2.000000e+00, ptr %23, align 8
  %24 = getelementptr inbounds [3 x [3 x double]], ptr %8, i32 0, i32 1
  %25 = getelementptr inbounds [3 x double], ptr %24, i32 0, i32 1
  store double 3.000000e+00, ptr %25, align 8
  %26 = getelementptr inbounds [3 x double], ptr %24, i32 0, i32 2
  store double -2.000000e+00, ptr %26, align 8
  %27 = getelementptr inbounds [3 x [3 x double]], ptr %8, i32 0, i32 2
  %28 = getelementptr inbounds [3 x double], ptr %27, i32 0, i32 2
  store double 2.000000e+00, ptr %28, align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 3, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %29 = load i32, ptr %9, align 4, !tbaa !11
  %30 = load i32, ptr %10, align 4, !tbaa !11
  %31 = getelementptr inbounds [3 x [3 x double]], ptr %8, i64 0, i64 0
  %32 = call ptr @Matrix_gen(i32 noundef %29, i32 noundef %30, ptr noundef %31)
  store ptr %32, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %12, ptr align 16 @__const.Function_sub._mat_B, i64 24, i1 false)
  store i32 3, ptr %9, align 4, !tbaa !11
  store i32 1, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %33 = load i32, ptr %9, align 4, !tbaa !11
  %34 = load i32, ptr %10, align 4, !tbaa !11
  %35 = getelementptr inbounds [3 x [1 x double]], ptr %12, i64 0, i64 0
  %36 = call ptr @Matrix_gen(i32 noundef %33, i32 noundef %34, ptr noundef %35)
  store ptr %36, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load ptr, ptr %11, align 8, !tbaa !9
  %39 = call ptr @M_mul(ptr noundef %37, ptr noundef %38)
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = call ptr @M_T(ptr noundef %40)
  %42 = call ptr @M_mul(ptr noundef %39, ptr noundef %41)
  store ptr %42, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %43 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %43, ptr %15, align 8, !tbaa !9
  %44 = load ptr, ptr %15, align 8, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = load ptr, ptr %13, align 8, !tbaa !9
  %47 = call ptr @M_mul(ptr noundef %45, ptr noundef %46)
  %48 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %44, double noundef -1.000000e+00, ptr noundef %47)
  store ptr %48, ptr %14, align 8, !tbaa !9
  %49 = load ptr, ptr %15, align 8, !tbaa !9
  %50 = call i32 @M_free(ptr noundef %49)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %51 = load ptr, ptr %14, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct._Matrix, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = getelementptr inbounds double, ptr %53, i64 0
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = fsub double %55, 2.000000e+00
  store double %56, ptr %16, align 8, !tbaa !5
  %57 = load ptr, ptr %14, align 8, !tbaa !9
  %58 = call i32 @M_free(ptr noundef %57)
  %59 = load ptr, ptr %11, align 8, !tbaa !9
  %60 = call i32 @M_free(ptr noundef %59)
  %61 = load ptr, ptr %13, align 8, !tbaa !9
  %62 = call i32 @M_free(ptr noundef %61)
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = call i32 @M_free(ptr noundef %63)
  %65 = load double, ptr %16, align 8, !tbaa !5
  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 24, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %65
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"double", !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 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_Matrix", !12, i64 0, !12, i64 4, !10, i64 8}


; 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"

@__const.Function_sub._mat_B = external hidden unnamed_addr constant [3 x [1 x double]], align 16

; 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 @M_add_sub(double noundef, ptr noundef, double noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @M_free(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) #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local double @Function_sub(double noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [3 x [3 x double]], align 16
  %5 = alloca [3 x [1 x double]], align 16
  %6 = tail call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %1, double noundef %0, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %4) #4
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(72) %7, i8 0, i64 48, i1 false)
  store <2 x double> <double 2.000000e+00, double -2.000000e+00>, ptr %4, align 16
  %8 = getelementptr inbounds i8, ptr %4, i64 32
  store <2 x double> <double 3.000000e+00, double -2.000000e+00>, ptr %8, align 16
  %9 = getelementptr inbounds i8, ptr %4, i64 64
  store double 2.000000e+00, ptr %9, align 16
  %10 = call ptr @Matrix_gen(i32 noundef 3, i32 noundef 3, ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %5, ptr noundef nonnull align 16 dereferenceable(24) @__const.Function_sub._mat_B, i64 24, i1 false)
  %11 = call ptr @Matrix_gen(i32 noundef 3, i32 noundef 1, ptr noundef nonnull %5)
  %12 = call ptr @M_mul(ptr noundef %6, ptr noundef %10)
  %13 = call ptr @M_T(ptr noundef %6)
  %14 = call ptr @M_mul(ptr noundef %12, ptr noundef %13)
  %15 = call ptr @M_mul(ptr noundef %6, ptr noundef %11)
  %16 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %14, double noundef -1.000000e+00, ptr noundef %15)
  %17 = call i32 @M_free(ptr noundef %14)
  %18 = getelementptr inbounds i8, ptr %16, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = fadd double %20, -2.000000e+00
  %22 = call i32 @M_free(ptr noundef %16)
  %23 = call i32 @M_free(ptr noundef %10)
  %24 = call i32 @M_free(ptr noundef %11)
  %25 = call i32 @M_free(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #4
  ret double %21
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass