; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 946B. Weird Subtraction Process.ll (Z5retItxx)

; 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 [11 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5retItxx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %10, label %7

7:                                                ; preds = %2
  %8 = load i64, ptr %4, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %7, %2
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %11, i64 noundef %12)
  br label %42

14:                                               ; preds = %7
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = mul nsw i64 2, %16
  %18 = icmp sge i64 %15, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = mul nsw i64 2, %20
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = srem i64 %22, %21
  store i64 %23, ptr %3, align 8, !tbaa !5
  br label %39

24:                                               ; preds = %14
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = mul nsw i64 2, %26
  %28 = icmp sge i64 %25, %27
  br i1 %28, label %29, label %34

29:                                               ; preds = %24
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = mul nsw i64 2, %30
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = srem i64 %32, %31
  store i64 %33, ptr %4, align 8, !tbaa !5
  br label %38

34:                                               ; preds = %24
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %35, i64 noundef %36)
  br label %42

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %38, %19
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = load i64, ptr %4, align 8, !tbaa !5
  call void @_Z5retItxx(i64 noundef %40, i64 noundef %41)
  br label %42

42:                                               ; preds = %39, %34, %10
  ret void
}

declare i32 @printf(ptr noundef, ...) #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 = { "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; 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 [11 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5retItxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i64 %0, 0
  %4 = icmp eq i64 %1, 0
  %or.cond26 = or i1 %3, %4
  br i1 %or.cond26, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %.tr.lcssa = phi i64 [ %0, %2 ], [ %.017, %tailrecurse ]
  %.tr23.lcssa = phi i64 [ %1, %2 ], [ %.0, %tailrecurse ]
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.tr.lcssa, i64 noundef %.tr23.lcssa)
  br label %17

.lr.ph:                                           ; preds = %2, %tailrecurse
  %.tr2328 = phi i64 [ %.0, %tailrecurse ], [ %1, %2 ]
  %.tr27 = phi i64 [ %.017, %tailrecurse ], [ %0, %2 ]
  %6 = shl nsw i64 %.tr2328, 1
  %.not = icmp sgt i64 %6, %.tr27
  br i1 %.not, label %9, label %7

7:                                                ; preds = %.lr.ph
  %8 = srem i64 %.tr27, %6
  br label %tailrecurse

9:                                                ; preds = %.lr.ph
  %10 = shl nsw i64 %.tr27, 1
  %.not22 = icmp sgt i64 %10, %.tr2328
  br i1 %.not22, label %13, label %11

11:                                               ; preds = %9
  %12 = srem i64 %.tr2328, %10
  br label %tailrecurse

13:                                               ; preds = %9
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.tr27, i64 noundef %.tr2328)
  br label %17

tailrecurse:                                      ; preds = %11, %7
  %.017 = phi i64 [ %8, %7 ], [ %.tr27, %11 ]
  %.0 = phi i64 [ %.tr2328, %7 ], [ %12, %11 ]
  %15 = icmp eq i64 %.017, 0
  %16 = icmp eq i64 %.0, 0
  %or.cond = or i1 %15, %16
  br i1 %or.cond, label %tailrecurse._crit_edge, label %.lr.ph

17:                                               ; preds = %13, %tailrecurse._crit_edge
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { 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 #1 = { 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" }

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


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