; LLVM IR from JessonYue/LeetCodeLearning :: Array/huangxinyu/c/Matrix.ll (Z3addiiPPiS0_)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z3addiiPPiS0_(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = mul i64 4, %15
  %17 = call noalias ptr @malloc(i64 noundef %16) #4
  store ptr %17, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %32, %4
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %35

23:                                               ; preds = %18
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = mul i64 4, %25
  %27 = call noalias ptr @malloc(i64 noundef %26) #4
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  store ptr %27, ptr %31, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %23
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %10, align 4, !tbaa !5
  br label %18, !llvm.loop !11

35:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %79, %35
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %82

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %75, %41
  %43 = load i32, ptr %13, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %78

47:                                               ; preds = %42
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load i32, ptr %13, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %57, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !9
  %62 = load i32, ptr %13, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = add nsw i32 %56, %65
  %67 = load ptr, ptr %9, align 8, !tbaa !9
  %68 = load i32, ptr %11, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %67, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = load i32, ptr %13, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  store i32 %66, ptr %74, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %47
  %76 = load i32, ptr %13, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %13, align 4, !tbaa !5
  br label %42, !llvm.loop !13

78:                                               ; preds = %46
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %11, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %11, align 4, !tbaa !5
  br label %36, !llvm.loop !14

82:                                               ; preds = %40
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %83
}

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

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

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

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


; 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 uwtable
define dso_local noalias noundef ptr @_Z3addiiPPiS0_(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = shl nsw i64 %5, 2
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #2
  %8 = icmp sgt i32 %0, 0
  br i1 %8, label %.lr.ph, label %._crit_edge30

.lr.ph:                                           ; preds = %4
  %9 = sext i32 %1 to i64
  %10 = shl nsw i64 %9, 2
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %64

.preheader25:                                     ; preds = %64
  %11 = icmp sgt i32 %1, 0
  %or.cond = and i1 %8, %11
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge30

.preheader.us.preheader:                          ; preds = %.preheader25
  %wide.trip.count41 = zext nneg i32 %0 to i64
  %wide.trip.count36 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  %n.vec = and i64 %wide.trip.count36, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count36
  %xtraiter = and i64 %wide.trip.count36, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv38 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next39, %._crit_edge.us ]
  %12 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv38
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds ptr, ptr %3, i64 %indvars.iv38
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv38
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us
  %18 = ptrtoint ptr %17 to i64
  %19 = ptrtoint ptr %15 to i64
  %20 = ptrtoint ptr %13 to i64
  %21 = sub i64 %18, %20
  %diff.check = icmp ult i64 %21, 32
  %22 = sub i64 %18, %19
  %diff.check43 = icmp ult i64 %22, 32
  %conflict.rdx = or i1 %diff.check, %diff.check43
  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 ]
  %23 = getelementptr inbounds i32, ptr %13, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %wide.load = load <4 x i32>, ptr %23, align 4, !tbaa !9
  %wide.load44 = load <4 x i32>, ptr %24, align 4, !tbaa !9
  %25 = getelementptr inbounds i32, ptr %15, i64 %index
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load45 = load <4 x i32>, ptr %25, align 4, !tbaa !9
  %wide.load46 = load <4 x i32>, ptr %26, align 4, !tbaa !9
  %27 = add nsw <4 x i32> %wide.load45, %wide.load
  %28 = add nsw <4 x i32> %wide.load46, %wide.load44
  %29 = getelementptr inbounds i32, ptr %17, i64 %index
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  store <4 x i32> %27, ptr %29, align 4, !tbaa !9
  store <4 x i32> %28, ptr %30, align 4, !tbaa !9
  %index.next = add nuw i64 %index, 8
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, 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.iv33.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.iv33.prol = phi i64 [ %indvars.iv.next34.prol, %scalar.ph.prol ], [ %indvars.iv33.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %32 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv33.prol
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv33.prol
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = add nsw i32 %35, %33
  %37 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv33.prol
  store i32 %36, ptr %37, align 4, !tbaa !9
  %indvars.iv.next34.prol = add nuw nsw i64 %indvars.iv33.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.iv33.unr = phi i64 [ %indvars.iv33.ph, %scalar.ph.preheader ], [ %indvars.iv.next34.prol, %scalar.ph.prol ]
  %38 = sub nsw i64 %indvars.iv33.ph, %wide.trip.count36
  %39 = icmp ugt i64 %38, -4
  br i1 %39, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv33 = phi i64 [ %indvars.iv.next34.3, %scalar.ph ], [ %indvars.iv33.unr, %scalar.ph.prol.loopexit ]
  %40 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv33
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv33
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = add nsw i32 %43, %41
  %45 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv33
  store i32 %44, ptr %45, align 4, !tbaa !9
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %46 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv.next34
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv.next34
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = add nsw i32 %49, %47
  %51 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next34
  store i32 %50, ptr %51, align 4, !tbaa !9
  %indvars.iv.next34.1 = add nuw nsw i64 %indvars.iv33, 2
  %52 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv.next34.1
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv.next34.1
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = add nsw i32 %55, %53
  %57 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next34.1
  store i32 %56, ptr %57, align 4, !tbaa !9
  %indvars.iv.next34.2 = add nuw nsw i64 %indvars.iv33, 3
  %58 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv.next34.2
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv.next34.2
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = add nsw i32 %61, %59
  %63 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next34.2
  store i32 %62, ptr %63, align 4, !tbaa !9
  %indvars.iv.next34.3 = add nuw nsw i64 %indvars.iv33, 4
  %exitcond37.not.3 = icmp eq i64 %indvars.iv.next34.3, %wide.trip.count36
  br i1 %exitcond37.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.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge30, label %.preheader.us, !llvm.loop !18

64:                                               ; preds = %.lr.ph, %64
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %64 ]
  %65 = tail call noalias ptr @malloc(i64 noundef %10) #2
  %66 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  store ptr %65, ptr %66, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader25, label %64, !llvm.loop !19

._crit_edge30:                                    ; preds = %._crit_edge.us, %4, %.preheader25
  ret ptr %7
}

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

attributes #0 = { mustprogress nofree 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 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 #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, !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}
!19 = distinct !{!19, !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