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

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4calcxi(i64 noundef %0, i32 noundef %1) #3 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  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 8, 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 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %8)
  %10 = fdiv double %7, %9
  %11 = call double @llvm.ceil.f64(double %10)
  %12 = fptosi double %11 to i64
  store i64 %12, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %29, %2
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = sext i64 %14 to i128
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = sext i64 %16 to i128
  %18 = mul nsw i128 %15, %17
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = sext i64 %19 to i128
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = sext i64 %21 to i128
  %23 = mul nsw i128 %20, %22
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sext i32 %24 to i128
  %26 = mul nsw i128 %23, %25
  %27 = icmp sge i128 %18, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %13
  br label %29

29:                                               ; preds = %28
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !11

32:                                               ; preds = %13
  br label %33

33:                                               ; preds = %49, %32
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = sext i64 %34 to i128
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = sext i64 %36 to i128
  %38 = mul nsw i128 %35, %37
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = sext i64 %39 to i128
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = sext i64 %41 to i128
  %43 = mul nsw i128 %40, %42
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = sext i32 %44 to i128
  %46 = mul nsw i128 %43, %45
  %47 = icmp slt i128 %38, %46
  br i1 %47, label %48, label %52

48:                                               ; preds = %33
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = add nsw i64 %50, -1
  store i64 %51, ptr %5, align 8, !tbaa !5
  br label %33, !llvm.loop !13

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4calcxi(i64 noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = sitofp i64 %0 to double
  %4 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %1)
  %5 = fdiv double %3, %4
  %6 = tail call double @llvm.ceil.f64(double %5)
  %7 = fptosi double %6 to i64
  %8 = sext i64 %0 to i128
  %9 = mul nsw i128 %8, %8
  %10 = sext i32 %1 to i128
  br label %11

11:                                               ; preds = %11, %2
  %.0 = phi i64 [ %7, %2 ], [ %15, %11 ]
  %12 = sext i64 %.0 to i128
  %13 = mul nsw i128 %12, %10
  %14 = mul i128 %13, %12
  %.not = icmp slt i128 %9, %14
  %15 = add nsw i64 %.0, 1
  br i1 %.not, label %.preheader, label %11, !llvm.loop !5

.preheader:                                       ; preds = %11, %.preheader
  %.1 = phi i64 [ %20, %.preheader ], [ %.0, %11 ]
  %16 = sext i64 %.1 to i128
  %17 = mul nsw i128 %16, %10
  %18 = mul i128 %17, %16
  %19 = icmp slt i128 %9, %18
  %20 = add nsw i64 %.1, -1
  br i1 %19, label %.preheader, label %21, !llvm.loop !7

21:                                               ; preds = %.preheader
  ret i64 %.1
}

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

!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,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass