; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK74/Problem A/A.ll (Z3getxxx)

; 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 i64 @_Z3getxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  %8 = load i64, ptr %5, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 1
  br i1 %9, label %10, label %12

10:                                               ; preds = %3
  %11 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %11, ptr %4, align 8
  br label %48

12:                                               ; preds = %3
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = srem i64 %13, 2
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %30

16:                                               ; preds = %12
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = sdiv i64 %17, 2
  %19 = load i64, ptr %6, align 8, !tbaa !5
  %20 = mul nsw i64 %18, %19
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = add nsw i64 %20, %21
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = sdiv i64 %23, 2
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = mul nsw i64 2, %25
  %27 = load i64, ptr %7, align 8, !tbaa !5
  %28 = call noundef i64 @_Z3getxxx(i64 noundef %24, i64 noundef %26, i64 noundef %27)
  %29 = add nsw i64 %22, %28
  store i64 %29, ptr %4, align 8
  br label %48

30:                                               ; preds = %12
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  %33 = sdiv i64 %32, 2
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = mul nsw i64 %33, %34
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = add nsw i64 %35, %36
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  %41 = sdiv i64 %40, 2
  %42 = sub nsw i64 %38, %41
  %43 = load i64, ptr %6, align 8, !tbaa !5
  %44 = mul nsw i64 2, %43
  %45 = load i64, ptr %7, align 8, !tbaa !5
  %46 = call noundef i64 @_Z3getxxx(i64 noundef %42, i64 noundef %44, i64 noundef %45)
  %47 = add nsw i64 %37, %46
  store i64 %47, ptr %4, align 8
  br label %48

48:                                               ; preds = %30, %16, %10
  %49 = load i64, ptr %4, align 8
  ret i64 %49
}

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 = !{!"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"

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i64 @_Z3getxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  br label %tailrecurse48

tailrecurse48:                                    ; preds = %13, %3
  %accumulator.tr = phi i64 [ 0, %3 ], [ %accumulator.ret.tr, %13 ]
  %.tr = phi i64 [ %0, %3 ], [ %17, %13 ]
  %.tr49 = phi i64 [ %1, %3 ], [ %18, %13 ]
  %4 = icmp eq i64 %.tr, 1
  br i1 %4, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %tailrecurse48, %tailrecurse
  %.tr1826 = phi i64 [ %9, %tailrecurse ], [ %.tr49, %tailrecurse48 ]
  %.tr25 = phi i64 [ %7, %tailrecurse ], [ %.tr, %tailrecurse48 ]
  %accumulator.tr24 = phi i64 [ %11, %tailrecurse ], [ 0, %tailrecurse48 ]
  %5 = and i64 %.tr25, 1
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %tailrecurse, label %13

tailrecurse:                                      ; preds = %.lr.ph
  %7 = ashr exact i64 %.tr25, 1
  %8 = mul nsw i64 %7, %.tr1826
  %9 = shl nsw i64 %.tr1826, 1
  %10 = add i64 %accumulator.tr24, %2
  %11 = add i64 %10, %8
  %12 = icmp eq i64 %.tr25, 2
  br i1 %12, label %tailrecurse._crit_edge, label %.lr.ph

13:                                               ; preds = %.lr.ph
  %14 = add nsw i64 %.tr25, 1
  %15 = ashr exact i64 %14, 1
  %16 = mul nsw i64 %15, %.tr1826
  %17 = sub nsw i64 %.tr25, %15
  %18 = shl nsw i64 %.tr1826, 1
  %19 = add i64 %accumulator.tr24, %2
  %20 = add i64 %19, %16
  %accumulator.ret.tr = add i64 %20, %accumulator.tr
  br label %tailrecurse48

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %tailrecurse48
  %accumulator.tr.lcssa = phi i64 [ 0, %tailrecurse48 ], [ %11, %tailrecurse ]
  %.tr18.lcssa = phi i64 [ %.tr49, %tailrecurse48 ], [ %9, %tailrecurse ]
  %accumulator.ret.tr20 = add nsw i64 %.tr18.lcssa, %accumulator.tr.lcssa
  %accumulator.ret.tr51 = add i64 %accumulator.ret.tr20, %accumulator.tr
  ret i64 %accumulator.ret.tr51
}

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: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass