; LLVM IR from AllAlgorithms/c :: algorithms/math (fast_power)

; 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: nounwind uwtable
define dso_local i32 @fast_power(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 0, %6
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i32 1, ptr %3, align 4
  br label %27

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = and i32 %10, 1
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %20

13:                                               ; preds = %9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = call i32 @fast_power(i32 noundef %15, i32 noundef %17)
  %19 = mul nsw i32 %14, %18
  store i32 %19, ptr %3, align 4
  br label %27

20:                                               ; preds = %9
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = mul nsw i32 %21, %22
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sdiv i32 %24, 2
  %26 = call i32 @fast_power(i32 noundef %23, i32 noundef %25)
  store i32 %26, ptr %3, align 4
  br label %27

27:                                               ; preds = %20, %13, %8
  %28 = load i32, ptr %3, align 4
  ret i32 %28
}

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

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


; 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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @fast_power(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse.outer
  %.tr10.ph18 = phi i32 [ %5, %tailrecurse.outer ], [ %1, %2 ]
  %.tr.ph17 = phi i32 [ %.tr13.lcssa, %tailrecurse.outer ], [ %0, %2 ]
  %accumulator.tr.ph16 = phi i32 [ %6, %tailrecurse.outer ], [ 1, %2 ]
  %4 = and i32 %.tr10.ph18, 1
  %.not20 = icmp eq i32 %4, 0
  br i1 %.not20, label %tailrecurse, label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse, %.lr.ph
  %.tr1014.lcssa = phi i32 [ %.tr10.ph18, %.lr.ph ], [ %9, %tailrecurse ]
  %.tr13.lcssa = phi i32 [ %.tr.ph17, %.lr.ph ], [ %8, %tailrecurse ]
  %5 = add nsw i32 %.tr1014.lcssa, -1
  %6 = mul nsw i32 %.tr13.lcssa, %accumulator.tr.ph16
  %7 = icmp eq i32 %5, 0
  br i1 %7, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse:                                      ; preds = %.lr.ph, %tailrecurse
  %.tr1322 = phi i32 [ %8, %tailrecurse ], [ %.tr.ph17, %.lr.ph ]
  %.tr101421 = phi i32 [ %9, %tailrecurse ], [ %.tr10.ph18, %.lr.ph ]
  %8 = mul nsw i32 %.tr1322, %.tr1322
  %9 = ashr exact i32 %.tr101421, 1
  %10 = and i32 %.tr101421, 2
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %tailrecurse, label %tailrecurse.outer

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %2
  %split = phi i32 [ 1, %2 ], [ %6, %tailrecurse.outer ]
  ret i32 %split
}

attributes #0 = { nofree norecurse nosync nounwind 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,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass