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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @M_T(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %7, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._Matrix, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._Matrix, ptr %11, i32 0, i32 1
  store i32 %10, ptr %12, align 4, !tbaa !12
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._Matrix, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._Matrix, ptr %16, i32 0, i32 0
  store i32 %15, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._Matrix, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = sext i32 %20 to i64
  %22 = mul i64 8, %21
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._Matrix, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = mul i64 %22, %26
  %28 = call noalias ptr @malloc(i64 noundef %27) #4
  store ptr %28, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._Matrix, ptr %30, i32 0, i32 2
  store ptr %29, ptr %31, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %73, %1
  %33 = load i32, ptr %5, align 4, !tbaa !14
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._Matrix, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = icmp slt i32 %33, %36
  br i1 %37, label %38, label %76

38:                                               ; preds = %32
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %39

39:                                               ; preds = %69, %38
  %40 = load i32, ptr %6, align 4, !tbaa !14
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._Matrix, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = icmp slt i32 %40, %43
  br i1 %44, label %45, label %72

45:                                               ; preds = %39
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._Matrix, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %6, align 4, !tbaa !14
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._Matrix, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = mul nsw i32 %49, %52
  %54 = load i32, ptr %5, align 4, !tbaa !14
  %55 = add nsw i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %48, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !15
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !14
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._Matrix, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !12
  %64 = mul nsw i32 %60, %63
  %65 = load i32, ptr %6, align 4, !tbaa !14
  %66 = add nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %59, i64 %67
  store double %58, ptr %68, align 8, !tbaa !15
  br label %69

69:                                               ; preds = %45
  %70 = load i32, ptr %6, align 4, !tbaa !14
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !14
  br label %39, !llvm.loop !17

72:                                               ; preds = %39
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %5, align 4, !tbaa !14
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !14
  br label %32, !llvm.loop !19

76:                                               ; preds = %32
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 #2 = { 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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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, !11, i64 0}
!10 = !{!"_Matrix", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(readwrite, argmem: read) uwtable
define dso_local noalias noundef ptr @M_T(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %3, ptr %4, align 4, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  store i32 %6, ptr %2, align 8, !tbaa !5
  %7 = sext i32 %3 to i64
  %8 = shl nsw i64 %7, 3
  %9 = sext i32 %6 to i64
  %10 = mul i64 %8, %9
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #2
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %11, ptr %12, align 8, !tbaa !12
  %13 = icmp sgt i32 %6, 0
  %14 = icmp sgt i32 %3, 0
  %or.cond = and i1 %13, %14
  br i1 %or.cond, label %.preheader.lr.ph.split.us, label %._crit_edge26

.preheader.lr.ph.split.us:                        ; preds = %1
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = zext nneg i32 %3 to i64
  %wide.trip.count32 = zext nneg i32 %6 to i64
  %xtraiter = and i64 %17, 3
  %18 = icmp ult i32 %3, 4
  %unroll_iter = and i64 %17, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %._crit_edge.us ], [ 0, %.preheader.lr.ph.split.us ]
  %19 = mul nuw nsw i64 %indvars.iv29, %17
  %invariant.gep = getelementptr inbounds double, ptr %16, i64 %indvars.iv29
  %invariant.gep34 = getelementptr inbounds double, ptr %11, i64 %19
  br i1 %18, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %20 = mul nuw nsw i64 %indvars.iv, %17
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %20
  %21 = load double, ptr %gep, align 8, !tbaa !13
  %gep35 = getelementptr inbounds double, ptr %invariant.gep34, i64 %indvars.iv
  store double %21, ptr %gep35, align 8, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = mul nuw nsw i64 %indvars.iv.next, %17
  %gep.1 = getelementptr inbounds double, ptr %invariant.gep, i64 %22
  %23 = load double, ptr %gep.1, align 8, !tbaa !13
  %gep35.1 = getelementptr inbounds double, ptr %invariant.gep34, i64 %indvars.iv.next
  store double %23, ptr %gep35.1, align 8, !tbaa !13
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %24 = mul nuw nsw i64 %indvars.iv.next.1, %17
  %gep.2 = getelementptr inbounds double, ptr %invariant.gep, i64 %24
  %25 = load double, ptr %gep.2, align 8, !tbaa !13
  %gep35.2 = getelementptr inbounds double, ptr %invariant.gep34, i64 %indvars.iv.next.1
  store double %25, ptr %gep35.2, align 8, !tbaa !13
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %26 = mul nuw nsw i64 %indvars.iv.next.2, %17
  %gep.3 = getelementptr inbounds double, ptr %invariant.gep, i64 %26
  %27 = load double, ptr %gep.3, align 8, !tbaa !13
  %gep35.3 = getelementptr inbounds double, ptr %invariant.gep34, i64 %indvars.iv.next.2
  store double %27, ptr %gep35.3, align 8, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.3, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %28 = mul nuw nsw i64 %indvars.iv.epil, %17
  %gep.epil = getelementptr inbounds double, ptr %invariant.gep, i64 %28
  %29 = load double, ptr %gep.epil, align 8, !tbaa !13
  %gep35.epil = getelementptr inbounds double, ptr %invariant.gep34, i64 %indvars.iv.epil
  store double %29, ptr %gep35.epil, align 8, !tbaa !13
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !17

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count32
  br i1 %exitcond33.not, label %._crit_edge26, label %.preheader.us, !llvm.loop !19

._crit_edge26:                                    ; preds = %._crit_edge.us, %1
  ret ptr %2
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #1 = { nofree nounwind memory(readwrite, argmem: read) 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 #2 = { nounwind allocsize(0) }

!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, !7, i64 0}
!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 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass