; LLVM IR from tangjz/acm-icpc :: hdu/5447.ll (Z5issqrn)

; 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 zeroext i1 @_Z5issqrn(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i128, align 16
  %4 = alloca i128, align 16
  %5 = alloca i128, align 16
  %6 = getelementptr inbounds { i64, i64 }, ptr %3, i32 0, i32 0
  store i64 %0, ptr %6, align 16
  %7 = getelementptr inbounds { i64, i64 }, ptr %3, i32 0, i32 1
  store i64 %1, ptr %7, align 8
  %8 = load i128, ptr %3, align 16, !tbaa !5
  store i128 %8, ptr %4, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  %9 = load i128, ptr %4, align 16, !tbaa !5
  %10 = sitofp i128 %9 to x86_fp80
  %11 = fptrunc x86_fp80 %10 to double
  %12 = call double @sqrt(double noundef %11) #4
  %13 = call double @llvm.ceil.f64(double %12)
  %14 = fptosi double %13 to i128
  store i128 %14, ptr %5, align 16, !tbaa !5
  br label %15

15:                                               ; preds = %22, %2
  %16 = load i128, ptr %5, align 16, !tbaa !5
  %17 = load i128, ptr %5, align 16, !tbaa !5
  %18 = mul nsw i128 %16, %17
  %19 = load i128, ptr %4, align 16, !tbaa !5
  %20 = icmp sle i128 %18, %19
  br i1 %20, label %21, label %25

21:                                               ; preds = %15
  br label %22

22:                                               ; preds = %21
  %23 = load i128, ptr %5, align 16, !tbaa !5
  %24 = add nsw i128 %23, 1
  store i128 %24, ptr %5, align 16, !tbaa !5
  br label %15, !llvm.loop !9

25:                                               ; preds = %15
  %26 = load i128, ptr %5, align 16, !tbaa !5
  %27 = add nsw i128 %26, -1
  store i128 %27, ptr %5, align 16, !tbaa !5
  br label %28

28:                                               ; preds = %35, %25
  %29 = load i128, ptr %5, align 16, !tbaa !5
  %30 = load i128, ptr %5, align 16, !tbaa !5
  %31 = mul nsw i128 %29, %30
  %32 = load i128, ptr %4, align 16, !tbaa !5
  %33 = icmp sgt i128 %31, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %28
  br label %35

35:                                               ; preds = %34
  %36 = load i128, ptr %5, align 16, !tbaa !5
  %37 = add nsw i128 %36, -1
  store i128 %37, ptr %5, align 16, !tbaa !5
  br label %28, !llvm.loop !11

38:                                               ; preds = %28
  %39 = load i128, ptr %5, align 16, !tbaa !5
  %40 = load i128, ptr %5, align 16, !tbaa !5
  %41 = mul nsw i128 %39, %40
  %42 = load i128, ptr %4, align 16, !tbaa !5
  %43 = icmp eq i128 %41, %42
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  ret i1 %43
}

; 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 double @sqrt(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.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 = !{!"__int128", !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 nofree nounwind memory(write) uwtable
define dso_local noundef zeroext i1 @_Z5issqrn(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.sroa.2.0.insert.ext = zext i64 %1 to i128
  %.sroa.2.0.insert.shift = shl nuw i128 %.sroa.2.0.insert.ext, 64
  %.sroa.0.0.insert.ext = zext i64 %0 to i128
  %.sroa.0.0.insert.insert = or disjoint i128 %.sroa.2.0.insert.shift, %.sroa.0.0.insert.ext
  %3 = sitofp i128 %.sroa.0.0.insert.insert to x86_fp80
  %4 = fptrunc x86_fp80 %3 to double
  %5 = tail call double @sqrt(double noundef %4) #3
  %6 = tail call double @llvm.ceil.f64(double %5)
  %7 = fptosi double %6 to i128
  br label %8

8:                                                ; preds = %8, %2
  %.0 = phi i128 [ %7, %2 ], [ %10, %8 ]
  %9 = mul nsw i128 %.0, %.0
  %.not = icmp sgt i128 %9, %.sroa.0.0.insert.insert
  %10 = add nsw i128 %.0, 1
  br i1 %.not, label %.preheader, label %8, !llvm.loop !5

.preheader:                                       ; preds = %8, %.preheader
  %.1.in = phi i128 [ %.1, %.preheader ], [ %.0, %8 ]
  %.1 = add nsw i128 %.1.in, -1
  %11 = mul nsw i128 %.1, %.1
  %12 = icmp sgt i128 %11, %.sroa.0.0.insert.insert
  br i1 %12, label %.preheader, label %13, !llvm.loop !7

13:                                               ; preds = %.preheader
  %14 = icmp eq i128 %11, %.sroa.0.0.insert.insert
  ret i1 %14
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(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 nofree nounwind memory(write) 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass