; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhouhongkun/HomeWork/MatrixOperation/main.ll (Z9addMatrix7_MatrixS_)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, ptr } @_Z10initMatrixii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, ptr } @_Z9addMatrix7_MatrixS_(i64 %0, ptr %1, i64 %2, ptr %3) #1 {
  %5 = alloca %struct._Matrix, align 8
  %6 = alloca %struct._Matrix, align 8
  %7 = alloca %struct._Matrix, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = getelementptr inbounds { i64, ptr }, ptr %6, i32 0, i32 0
  store i64 %0, ptr %11, align 8
  %12 = getelementptr inbounds { i64, ptr }, ptr %6, i32 0, i32 1
  store ptr %1, ptr %12, align 8
  %13 = getelementptr inbounds { i64, ptr }, ptr %7, i32 0, i32 0
  store i64 %2, ptr %13, align 8
  %14 = getelementptr inbounds { i64, ptr }, ptr %7, i32 0, i32 1
  store ptr %3, ptr %14, align 8
  %15 = getelementptr inbounds %struct._Matrix, ptr %6, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._Matrix, ptr %6, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = call { i64, ptr } @_Z10initMatrixii(i32 noundef %16, i32 noundef %18)
  %20 = getelementptr inbounds { i64, ptr }, ptr %5, i32 0, i32 0
  %21 = extractvalue { i64, ptr } %19, 0
  store i64 %21, ptr %20, align 8
  %22 = getelementptr inbounds { i64, ptr }, ptr %5, i32 0, i32 1
  %23 = extractvalue { i64, ptr } %19, 1
  store ptr %23, ptr %22, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %24

24:                                               ; preds = %72, %4
  %25 = load i32, ptr %8, align 4, !tbaa !12
  %26 = getelementptr inbounds %struct._Matrix, ptr %6, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !5
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %24
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %75

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %31

31:                                               ; preds = %68, %30
  %32 = load i32, ptr %10, align 4, !tbaa !12
  %33 = getelementptr inbounds %struct._Matrix, ptr %6, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %71

37:                                               ; preds = %31
  %38 = getelementptr inbounds %struct._Matrix, ptr %6, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = load i32, ptr %8, align 4, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = load i32, ptr %10, align 4, !tbaa !12
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !12
  %48 = getelementptr inbounds %struct._Matrix, ptr %7, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load i32, ptr %8, align 4, !tbaa !12
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load i32, ptr %10, align 4, !tbaa !12
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !12
  %58 = add nsw i32 %47, %57
  %59 = getelementptr inbounds %struct._Matrix, ptr %5, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = load i32, ptr %8, align 4, !tbaa !12
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %60, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !14
  %65 = load i32, ptr %10, align 4, !tbaa !12
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  store i32 %58, ptr %67, align 4, !tbaa !12
  br label %68

68:                                               ; preds = %37
  %69 = load i32, ptr %10, align 4, !tbaa !12
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !12
  br label %31, !llvm.loop !15

71:                                               ; preds = %36
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %8, align 4, !tbaa !12
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %8, align 4, !tbaa !12
  br label %24, !llvm.loop !17

75:                                               ; preds = %29
  %76 = load { i64, ptr }, ptr %5, align 8
  ret { i64, ptr } %76
}

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


; 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 nounwind uwtable
declare dso_local { i64, ptr } @_Z10initMatrixii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, ptr } @_Z9addMatrix7_MatrixS_(i64 %0, ptr nocapture readonly %1, i64 %2, ptr nocapture readonly %3) local_unnamed_addr #0 {
  %.sroa.010.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.3.0.extract.shift = lshr i64 %0, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %5 = tail call { i64, ptr } @_Z10initMatrixii(i32 noundef %.sroa.010.0.extract.trunc, i32 noundef %.sroa.3.0.extract.trunc)
  %6 = extractvalue { i64, ptr } %5, 1
  %7 = icmp sgt i32 %.sroa.010.0.extract.trunc, 0
  %8 = icmp sgt i32 %.sroa.3.0.extract.trunc, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge17

.preheader.us.preheader:                          ; preds = %4
  %wide.trip.count23 = and i64 %0, 2147483647
  %min.iters.check = icmp ult i64 %0, 34359738368
  %n.vec = and i64 %.sroa.3.0.extract.shift, 2147483640
  %cmp.n = icmp eq i64 %.sroa.3.0.extract.shift, %n.vec
  %xtraiter = and i64 %.sroa.3.0.extract.shift, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv20 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next21, %._crit_edge.us ]
  %9 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv20
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv20
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv20
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us
  %15 = ptrtoint ptr %14 to i64
  %16 = ptrtoint ptr %12 to i64
  %17 = ptrtoint ptr %10 to i64
  %18 = sub i64 %15, %17
  %diff.check = icmp ult i64 %18, 32
  %19 = sub i64 %15, %16
  %diff.check25 = icmp ult i64 %19, 32
  %conflict.rdx = or i1 %diff.check, %diff.check25
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %20 = getelementptr inbounds i32, ptr %10, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %wide.load = load <4 x i32>, ptr %20, align 4, !tbaa !9
  %wide.load26 = load <4 x i32>, ptr %21, align 4, !tbaa !9
  %22 = getelementptr inbounds i32, ptr %12, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %wide.load27 = load <4 x i32>, ptr %22, align 4, !tbaa !9
  %wide.load28 = load <4 x i32>, ptr %23, align 4, !tbaa !9
  %24 = add nsw <4 x i32> %wide.load27, %wide.load
  %25 = add nsw <4 x i32> %wide.load28, %wide.load26
  %26 = getelementptr inbounds i32, ptr %14, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  store <4 x i32> %24, ptr %26, align 4, !tbaa !9
  store <4 x i32> %25, ptr %27, align 4, !tbaa !9
  %index.next = add nuw i64 %index, 8
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %29 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.prol
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv.prol
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = add nsw i32 %32, %30
  %34 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv.prol
  store i32 %33, ptr %34, align 4, !tbaa !9
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !15

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %35 = sub nsw i64 %indvars.iv.ph, %.sroa.3.0.extract.shift
  %36 = icmp ugt i64 %35, -4
  br i1 %36, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %37 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = add nsw i32 %40, %38
  %42 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv
  store i32 %41, ptr %42, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv.next
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = add nsw i32 %46, %44
  %48 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv.next
  store i32 %47, ptr %48, align 4, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %49 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next.1
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv.next.1
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = add nsw i32 %52, %50
  %54 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv.next.1
  store i32 %53, ptr %54, align 4, !tbaa !9
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %55 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next.2
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv.next.2
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = add nsw i32 %58, %56
  %60 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv.next.2
  store i32 %59, ptr %60, align 4, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %.sroa.3.0.extract.shift
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !17

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond24.not = icmp eq i64 %indvars.iv.next21, %wide.trip.count23
  br i1 %exitcond24.not, label %._crit_edge17, label %.preheader.us, !llvm.loop !18

._crit_edge17:                                    ; preds = %._crit_edge.us, %4
  ret { i64, ptr } %5
}

attributes #0 = { mustprogress 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" }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !12, !13}
!18 = distinct !{!18, !12}


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