; LLVM IR from tangjz/acm-icpc :: spoj/DIVCNT1.ll (Z5iSqrty)

; 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 nounwind uwtable
define dso_local noundef i32 @_Z5iSqrty(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = uitofp i64 %5 to x86_fp80
  %7 = call x86_fp80 @sqrtl(x86_fp80 noundef %6) #4
  %8 = fptrunc x86_fp80 %7 to double
  %9 = call double @llvm.floor.f64(double %8)
  %10 = fptoui double %9 to i32
  store i32 %10, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = mul i64 %12, %14
  store i64 %15, ptr %4, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %21, %1
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = icmp ugt i64 %17, %18
  br i1 %19, label %20, label %30

20:                                               ; preds = %16
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add i32 %22, -1
  store i32 %23, ptr %3, align 4, !tbaa !9
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = shl i64 %25, 1
  %27 = or i64 %26, 1
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = sub i64 %28, %27
  store i64 %29, ptr %4, align 8, !tbaa !5
  br label %16, !llvm.loop !11

30:                                               ; preds = %16
  br label %31

31:                                               ; preds = %41, %30
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = sub i64 %32, %33
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = shl i64 %36, 1
  %38 = or i64 %37, 1
  %39 = icmp uge i64 %34, %38
  br i1 %39, label %40, label %50

40:                                               ; preds = %31
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = shl i64 %43, 1
  %45 = or i64 %44, 1
  %46 = load i64, ptr %4, align 8, !tbaa !5
  %47 = add i64 %46, %45
  store i64 %47, ptr %4, align 8, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %3, align 4, !tbaa !9
  br label %31, !llvm.loop !13

50:                                               ; preds = %31
  %51 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %51
}

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

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_Z5iSqrty(i64 noundef %0) local_unnamed_addr #0 {
  %2 = uitofp i64 %0 to x86_fp80
  %sqrt = tail call x86_fp80 @llvm.sqrt.f80(x86_fp80 %2)
  %3 = fptrunc x86_fp80 %sqrt to double
  %4 = tail call double @llvm.floor.f64(double %3)
  %5 = fptoui double %4 to i32
  %6 = zext i32 %5 to i64
  %7 = mul nuw i64 %6, %6
  %8 = icmp ugt i64 %7, %0
  br i1 %8, label %.lr.ph, label %..preheader_crit_edge

..preheader_crit_edge:                            ; preds = %1
  %.pre = shl nuw nsw i64 %6, 1
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph, %..preheader_crit_edge
  %.pre-phi28 = phi i64 [ %.pre, %..preheader_crit_edge ], [ %12, %.lr.ph ]
  %.015.lcssa = phi i32 [ %5, %..preheader_crit_edge ], [ %10, %.lr.ph ]
  %.0.lcssa = phi i64 [ %7, %..preheader_crit_edge ], [ %13, %.lr.ph ]
  %9 = sub i64 %0, %.0.lcssa
  %.not.not21 = icmp ugt i64 %9, %.pre-phi28
  br i1 %.not.not21, label %.lr.ph24, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.019 = phi i64 [ %13, %.lr.ph ], [ %7, %1 ]
  %.01518 = phi i32 [ %10, %.lr.ph ], [ %5, %1 ]
  %10 = add i32 %.01518, -1
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 1
  %.neg = xor i64 %12, -1
  %13 = add i64 %.019, %.neg
  %14 = icmp ugt i64 %13, %0
  br i1 %14, label %.lr.ph, label %.preheader, !llvm.loop !5

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %15 = phi i64 [ %21, %.lr.ph24 ], [ %.pre-phi28, %.preheader ]
  %.123 = phi i64 [ %17, %.lr.ph24 ], [ %.0.lcssa, %.preheader ]
  %.11622 = phi i32 [ %18, %.lr.ph24 ], [ %.015.lcssa, %.preheader ]
  %16 = add i64 %.123, 1
  %17 = add i64 %16, %15
  %18 = add i32 %.11622, 1
  %19 = sub i64 %0, %17
  %20 = zext i32 %18 to i64
  %21 = shl nuw nsw i64 %20, 1
  %.not.not = icmp ugt i64 %19, %21
  br i1 %.not.not, label %.lr.ph24, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph24, %.preheader
  %.116.lcssa = phi i32 [ %.015.lcssa, %.preheader ], [ %18, %.lr.ph24 ]
  ret i32 %.116.lcssa
}

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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: AggressiveInstCombinePass,BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass