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

; 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 @_Z9is_triplei(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = shl i32 %5, 1
  %7 = sitofp i32 %6 to double
  %8 = call double @sqrt(double noundef %7) #3
  %9 = fptosi double %8 to i32
  store i32 %9, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = mul nsw i32 %10, %12
  %14 = ashr i32 %13, 1
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %23, %1
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  %19 = add nsw i32 %18, 1
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %15
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

28:                                               ; preds = %15
  br label %29

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

33:                                               ; preds = %29
  br label %34

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

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

; 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 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 = { 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 = !{!"int", !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_triplei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = shl i32 %0, 1
  %3 = sitofp i32 %2 to double
  %4 = tail call double @sqrt(double noundef %3) #2
  %5 = fptosi double %4 to i32
  %6 = add nsw i32 %5, 1
  %7 = mul nsw i32 %6, %5
  %8 = ashr i32 %7, 1
  %9 = add nsw i32 %8, %5
  %.not.not17 = icmp slt i32 %9, %0
  br i1 %.not.not17, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %1
  %.014.lcssa = phi i32 [ %5, %1 ], [ %11, %.lr.ph ]
  %.0.lcssa = phi i32 [ %8, %1 ], [ %12, %.lr.ph ]
  %10 = icmp sgt i32 %.0.lcssa, %0
  br i1 %10, label %.lr.ph23, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.019 = phi i32 [ %12, %.lr.ph ], [ %8, %1 ]
  %.01418 = phi i32 [ %11, %.lr.ph ], [ %5, %1 ]
  %11 = add nsw i32 %.01418, 1
  %12 = add nsw i32 %.019, %11
  %13 = add nsw i32 %12, %11
  %.not.not = icmp slt i32 %13, %0
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !5

.lr.ph23:                                         ; preds = %.preheader, %.lr.ph23
  %.122 = phi i32 [ %15, %.lr.ph23 ], [ %.0.lcssa, %.preheader ]
  %.11521 = phi i32 [ %14, %.lr.ph23 ], [ %.014.lcssa, %.preheader ]
  %14 = add nsw i32 %.11521, -1
  %15 = sub nsw i32 %.122, %.11521
  %16 = icmp sgt i32 %15, %0
  br i1 %16, label %.lr.ph23, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph23, %.preheader
  %.1.lcssa = phi i32 [ %.0.lcssa, %.preheader ], [ %15, %.lr.ph23 ]
  %17 = icmp eq i32 %.1.lcssa, %0
  ret i1 %17
}

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