; LLVM IR from Mohammed-Shoaib/Coding-Problems :: AtCoder/Solutions/abc172_c.ll (Z8tsundokuiiiRSt6vectorIxSaIxEES2_)

; 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 uwtable
define dso_local noundef i32 @_Z8tsundokuiiiRSt6vectorIxSaIxEES2_(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %46, %5
  %19 = load i32, ptr %14, align 4, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %18
  %23 = load i32, ptr %13, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = load ptr, ptr %10, align 8, !tbaa !9
  %26 = load i32, ptr %14, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %25, i64 noundef %27) #4
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = add nsw i64 %24, %29
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = icmp sle i64 %30, %32
  br label %34

34:                                               ; preds = %22, %18
  %35 = phi i1 [ false, %18 ], [ %33, %22 ]
  br i1 %35, label %36, label %49

36:                                               ; preds = %34
  %37 = load ptr, ptr %10, align 8, !tbaa !9
  %38 = load i32, ptr %14, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %37, i64 noundef %39) #4
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = add nsw i64 %43, %41
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr %13, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %36
  %47 = load i32, ptr %14, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %14, align 4, !tbaa !5
  br label %18, !llvm.loop !13

49:                                               ; preds = %34
  %50 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %50, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %95, %49
  %52 = load i32, ptr %15, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 5, ptr %16, align 4
  br label %98

56:                                               ; preds = %51
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = load i32, ptr %15, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %57, i64 noundef %59) #4
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = add nsw i64 %63, %61
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %12, align 4, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = icmp sgt i32 %66, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %56
  store i32 5, ptr %16, align 4
  br label %98

70:                                               ; preds = %56
  br label %71

71:                                               ; preds = %77, %70
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = load i32, ptr %13, align 4, !tbaa !5
  %74 = add nsw i32 %72, %73
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = icmp sgt i32 %74, %75
  br i1 %76, label %77, label %88

77:                                               ; preds = %71
  %78 = load ptr, ptr %10, align 8, !tbaa !9
  %79 = load i32, ptr %14, align 4, !tbaa !5
  %80 = add nsw i32 %79, -1
  store i32 %80, ptr %14, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %78, i64 noundef %81) #4
  %83 = load i64, ptr %82, align 8, !tbaa !11
  %84 = load i32, ptr %13, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = sub nsw i64 %85, %83
  %87 = trunc i64 %86 to i32
  store i32 %87, ptr %13, align 4, !tbaa !5
  br label %71, !llvm.loop !15

88:                                               ; preds = %71
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %89 = load i32, ptr %15, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  %91 = load i32, ptr %14, align 4, !tbaa !5
  %92 = add nsw i32 %90, %91
  store i32 %92, ptr %17, align 4, !tbaa !5
  %93 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %17, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %94 = load i32, ptr %93, align 4, !tbaa !5
  store i32 %94, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %95

95:                                               ; preds = %88
  %96 = load i32, ptr %15, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %15, align 4, !tbaa !5
  br label %51, !llvm.loop !16

98:                                               ; preds = %69, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %11, align 4, !tbaa !5
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret i32 %100
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

attributes #0 = { mustprogress 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 = { 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 #3 = { inlinehint 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 #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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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
define dso_local noundef i32 @_Z8tsundokuiiiRSt6vectorIxSaIxEES2_(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4) local_unnamed_addr #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %5
  %9 = sext i32 %2 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %10

10:                                               ; preds = %.lr.ph, %15
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %15 ]
  %.02731 = phi i32 [ 0, %.lr.ph ], [ %19, %15 ]
  %11 = sext i32 %.02731 to i64
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %indvars.iv) #3
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = add nsw i64 %13, %11
  %.not = icmp sgt i64 %14, %9
  br i1 %.not, label %.critedge.loopexit.split.loop.exit61, label %15

15:                                               ; preds = %10
  %16 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %indvars.iv) #3
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = trunc i64 %17 to i32
  %19 = add i32 %.02731, %18
  %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 %.critedge, label %10, !llvm.loop !9

