; LLVM IR from TLE-MEC/Hack-CP-DSA :: Hackerearth/Balancing cubes/solution.ll (Z18numberOfOperationsi)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z18numberOfOperationsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sle i32 %4, 1
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  br label %29

7:                                                ; preds = %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 2
  br i1 %9, label %13, label %10

10:                                               ; preds = %7
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 3
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %7
  store i32 1, ptr %2, align 4
  br label %29

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

18:                                               ; preds = %14
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sdiv i32 %19, 3
  %21 = add nsw i32 %20, 1
  %22 = call noundef i32 @_Z18numberOfOperationsi(i32 noundef %21)
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4
  br label %29

24:                                               ; preds = %14
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sdiv i32 %25, 3
  %27 = call noundef i32 @_Z18numberOfOperationsi(i32 noundef %26)
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4
  br label %29

29:                                               ; preds = %24, %18, %13, %6
  %30 = load i32, ptr %2, align 4
  ret i32 %30
}

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

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


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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_Z18numberOfOperationsi(i32 noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse25

tailrecurse25:                                    ; preds = %10, %1
  %accumulator.tr = phi i32 [ 0, %1 ], [ %accumulator.ret.tr, %10 ]
  %.tr = phi i32 [ %0, %1 ], [ %6, %10 ]
  %2 = icmp slt i32 %.tr, 2
  br i1 %2, label %common.ret, label %.lr.ph

.lr.ph:                                           ; preds = %tailrecurse25, %tailrecurse
  %.tr13 = phi i32 [ %8, %tailrecurse ], [ %.tr, %tailrecurse25 ]
  %accumulator.tr12 = phi i32 [ %7, %tailrecurse ], [ 0, %tailrecurse25 ]
  %3 = and i32 %.tr13, 2147483646
  %or.cond = icmp eq i32 %3, 2
  br i1 %or.cond, label %._crit_edge.loopexit, label %4

4:                                                ; preds = %.lr.ph
  %5 = urem i32 %.tr13, 3
  %.not = icmp eq i32 %5, 0
  %6 = udiv i32 %.tr13, 3
  %7 = add nuw i32 %accumulator.tr12, 1
  br i1 %.not, label %10, label %tailrecurse

tailrecurse:                                      ; preds = %4
  %8 = add nuw nsw i32 %6, 1
  %9 = icmp ult i32 %.tr13, 3
  br i1 %9, label %._crit_edge.loopexit, label %.lr.ph

common.ret:                                       ; preds = %tailrecurse25, %._crit_edge.loopexit
  %common.ret.op = phi i32 [ 0, %tailrecurse25 ], [ %11, %._crit_edge.loopexit ]
  %accumulator.ret.tr26 = add i32 %common.ret.op, %accumulator.tr
  ret i32 %accumulator.ret.tr26

10:                                               ; preds = %4
  %accumulator.ret.tr = add i32 %7, %accumulator.tr
  br label %tailrecurse25

._crit_edge.loopexit:                             ; preds = %.lr.ph, %tailrecurse
  %accumulator.tr.lcssa.ph = phi i32 [ %7, %tailrecurse ], [ %accumulator.tr12, %.lr.ph ]
  %.0.ph = phi i32 [ 0, %tailrecurse ], [ 1, %.lr.ph ]
  %11 = add nsw i32 %.0.ph, %accumulator.tr.lcssa.ph
  br label %common.ret
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(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)"}


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