; LLVM IR from MtSaka/library :: test/yosupo/number_theory/kth_root_integer.test.ll (Z16kth_root_integeryi)

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

%class.anon = type { ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z16kth_root_integeryi(i64 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca %class.anon, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %17, label %11

11:                                               ; preds = %2
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = icmp eq i64 %12, 1
  br i1 %13, label %17, label %14

14:                                               ; preds = %11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %19

17:                                               ; preds = %14, %11, %2
  %18 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %18, ptr %3, align 8
  br label %59

19:                                               ; preds = %14
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp sge i32 %20, 64
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i64 1, ptr %3, align 8
  br label %59

23:                                               ; preds = %19
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 2
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = uitofp i64 %27 to x86_fp80
  %29 = call x86_fp80 @sqrtl(x86_fp80 noundef %28) #4
  %30 = fptoui x86_fp80 %29 to i64
  store i64 %30, ptr %3, align 8
  br label %59

31:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %32 = getelementptr inbounds %class.anon, ptr %6, i32 0, i32 0
  store ptr %5, ptr %32, align 8, !tbaa !11
  %33 = getelementptr inbounds %class.anon, ptr %6, i32 0, i32 1
  store ptr %4, ptr %33, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = sdiv i32 64, %34
  store i32 %35, ptr %8, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %54, %31
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %57

40:                                               ; preds = %36
  %41 = load i64, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = shl i32 1, %42
  %44 = zext i32 %43 to i64
  %45 = or i64 %41, %44
  %46 = call noundef zeroext i1 @"_ZZ16kth_root_integeryiENK3$_0clEy"(ptr noundef nonnull align 8 dereferenceable(16) %6, i64 noundef %45)
  br i1 %46, label %47, label %53

47:                                               ; preds = %40
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = shl i32 1, %48
  %50 = zext i32 %49 to i64
  %51 = load i64, ptr %7, align 8, !tbaa !5
  %52 = or i64 %51, %50
  store i64 %52, ptr %7, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %47, %40
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %8, align 4, !tbaa !9
  br label %36, !llvm.loop !13

57:                                               ; preds = %39
  %58 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %58, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  br label %59

59:                                               ; preds = %57, %26, %22, %17
  %60 = load i64, ptr %3, align 8
  ret i64 %60
}

; Function Attrs: nounwind
declare x86_fp80 @sqrtl(x86_fp80 noundef) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @"_ZZ16kth_root_integeryiENK3$_0clEy"(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #3 align 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%class.anon = type { ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z16kth_root_integeryi(i64 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca %class.anon, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %or.cond = icmp ult i64 %0, 2
  %6 = icmp eq i32 %1, 1
  %or.cond3 = or i1 %or.cond, %6
  br i1 %or.cond3, label %23, label %7

7:                                                ; preds = %2
  %8 = icmp sgt i32 %1, 63
  br i1 %8, label %23, label %9

9:                                                ; preds = %7
  %10 = icmp eq i32 %1, 2
  br i1 %10, label %11, label %14

11:                                               ; preds = %9
  %12 = uitofp i64 %0 to x86_fp80
  %sqrt = tail call x86_fp80 @llvm.sqrt.f80(x86_fp80 %12)
  %13 = fptoui x86_fp80 %sqrt to i64
  br label %23

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  store ptr %4, ptr %5, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %3, ptr %15, align 8, !tbaa !11
  %16 = sdiv i32 64, %1
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %14
  %.011.lcssa = phi i64 [ 0, %14 ], [ %spec.select, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  br label %23

.lr.ph:                                           ; preds = %14, %.lr.ph
  %.016 = phi i32 [ %22, %.lr.ph ], [ %16, %14 ]
  %.01115 = phi i64 [ %spec.select, %.lr.ph ], [ 0, %14 ]
  %18 = shl nuw i32 1, %.016
  %19 = zext i32 %18 to i64
  %20 = or i64 %.01115, %19
  %21 = call noundef zeroext i1 @"_ZZ16kth_root_integeryiENK3$_0clEy"(ptr noundef nonnull align 8 dereferenceable(16) %5, i64 noundef %20)
  %spec.select = select i1 %21, i64 %20, i64 %.01115
  %22 = add nsw i32 %.016, -1
  %.not = icmp eq i32 %.016, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

23:                                               ; preds = %7, %2, %._crit_edge, %11
  %.012 = phi i64 [ %13, %11 ], [ %.011.lcssa, %._crit_edge ], [ %0, %2 ], [ 1, %7 ]
  ret i64 %.012
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @"_ZZ16kth_root_integeryiENK3$_0clEy"(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #2 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare x86_fp80 @llvm.sqrt.f80(x86_fp80) #3

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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