; LLVM IR from tangjz/acm-icpc :: 51nod/1837.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: 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) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = sitofp i64 %5 to x86_fp80
  %7 = call x86_fp80 @sqrtl(x86_fp80 noundef %6) #3
  %8 = fptosi x86_fp80 %7 to i64
  store i64 %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = mul nsw i64 %9, %10
  store i64 %11, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %21, %1
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = shl i64 %14, 1
  %16 = or i64 %15, 1
  %17 = add nsw i64 %13, %16
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = icmp sle i64 %17, %18
  br i1 %19, label %20, label %28

20:                                               ; preds = %12
  br label %21

21:                                               ; preds = %20
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %3, align 8, !tbaa !5
  %24 = shl i64 %22, 1
  %25 = or i64 %24, 1
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = add nsw i64 %26, %25
  store i64 %27, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !9

28:                                               ; preds = %12
  br label %29

29:                                               ; preds = %34, %28
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = icmp sgt i64 %30, %31
  br i1 %32, label %33, label %41

33:                                               ; preds = %29
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = add nsw i64 %35, -1
  store i64 %36, ptr %3, align 8, !tbaa !5
  %37 = shl i64 %36, 1
  %38 = or i64 %37, 1
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = sub nsw i64 %39, %38
  store i64 %40, ptr %4, align 8, !tbaa !5
  br label %29, !llvm.loop !11

41:                                               ; preds = %29
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %2, align 8, !tbaa !5
  %44 = icmp eq i64 %42, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i1 %44
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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 memory(write) uwtable
define dso_local noundef zeroext i1 @_Z9is_squarex(i64 noundef %0) local_unnamed_addr #0 {
  %2 = sitofp i64 %0 to x86_fp80
  %3 = tail call x86_fp80 @sqrtl(x86_fp80 noundef %2) #2
  %4 = fptosi x86_fp80 %3 to i64
  %5 = mul nsw i64 %4, %4
  br label %6

6:                                                ; preds = %6, %1
  %.014 = phi i64 [ %4, %1 ], [ %10, %6 ]
  %.0 = phi i64 [ %5, %1 ], [ %9, %6 ]
  %7 = shl i64 %.014, 1
  %8 = or disjoint i64 %7, 1
  %9 = add nsw i64 %8, %.0
  %.not = icmp sgt i64 %9, %0
  %10 = add nsw i64 %.014, 1
  br i1 %.not, label %.preheader, label %6, !llvm.loop !5

.preheader:                                       ; preds = %6
  %11 = icmp sgt i64 %.0, %0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.119 = phi i64 [ %14, %.lr.ph ], [ %.0, %.preheader ]
  %.11518 = phi i64 [ %12, %.lr.ph ], [ %.014, %.preheader ]
  %12 = add nsw i64 %.11518, -1
  %13 = shl i64 %12, 1
  %.neg = xor i64 %13, -1
  %14 = add i64 %.119, %.neg
  %15 = icmp sgt i64 %14, %0
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.1.lcssa = phi i64 [ %.0, %.preheader ], [ %14, %.lr.ph ]
  %16 = icmp eq i64 %.1.lcssa, %0
  ret i1 %16
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare x86_fp80 @sqrtl(x86_fp80 noundef) local_unnamed_addr #1

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 = { 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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass