; LLVM IR from eyangch/competitive-programming :: CSES/Introductory_Problems (tower_of_hanoi_fast)

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

@N = external dso_local global i32, align 4

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar_unlocked(i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #4
  %7 = call i32 @getchar_unlocked()
  %8 = trunc i32 %7 to i8
  store i8 %8, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  %9 = call i32 @getchar_unlocked()
  %10 = trunc i32 %9 to i8
  store i8 %10, ptr %3, align 1, !tbaa !5
  %11 = load i8, ptr %3, align 1, !tbaa !5
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 10
  br i1 %13, label %14, label %18

14:                                               ; preds = %0
  %15 = load i8, ptr %2, align 1, !tbaa !5
  %16 = sext i8 %15 to i32
  %17 = sub nsw i32 %16, 48
  store i32 %17, ptr @N, align 4, !tbaa !8
  br label %27

18:                                               ; preds = %0
  %19 = load i8, ptr %2, align 1, !tbaa !5
  %20 = sext i8 %19 to i32
  %21 = sub nsw i32 %20, 48
  %22 = mul nsw i32 10, %21
  %23 = load i8, ptr %3, align 1, !tbaa !5
  %24 = sext i8 %23 to i32
  %25 = add nsw i32 %22, %24
  %26 = sub nsw i32 %25, 48
  store i32 %26, ptr @N, align 4, !tbaa !8
  br label %27

27:                                               ; preds = %18, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %28 = load i32, ptr @N, align 4, !tbaa !8
  %29 = shl i32 1, %28
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 10000, ptr %5, align 4, !tbaa !8
  br label %31

31:                                               ; preds = %38, %27
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %4, align 4, !tbaa !8
  %34 = load i32, ptr %5, align 4, !tbaa !8
  %35 = sdiv i32 %33, %34
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  br label %41

38:                                               ; preds = %32
  %39 = load i32, ptr %5, align 4, !tbaa !8
  %40 = sdiv i32 %39, 10
  store i32 %40, ptr %5, align 4, !tbaa !8
  br label %31, !llvm.loop !10

41:                                               ; preds = %37
  br label %42

42:                                               ; preds = %45, %41
  %43 = load i32, ptr %4, align 4, !tbaa !8
  %44 = icmp sgt i32 %43, 0
  br i1 %44, label %45, label %57

45:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %46 = load i32, ptr %4, align 4, !tbaa !8
  %47 = load i32, ptr %5, align 4, !tbaa !8
  %48 = sdiv i32 %46, %47
  store i32 %48, ptr %6, align 4, !tbaa !8
  %49 = load i32, ptr %5, align 4, !tbaa !8
  %50 = load i32, ptr %4, align 4, !tbaa !8
  %51 = srem i32 %50, %49
  store i32 %51, ptr %4, align 4, !tbaa !8
  %52 = load i32, ptr %5, align 4, !tbaa !8
  %53 = sdiv i32 %52, 10
  store i32 %53, ptr %5, align 4, !tbaa !8
  %54 = load i32, ptr %6, align 4, !tbaa !8
  %55 = add nsw i32 %54, 48
  %56 = call i32 @putchar_unlocked(i32 noundef %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %42, !llvm.loop !12

57:                                               ; preds = %42
  %58 = call i32 @putchar_unlocked(i32 noundef 10)
  %59 = load i32, ptr @N, align 4, !tbaa !8
  call void @_Z3tohiiii(i32 noundef %59, i32 noundef 1, i32 noundef 3, i32 noundef 2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #4
  %60 = load i32, ptr %1, align 4
  ret i32 %60
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @getchar_unlocked() #1

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

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 = { inlinehint 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 #2 = { mustprogress norecurse 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, 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"

@N = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar_unlocked(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 @getchar_unlocked()
  %2 = tail call i32 @getchar_unlocked()
  %sext = shl i32 %2, 24
  %3 = icmp eq i32 %sext, 167772160
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %sext18 = shl i32 %1, 24
  %5 = ashr exact i32 %sext18, 24
  br label %12

6:                                                ; preds = %0
  %7 = ashr exact i32 %sext, 24
  %sext17 = shl i32 %1, 24
  %8 = ashr exact i32 %sext17, 24
  %9 = mul nsw i32 %8, 10
  %10 = add nsw i32 %9, -480
  %11 = add nsw i32 %10, %7
  br label %12

12:                                               ; preds = %6, %4
  %storemerge.in = phi i32 [ %11, %6 ], [ %5, %4 ]
  %storemerge = add nsw i32 %storemerge.in, -48
  store i32 %storemerge, ptr @N, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %storemerge
  %13 = xor i32 %notmask, -1
  %.not = icmp ugt i32 %notmask, -10001
  br i1 %.not, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %12
  %.015.lcssa = phi i32 [ 10000, %12 ], [ %14, %.lr.ph ]
  %.not23 = icmp eq i32 %storemerge, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph22

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.01519 = phi i32 [ %14, %.lr.ph ], [ 10000, %12 ]
  %14 = sdiv i32 %.01519, 10
  %15 = sdiv i32 %13, %14
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph22:                                         ; preds = %.preheader, %.lr.ph22
  %.021 = phi i32 [ %18, %.lr.ph22 ], [ %13, %.preheader ]
  %.120 = phi i32 [ %19, %.lr.ph22 ], [ %.015.lcssa, %.preheader ]
  %17 = sdiv i32 %.021, %.120
  %18 = srem i32 %.021, %.120
  %19 = sdiv i32 %.120, 10
  %20 = add nsw i32 %17, 48
  %21 = tail call i32 @putchar_unlocked(i32 noundef %20)
  %22 = icmp sgt i32 %18, 0
  br i1 %22, label %.lr.ph22, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph22, %.preheader
  %23 = tail call i32 @putchar_unlocked(i32 noundef 10)
  %24 = load i32, ptr @N, align 4, !tbaa !5
  tail call void @_Z3tohiiii(i32 noundef %24, i32 noundef 1, i32 noundef 3, i32 noundef 2)
  ret i32 0
}

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @getchar_unlocked() local_unnamed_addr #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 = { inlinehint 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 #2 = { mustprogress norecurse 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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