; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Mathematical Algorithms/Adding Two Numbers in Base 14.ll (Z8Equalizeiii)

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

@Number1 = external dso_local global [100 x i8], align 16
@Number2 = external dso_local global [100 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8Equalizeiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp ne i32 %11, %12
  br i1 %13, label %14, label %45

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  store i32 %16, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sub nsw i32 %17, 1
  store i32 %18, ptr %8, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %39, %14
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %44

23:                                               ; preds = %19
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = icmp sge i32 %24, 0
  br i1 %25, label %26, label %34

26:                                               ; preds = %23
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %32
  store i8 %30, ptr %33, align 1, !tbaa !9
  br label %38

34:                                               ; preds = %23
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %36
  store i8 48, ptr %37, align 1, !tbaa !9
  br label %38

38:                                               ; preds = %34, %26
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %8, align 4, !tbaa !5
  br label %19, !llvm.loop !10

44:                                               ; preds = %22
  br label %76

45:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  store i32 %47, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  store i32 %49, ptr %10, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %70, %45
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = icmp sge i32 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %75

54:                                               ; preds = %50
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = icmp sge i32 %55, 0
  br i1 %56, label %57, label %65

57:                                               ; preds = %54
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %63
  store i8 %61, ptr %64, align 1, !tbaa !9
  br label %69

65:                                               ; preds = %54
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %67
  store i8 48, ptr %68, align 1, !tbaa !9
  br label %69

69:                                               ; preds = %65, %57
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %9, align 4, !tbaa !5
  %73 = load i32, ptr %10, align 4, !tbaa !5
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %10, align 4, !tbaa !5
  br label %50, !llvm.loop !12

75:                                               ; preds = %53
  br label %76

76:                                               ; preds = %75, %44
  ret void
}

