; LLVM IR from Amoiensis/Optimization-Algorithm :: [Unconstrained_Optimization]无约束优化/[Gradient_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._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: nounwind uwtable
define dso_local double @Function(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [3 x [3 x double]], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca [3 x [1 x double]], align 16
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 72, i1 false)
  %12 = getelementptr inbounds [3 x [3 x double]], ptr %3, i32 0, i32 0
  %13 = getelementptr inbounds [3 x double], ptr %12, i32 0, i32 0
  store double 2.000000e+00, ptr %13, align 16
  %14 = getelementptr inbounds [3 x double], ptr %12, i32 0, i32 1
  store double -2.000000e+00, ptr %14, align 8
  %15 = getelementptr inbounds [3 x [3 x double]], ptr %3, i32 0, i32 1
  %16 = getelementptr inbounds [3 x double], ptr %15, i32 0, i32 1
  store double 3.000000e+00, ptr %16, align 8
  %17 = getelementptr inbounds [3 x double], ptr %15, i32 0, i32 2
  store double -2.000000e+00, ptr %17, align 8
  %18 = getelementptr inbounds [3 x [3 x double]], ptr %3, i32 0, i32 2
  %19 = getelementptr inbounds [3 x double], ptr %18, i32 0, i32 2
  store double 2.000000e+00, ptr %19, align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 3, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 3, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = getelementptr inbounds [3 x [3 x double]], ptr %3, i64 0, i64 0
  %23 = call ptr @Matrix_gen(i32 noundef %20, i32 noundef %21, ptr noundef %22)
  store ptr %23, ptr %6, align 8, !tbaa !5
  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.Function._mat_B, i64 24, i1 false)
  store i32 3, ptr %4, align 4, !tbaa !9
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = getelementptr inbounds [3 x [1 x double]], ptr %7, i64 0, i64 0
  %27 = call ptr @Matrix_gen(i32 noundef %24, i32 noundef %25, ptr noundef %26)
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call ptr @M_mul(ptr noundef %28, ptr noundef %29)
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = call ptr @M_T(ptr noundef %31)
  %33 = call ptr @M_mul(ptr noundef %30, ptr noundef %32)
  store ptr %33, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %34, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call ptr @M_mul(ptr noundef %36, ptr noundef %37)
  %39 = call ptr @M_add_sub(double noundef 1.000000e+00, ptr noundef %35, double noundef -1.000000e+00, ptr noundef %38)
  store ptr %39, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = call i32 @M_free(ptr noundef %40)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._Matrix, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds double, ptr %44, i64 0
  %46 = load double, ptr %45, align 8, !tbaa !13
  %47 = fsub double %46, 2.000000e+00
  store double %47, ptr %11, align 8, !tbaa !13
  %48 = load double, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, 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
  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 72, ptr %3) #4
  ret double %48
}

; 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

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_Matrix", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}


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

; 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

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