.critedge.loopexit.split.loop.exit61:             ; preds = %10
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %15, %.critedge.loopexit.split.loop.exit61, %5
  %.027.lcssa = phi i32 [ 0, %5 ], [ %.02731, %.critedge.loopexit.split.loop.exit61 ], [ %19, %15 ]
  %.026.lcssa = phi i32 [ 0, %5 ], [ %20, %.critedge.loopexit.split.loop.exit61 ], [ %1, %15 ]
  store i32 %.026.lcssa, ptr %6, align 4, !tbaa !11
  %21 = icmp sgt i32 %0, 0
  br i1 %21, label %.lr.ph46.preheader, label %._crit_edge47

.lr.ph46.preheader:                               ; preds = %.critedge
  %wide.trip.count57 = zext nneg i32 %0 to i64
  br label %.lr.ph46

.lr.ph46:                                         ; preds = %.lr.ph46.preheader, %._crit_edge
  %indvars.iv54 = phi i64 [ 0, %.lr.ph46.preheader ], [ %indvars.iv.next55, %._crit_edge ]
  %.144 = phi i32 [ %.026.lcssa, %.lr.ph46.preheader ], [ %.2.lcssa, %._crit_edge ]
  %.12843 = phi i32 [ %.027.lcssa, %.lr.ph46.preheader ], [ %.229.lcssa, %._crit_edge ]
  %.03042 = phi i64 [ 0, %.lr.ph46.preheader ], [ %25, %._crit_edge ]
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv54) #3
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %sext = shl i64 %.03042, 32
  %24 = ashr exact i64 %sext, 32
  %25 = add nsw i64 %23, %24
  %26 = trunc i64 %25 to i32
  %27 = icmp sgt i32 %26, %2
  br i1 %27, label %.lr.ph46.._crit_edge47.loopexit_crit_edge, label %.preheader

.lr.ph46.._crit_edge47.loopexit_crit_edge:        ; preds = %.lr.ph46
  %.pre.pre = load i32, ptr %6, align 4, !tbaa !11
  br label %._crit_edge47

.preheader:                                       ; preds = %.lr.ph46
  %28 = add nsw i32 %.12843, %26
  %29 = icmp sgt i32 %28, %2
  br i1 %29, label %.lr.ph39.preheader, label %._crit_edge

.lr.ph39.preheader:                               ; preds = %.preheader
  %30 = sext i32 %.144 to i64
  br label %.lr.ph39

.lr.ph39:                                         ; preds = %.lr.ph39.preheader, %.lr.ph39
  %indvars.iv51 = phi i64 [ %30, %.lr.ph39.preheader ], [ %indvars.iv.next52, %.lr.ph39 ]
  %.22937 = phi i32 [ %.12843, %.lr.ph39.preheader ], [ %34, %.lr.ph39 ]
  %indvars.iv.next52 = add nsw i64 %indvars.iv51, -1
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %indvars.iv.next52) #3
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = trunc i64 %32 to i32
  %34 = sub i32 %.22937, %33
  %35 = add nsw i32 %34, %26
  %36 = icmp sgt i32 %35, %2
  br i1 %36, label %.lr.ph39, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %.lr.ph39
  %37 = trunc nsw i64 %indvars.iv.next52 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.229.lcssa = phi i32 [ %.12843, %.preheader ], [ %34, %._crit_edge.loopexit ]
  %.2.lcssa = phi i32 [ %.144, %.preheader ], [ %37, %._crit_edge.loopexit ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %38 = trunc nuw nsw i64 %indvars.iv.next55 to i32
  %39 = add nsw i32 %.2.lcssa, %38
  store i32 %39, ptr %7, align 4, !tbaa !11
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %41 = load i32, ptr %40, align 4, !tbaa !11
  store i32 %41, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  %exitcond58.not = icmp eq i64 %indvars.iv.next55, %wide.trip.count57
  br i1 %exitcond58.not, label %._crit_edge47, label %.lr.ph46, !llvm.loop !14

._crit_edge47:                                    ; preds = %._crit_edge, %.lr.ph46.._crit_edge47.loopexit_crit_edge, %.critedge
  %42 = phi i32 [ %.026.lcssa, %.critedge ], [ %.pre.pre, %.lr.ph46.._crit_edge47.loopexit_crit_edge ], [ %41, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  ret i32 %42
}

; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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


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