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

; 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 @_Z5iRootxi(i64 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = sitofp i64 %6 to double
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %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 !9
  br label %14

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

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

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

30:                                               ; preds = %28
  br label %31

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

34:                                               ; preds = %28
  br label %35

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

42:                                               ; preds = %35
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = call noundef i32 @_Z4iPowii(i32 noundef %43, i32 noundef %44)
  %46 = sext i32 %45 to i64
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = icmp sgt i64 %46, %47
  br label %49

49:                                               ; preds = %42, %35
  %50 = phi i1 [ true, %35 ], [ %48, %42 ]
  br i1 %50, label %51, label %55

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %5, align 4, !tbaa !9
  br label %35, !llvm.loop !13

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

; 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 @_Z5iRootxi(i64 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sitofp i64 %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+06
  br i1 %11, label %.critedge.preheader, label %.lr.ph

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

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

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

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

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

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

27:                                               ; preds = %22
  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