; 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

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 }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@Number1 = external dso_local local_unnamed_addr global [100 x i8], align 16
@Number2 = external dso_local local_unnamed_addr global [100 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z8Equalizeiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, %1
  %4 = icmp sgt i32 %0, 0
  br i1 %.not, label %.preheader, label %.preheader25

.preheader25:                                     ; preds = %3
  br i1 %4, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader25
  %5 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %5, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %.02130.prol = add nsw i32 %1, -1
  %indvars.iv.next.prol = add nsw i64 %5, -1
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %7, label %.lr.ph.prol.loopexit.unr-lcssa

7:                                                ; preds = %.lr.ph.prol
  %8 = zext nneg i32 %.02130.prol to i64
  %9 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  br label %.lr.ph.prol.loopexit.unr-lcssa

.lr.ph.prol.loopexit.unr-lcssa:                   ; preds = %7, %.lr.ph.prol
  %.sink.prol = phi i8 [ %10, %7 ], [ 48, %.lr.ph.prol ]
  %11 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %indvars.iv.next.prol
  store i8 %.sink.prol, ptr %11, align 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol.loopexit.unr-lcssa, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %.021.in29.unr = phi i32 [ %1, %.lr.ph.preheader ], [ %.02130.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %12 = icmp eq i32 %0, 1
  br i1 %12, label %.loopexit, label %.lr.ph

.preheader:                                       ; preds = %3
  br i1 %4, label %.lr.ph37.preheader, label %.loopexit

.lr.ph37.preheader:                               ; preds = %.preheader
  %13 = zext nneg i32 %0 to i64
  %xtraiter47 = and i64 %13, 1
  %lcmp.mod48.not = icmp eq i64 %xtraiter47, 0
  br i1 %lcmp.mod48.not, label %.lr.ph37.prol.loopexit, label %.lr.ph37.prol

.lr.ph37.prol:                                    ; preds = %.lr.ph37.preheader
  %.035.prol = add nsw i32 %2, -1
  %indvars.iv.next41.prol = add nsw i64 %13, -1
  %14 = icmp sgt i32 %2, 0
  br i1 %14, label %15, label %.lr.ph37.prol.loopexit.unr-lcssa

15:                                               ; preds = %.lr.ph37.prol
  %16 = zext nneg i32 %.035.prol to i64
  %17 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5
  br label %.lr.ph37.prol.loopexit.unr-lcssa

.lr.ph37.prol.loopexit.unr-lcssa:                 ; preds = %15, %.lr.ph37.prol
  %.sink43.prol = phi i8 [ %18, %15 ], [ 48, %.lr.ph37.prol ]
  %19 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %indvars.iv.next41.prol
  store i8 %.sink43.prol, ptr %19, align 1
  br label %.lr.ph37.prol.loopexit

.lr.ph37.prol.loopexit:                           ; preds = %.lr.ph37.prol.loopexit.unr-lcssa, %.lr.ph37.preheader
  %indvars.iv40.unr = phi i64 [ %13, %.lr.ph37.preheader ], [ %indvars.iv.next41.prol, %.lr.ph37.prol.loopexit.unr-lcssa ]
  %.0.in34.unr = phi i32 [ %2, %.lr.ph37.preheader ], [ %.035.prol, %.lr.ph37.prol.loopexit.unr-lcssa ]
  %20 = icmp eq i32 %0, 1
  br i1 %20, label %.loopexit, label %.lr.ph37

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %32
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %32 ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %.021.in29 = phi i32 [ %.02130.1, %32 ], [ %.021.in29.unr, %.lr.ph.prol.loopexit ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %21 = icmp sgt i32 %.021.in29, 0
  br i1 %21, label %22, label %.lr.ph.1

22:                                               ; preds = %.lr.ph
  %.02130 = add nsw i32 %.021.in29, -1
  %23 = zext nneg i32 %.02130 to i64
  %24 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %22
  %.sink = phi i8 [ %25, %22 ], [ 48, %.lr.ph ]
  %26 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %indvars.iv.next
  store i8 %.sink, ptr %26, align 1
  %.02130.1 = add nsw i32 %.021.in29, -2
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %27 = icmp sgt i32 %.021.in29, 1
  br i1 %27, label %28, label %32

28:                                               ; preds = %.lr.ph.1
  %29 = zext nneg i32 %.02130.1 to i64
  %30 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !5
  br label %32

32:                                               ; preds = %28, %.lr.ph.1
  %.sink.1 = phi i8 [ %31, %28 ], [ 48, %.lr.ph.1 ]
  %33 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %indvars.iv.next.1
  store i8 %.sink.1, ptr %33, align 1
  %34 = icmp ugt i64 %indvars.iv.next, 1
  br i1 %34, label %.lr.ph, label %.loopexit, !llvm.loop !8

.lr.ph37:                                         ; preds = %.lr.ph37.prol.loopexit, %46
  %indvars.iv40 = phi i64 [ %indvars.iv.next41.1, %46 ], [ %indvars.iv40.unr, %.lr.ph37.prol.loopexit ]
  %.0.in34 = phi i32 [ %.035.1, %46 ], [ %.0.in34.unr, %.lr.ph37.prol.loopexit ]
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, -1
  %35 = icmp sgt i32 %.0.in34, 0
  br i1 %35, label %36, label %.lr.ph37.1

36:                                               ; preds = %.lr.ph37
  %.035 = add nsw i32 %.0.in34, -1
  %37 = zext nneg i32 %.035 to i64
  %38 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !5
  br label %.lr.ph37.1

.lr.ph37.1:                                       ; preds = %.lr.ph37, %36
  %.sink43 = phi i8 [ %39, %36 ], [ 48, %.lr.ph37 ]
  %40 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %indvars.iv.next41
  store i8 %.sink43, ptr %40, align 1
  %.035.1 = add nsw i32 %.0.in34, -2
  %indvars.iv.next41.1 = add nsw i64 %indvars.iv40, -2
  %41 = icmp sgt i32 %.0.in34, 1
  br i1 %41, label %42, label %46

42:                                               ; preds = %.lr.ph37.1
  %43 = zext nneg i32 %.035.1 to i64
  %44 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !5
  br label %46

46:                                               ; preds = %42, %.lr.ph37.1
  %.sink43.1 = phi i8 [ %45, %42 ], [ 48, %.lr.ph37.1 ]
  %47 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %indvars.iv.next41.1
  store i8 %.sink43.1, ptr %47, align 1
  %48 = icmp ugt i64 %indvars.iv.next41, 1
  br i1 %48, label %.lr.ph37, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %32, %.lr.ph37.prol.loopexit, %46, %.preheader25, %.preheader
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass