; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions/42. Adding Reversed Numbers (main)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %10

10:                                               ; preds = %54, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %2, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %57

14:                                               ; preds = %10
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  br label %16

16:                                               ; preds = %19, %14
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %16
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = mul nsw i32 %20, 10
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = srem i32 %22, 10
  %24 = add nsw i32 %21, %23
  store i32 %24, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sdiv i32 %25, 10
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !9

27:                                               ; preds = %16
  br label %28

28:                                               ; preds = %31, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %39

31:                                               ; preds = %28
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = mul nsw i32 %32, 10
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = srem i32 %34, 10
  %36 = add nsw i32 %33, %35
  store i32 %36, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sdiv i32 %37, 10
  store i32 %38, ptr %4, align 4, !tbaa !5
  br label %28, !llvm.loop !11

39:                                               ; preds = %28
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr %8, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %46, %39
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %54

46:                                               ; preds = %43
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = mul nsw i32 %47, 10
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = srem i32 %49, 10
  %51 = add nsw i32 %48, %50
  store i32 %51, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = sdiv i32 %52, 10
  store i32 %53, ptr %8, align 4, !tbaa !5
  br label %43, !llvm.loop !12

54:                                               ; preds = %43
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %55)
  br label %10, !llvm.loop !13

57:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

declare i32 @printf(ptr 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 = { 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %.not32 = icmp eq i32 %5, 0
  br i1 %.not32, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %0, %._crit_edge30
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.pr = load i32, ptr %2, align 4, !tbaa !5
  %.not1418 = icmp eq i32 %.pr, 0
  br i1 %.not1418, label %thread-pre-split, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph34, %.lr.ph
  %.01019 = phi i32 [ %11, %.lr.ph ], [ 0, %.lr.ph34 ]
  %8 = phi i32 [ %12, %.lr.ph ], [ %.pr, %.lr.ph34 ]
  %9 = mul nsw i32 %.01019, 10
  %10 = srem i32 %8, 10
  %11 = add nsw i32 %9, %10
  %12 = sdiv i32 %8, 10
  %.off = add i32 %8, 9
  %.not14 = icmp ult i32 %.off, 19
  br i1 %.not14, label %.thread-pre-split_crit_edge, label %.lr.ph, !llvm.loop !9

.thread-pre-split_crit_edge:                      ; preds = %.lr.ph
  store i32 %12, ptr %2, align 4, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %.thread-pre-split_crit_edge, %.lr.ph34
  %.010.lcssa = phi i32 [ %11, %.thread-pre-split_crit_edge ], [ 0, %.lr.ph34 ]
  %.pr17 = load i32, ptr %3, align 4, !tbaa !5
  %.not1520 = icmp eq i32 %.pr17, 0
  br i1 %.not1520, label %18, label %.lr.ph22

.lr.ph22:                                         ; preds = %thread-pre-split, %.lr.ph22
  %.0921 = phi i32 [ %16, %.lr.ph22 ], [ 0, %thread-pre-split ]
  %13 = phi i32 [ %17, %.lr.ph22 ], [ %.pr17, %thread-pre-split ]
  %14 = mul nsw i32 %.0921, 10
  %15 = srem i32 %13, 10
  %16 = add nsw i32 %14, %15
  %17 = sdiv i32 %13, 10
  %.off36 = add i32 %13, 9
  %.not15 = icmp ult i32 %.off36, 19
  br i1 %.not15, label %._crit_edge, label %.lr.ph22, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph22
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %thread-pre-split
  %.09.lcssa = phi i32 [ %16, %._crit_edge ], [ 0, %thread-pre-split ]
  %19 = add nsw i32 %.09.lcssa, %.010.lcssa
  %.not1625 = icmp eq i32 %19, 0
  br i1 %.not1625, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %18, %.lr.ph29
  %.027 = phi i32 [ %23, %.lr.ph29 ], [ %19, %18 ]
  %.01126 = phi i32 [ %22, %.lr.ph29 ], [ 0, %18 ]
  %20 = mul nsw i32 %.01126, 10
  %21 = srem i32 %.027, 10
  %22 = add nsw i32 %21, %20
  %23 = sdiv i32 %.027, 10
  %.027.off = add i32 %.027, 9
  %.not16 = icmp ult i32 %.027.off, 19
  br i1 %.not16, label %._crit_edge30, label %.lr.ph29, !llvm.loop !12

._crit_edge30:                                    ; preds = %.lr.ph29, %18
  %.011.lcssa = phi i32 [ 0, %18 ], [ %22, %.lr.ph29 ]
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.011.lcssa)
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !13

._crit_edge35:                                    ; preds = %._crit_edge30, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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