; LLVM IR from tangjz/acm-icpc :: 51nod/1024.ll (Z5iRootii)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4iPowii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5iRootii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sitofp i32 %6 to double
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sitofp i32 %8 to double
  %10 = fdiv double 1.000000e+00, %9
  %11 = call double @pow(double noundef %7, double noundef %10) #4
  %12 = call double @llvm.ceil.f64(double %11)
  %13 = fptosi double %12 to i32
  store i32 %13, ptr %5, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %30, %2
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sitofp i32 %15 to double
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sitofp i32 %17 to double
  %19 = call double @pow(double noundef %16, double noundef %18) #4
  %20 = fcmp ole double %19, 2.000000e+04
  br i1 %20, label %21, label %27

21:                                               ; preds = %14
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = call noundef i32 @_Z4iPowii(i32 noundef %22, i32 noundef %23)
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br label %27

27:                                               ; preds = %21, %14
  %28 = phi i1 [ false, %14 ], [ %26, %21 ]
  br i1 %28, label %29, label %33

29:                                               ; preds = %27
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %14, !llvm.loop !9

33:                                               ; preds = %27
  br label %34

34:                                               ; preds = %50, %33
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sitofp i32 %35 to double
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sitofp i32 %37 to double
  %39 = call double @pow(double noundef %36, double noundef %38) #4
  %40 = fcmp ogt double %39, 2.000000e+04
  br i1 %40, label %47, label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = call noundef i32 @_Z4iPowii(i32 noundef %42, i32 noundef %43)
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = icmp sgt i32 %44, %45
  br label %47

47:                                               ; preds = %41, %34
  %48 = phi i1 [ true, %34 ], [ %46, %41 ]
  br i1 %48, label %49, label %53

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %5, align 4, !tbaa !5
  br label %34, !llvm.loop !11

53:                                               ; preds = %47
  %54 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %54
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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
declare dso_local noundef i32 @_Z4iPowii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5iRootii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sitofp i32 %0 to double
  %4 = sitofp i32 %1 to double
  %5 = fdiv double 1.000000e+00, %4
  %6 = tail call double @pow(double noundef %3, double noundef %5) #3
  %7 = tail call double @llvm.ceil.f64(double %6)
  %8 = fptosi double %7 to i32
  %9 = sitofp i32 %8 to double
  %10 = tail call double @pow(double noundef %9, double noundef %4) #3
  %11 = fcmp ugt double %10, 2.000000e+04
  br i1 %11, label %.critedge.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %2, %13
  %.017 = phi i32 [ %14, %13 ], [ %8, %2 ]
  %12 = tail call noundef i32 @_Z4iPowii(i32 noundef %.017, i32 noundef %1)
  %.not = icmp sgt i32 %12, %0
  br i1 %.not, label %.critedge.preheader, label %13

13:                                               ; preds = %.lr.ph
  %14 = add nsw i32 %.017, 1
  %15 = sitofp i32 %14 to double
  %16 = tail call double @pow(double noundef %15, double noundef %4) #3
  %17 = fcmp ugt double %16, 2.000000e+04
  br i1 %17, label %.critedge.preheader, label %.lr.ph, !llvm.loop !5

.critedge.preheader:                              ; preds = %.lr.ph, %13, %2
  %.1.ph = phi i32 [ %8, %2 ], [ %.017, %.lr.ph ], [ %14, %13 ]
  br label %.critedge

.critedge:                                        ; preds = %.critedge.preheader, %.critedge2
  %.1 = phi i32 [ %24, %.critedge2 ], [ %.1.ph, %.critedge.preheader ]
  %18 = sitofp i32 %.1 to double
  %19 = tail call double @pow(double noundef %18, double noundef %4) #3
  %20 = fcmp ogt double %19, 2.000000e+04
  br i1 %20, label %.critedge2, label %21

21:                                               ; preds = %.critedge
  %22 = tail call noundef i32 @_Z4iPowii(i32 noundef %.1, i32 noundef %1)
  %23 = icmp sgt i32 %22, %0
  br i1 %23, label %.critedge2, label %25

.critedge2:                                       ; preds = %.critedge, %21
  %24 = add nsw i32 %.1, -1
  br label %.critedge, !llvm.loop !7

25:                                               ; preds = %21
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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