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

; 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
@Sum = external dso_local global [100 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z15GetNumeralValuec(i8 noundef signext) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_Z10GetNumerali(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8Equalizeiii(i32 noundef, i32 noundef, i32 noundef) #0

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z9AddBase14v() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  %9 = call i64 @strlen(ptr noundef @Number1) #6
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %11 = call i64 @strlen(ptr noundef @Number2) #6
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %13 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %14 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %14, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp ne i32 %15, %16
  br i1 %17, label %18, label %22

18:                                               ; preds = %0
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z8Equalizeiii(i32 noundef %19, i32 noundef %20, i32 noundef %21)
  br label %22

22:                                               ; preds = %18, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  store i32 %24, ptr %8, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %58, %22
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = icmp sge i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %61

29:                                               ; preds = %25
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = call noundef i32 @_Z15GetNumeralValuec(i8 noundef signext %33)
  store i32 %34, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !9
  %39 = call noundef i32 @_Z15GetNumeralValuec(i8 noundef signext %38)
  store i32 %39, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  store i32 %44, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = icmp sge i32 %45, 14
  br i1 %46, label %47, label %50

47:                                               ; preds = %29
  store i32 1, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 14
  store i32 %49, ptr %7, align 4, !tbaa !5
  br label %51

50:                                               ; preds = %29
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %50, %47
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = call noundef signext i8 @_Z10GetNumerali(i32 noundef %52)
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100 x i8], ptr @Sum, i64 0, i64 %56
  store i8 %53, ptr %57, align 1, !tbaa !9
  br label %58

58:                                               ; preds = %51
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = add nsw i32 %59, -1
  store i32 %60, ptr %8, align 4, !tbaa !5
  br label %25, !llvm.loop !10

61:                                               ; preds = %28
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i8 49, ptr @Sum, align 16, !tbaa !9
  br label %66

65:                                               ; preds = %61
  store i8 48, ptr @Sum, align 16, !tbaa !9
  br label %66

66:                                               ; preds = %65, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret ptr @Sum
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; 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)) #4

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 = { 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 #3 = { nounwind willreturn memory(read) "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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"}


; 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 global [100 x i8], align 16
@Number2 = external dso_local global [100 x i8], align 16
@Sum = external dso_local global [100 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z15GetNumeralValuec(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_Z10GetNumerali(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8Equalizeiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef nonnull ptr @_Z9AddBase14v() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @Number1) #5
  %4 = trunc i64 %3 to i32
  store i32 %4, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @Number2) #5
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %9, %10
  br i1 %.not, label %12, label %11

11:                                               ; preds = %0
  call void @_Z8Equalizeiii(i32 noundef %8, i32 noundef %9, i32 noundef %10)
  br label %12

12:                                               ; preds = %11, %0
  %13 = icmp sgt i32 %8, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %12
  %14 = zext nneg i32 %8 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %15 = select i1 %24, i8 49, i8 48
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %12
  %.015.lcssa = phi i8 [ 48, %12 ], [ %15, %._crit_edge.loopexit ]
  store i8 %.015.lcssa, ptr @Sum, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret ptr @Sum

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %14, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01521 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %.lr.ph ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %16 = getelementptr inbounds [100 x i8], ptr @Number1, i64 0, i64 %indvars.iv.next
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = call noundef i32 @_Z15GetNumeralValuec(i8 noundef signext %17)
  %19 = getelementptr inbounds [100 x i8], ptr @Number2, i64 0, i64 %indvars.iv.next
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = call noundef i32 @_Z15GetNumeralValuec(i8 noundef signext %20)
  %22 = add nsw i32 %18, %.01521
  %23 = add nsw i32 %22, %21
  %24 = icmp sgt i32 %23, 13
  %25 = add nsw i32 %23, -14
  %.1 = zext i1 %24 to i32
  %.014 = select i1 %24, i32 %25, i32 %23
  %26 = call noundef signext i8 @_Z10GetNumerali(i32 noundef %.014)
  %27 = getelementptr inbounds [100 x i8], ptr @Sum, i64 0, i64 %indvars.iv
  store i8 %26, ptr %27, align 1, !tbaa !9
  %28 = icmp ugt i64 %indvars.iv, 1
  br i1 %28, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !10
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #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 #3

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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"}


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