; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/1144.ll (Z9is_squarex)

; 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: nounwind
declare double @sqrt(double noundef) #1

; 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
define dso_local noundef zeroext i1 @_Z9is_squarex(i64 noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = sitofp i64 %4 to double
  %6 = call double @sqrt(double noundef %5) #3
  %7 = fptosi double %6 to i64
  store i64 %7, ptr %3, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %17, %1
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = add nsw i64 %9, 1
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = add nsw i64 %11, 1
  %13 = mul nsw i64 %10, %12
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %8
  br label %17

17:                                               ; preds = %16
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = add nsw i64 %18, 1
  store i64 %19, ptr %3, align 8, !tbaa !5
  br label %8, !llvm.loop !9

20:                                               ; preds = %8
  br label %21

21:                                               ; preds = %28, %20
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = mul nsw i64 %22, %23
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = icmp sgt i64 %24, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %21
  br label %28

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

31:                                               ; preds = %21
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = mul nsw i64 %32, %33
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = icmp eq i64 %34, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i1 %36
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = 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 willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind memory(write) uwtable
define dso_local noundef zeroext i1 @_Z9is_squarex(i64 noundef %0) local_unnamed_addr #1 {
  %2 = sitofp i64 %0 to double
  %3 = tail call double @sqrt(double noundef %2) #2
  %4 = fptosi double %3 to i64
  br label %5

5:                                                ; preds = %5, %1
  %.0 = phi i64 [ %4, %1 ], [ %6, %5 ]
  %6 = add nsw i64 %.0, 1
  %7 = mul nsw i64 %6, %6
  %.not = icmp sgt i64 %7, %0
  br i1 %.not, label %.preheader, label %5, !llvm.loop !5

.preheader:                                       ; preds = %5, %.preheader
  %.1 = phi i64 [ %10, %.preheader ], [ %.0, %5 ]
  %8 = mul nsw i64 %.1, %.1
  %9 = icmp sgt i64 %8, %0
  %10 = add nsw i64 %.1, -1
  br i1 %9, label %.preheader, label %11, !llvm.loop !7

11:                                               ; preds = %.preheader
  %12 = icmp eq i64 %8, %0
  ret i1 %12
}

attributes #0 = { 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 #1 = { 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 #2 = { 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,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass