; LLVM IR from andreimaximov/algorithms :: codeforces/geometric-progression/main.ll (Z4ipowiii)

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

13:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %48

14:                                               ; preds = %3
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = srem i32 %15, 2
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %26

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = call noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #3
  %24 = call noundef i32 @_Z4ipowiii(i32 noundef %20, i32 noundef %22, i32 noundef %23)
  %25 = mul nsw i32 %19, %24
  store i32 %25, ptr %4, align 4
  br label %48

26:                                               ; preds = %14
  br label %27

27:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sdiv i32 %29, 2
  %31 = call noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #3
  %32 = call noundef i32 @_Z4ipowiii(i32 noundef %28, i32 noundef %30, i32 noundef %31)
  store i32 %32, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = mul nsw i64 %34, %36
  store i64 %37, ptr %9, align 8, !tbaa !9
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = icmp sgt i64 %38, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %27
  %43 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %43, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %47

44:                                               ; preds = %27
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %47

47:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %48

48:                                               ; preds = %47, %18, %13
  %49 = load i32, ptr %4, align 4
  ret i32 %49
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #1 align 2

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

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

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


; 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 nounwind uwtable
define dso_local noundef i32 @_Z4ipowiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, 0
  br i1 %4, label %common.ret48, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = and i32 %1, -2147483647
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %tailrecurse, label %.lr.ph._crit_edge

.lr.ph:                                           ; preds = %tailrecurse
  %7 = and i32 %9, -2147483647
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %tailrecurse, label %.lr.ph._crit_edge

tailrecurse:                                      ; preds = %.lr.ph.preheader, %.lr.ph
  %accumulator.tr2235 = phi i32 [ %11, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.tr162334 = phi i32 [ %9, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %9 = add nsw i32 %.tr162334, -1
  %10 = tail call noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #1
  %11 = mul nsw i32 %accumulator.tr2235, %0
  %12 = icmp eq i32 %9, 0
  br i1 %12, label %common.ret48, label %.lr.ph

common.ret48:                                     ; preds = %3, %tailrecurse, %.lr.ph._crit_edge
  %common.ret48.op = phi i32 [ %accumulator.ret.tr, %.lr.ph._crit_edge ], [ 1, %3 ], [ %11, %tailrecurse ]
  ret i32 %common.ret48.op

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.tr1724.lcssa = phi i32 [ %2, %.lr.ph.preheader ], [ %10, %.lr.ph ]
  %.tr1623.lcssa = phi i32 [ %1, %.lr.ph.preheader ], [ %9, %.lr.ph ]
  %accumulator.tr22.lcssa = phi i32 [ 1, %.lr.ph.preheader ], [ %11, %.lr.ph ]
  %13 = sdiv i32 %.tr1623.lcssa, 2
  %14 = tail call noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #1
  %15 = tail call noundef i32 @_Z4ipowiii(i32 noundef %0, i32 noundef %13, i32 noundef %14)
  %16 = sext i32 %15 to i64
  %17 = mul nsw i64 %16, %16
  %18 = sext i32 %.tr1724.lcssa to i64
  %19 = icmp sgt i64 %17, %18
  %20 = trunc i64 %17 to i32
  %.0 = select i1 %19, i32 %.tr1724.lcssa, i32 %20
  %accumulator.ret.tr = mul nsw i32 %.0, %accumulator.tr22.lcssa
  br label %common.ret48
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() local_unnamed_addr #0 align 2

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


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