; LLVM IR from tangjz/acm-icpc :: 51nod (1629)

; 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"

@_ZL2pi = external hidden global double, align 8
@s = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4dcmpd(double noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z4calcd(double noundef) #0

; 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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %8 = load double, ptr @s, align 8, !tbaa !5
  %9 = fdiv double %8, 2.000000e+00
  %10 = load double, ptr @_ZL2pi, align 8, !tbaa !5
  %11 = fdiv double %9, %10
  %12 = call double @sqrt(double noundef %11) #5
  store double %12, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %42, %0
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 100
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %45

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %18 = load double, ptr %2, align 8, !tbaa !5
  %19 = load double, ptr %3, align 8, !tbaa !5
  %20 = load double, ptr %2, align 8, !tbaa !5
  %21 = fsub double %19, %20
  %22 = fdiv double %21, 3.000000e+00
  %23 = fadd double %18, %22
  store double %23, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = load double, ptr %3, align 8, !tbaa !5
  %26 = load double, ptr %2, align 8, !tbaa !5
  %27 = fsub double %25, %26
  %28 = fdiv double %27, 3.000000e+00
  %29 = fsub double %24, %28
  store double %29, ptr %6, align 8, !tbaa !5
  %30 = load double, ptr %5, align 8, !tbaa !5
  %31 = call noundef double @_Z4calcd(double noundef %30)
  %32 = load double, ptr %6, align 8, !tbaa !5
  %33 = call noundef double @_Z4calcd(double noundef %32)
  %34 = fsub double %31, %33
  %35 = call noundef i32 @_Z4dcmpd(double noundef %34)
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %17
  %38 = load double, ptr %6, align 8, !tbaa !5
  store double %38, ptr %3, align 8, !tbaa !5
  br label %41

39:                                               ; preds = %17
  %40 = load double, ptr %5, align 8, !tbaa !5
  store double %40, ptr %2, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %39, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !9
  br label %13, !llvm.loop !11

45:                                               ; preds = %16
  %46 = load double, ptr %2, align 8, !tbaa !5
  %47 = call noundef double @_Z4calcd(double noundef %46)
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %47)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #4

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 = { mustprogress norecurse 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 = { "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 #5 = { 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 = !{!"double", !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"}


; 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"

@_ZL2pi = external hidden local_unnamed_addr global double, align 8
@s = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4dcmpd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z4calcd(double noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s)
  %2 = load double, ptr @s, align 8, !tbaa !5
  %3 = fmul double %2, 5.000000e-01
  %4 = load double, ptr @_ZL2pi, align 8, !tbaa !5
  %5 = fdiv double %3, %4
  %6 = tail call double @sqrt(double noundef %5) #4
  br label %10

7:                                                ; preds = %10
  %8 = tail call noundef double @_Z4calcd(double noundef %.0.)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %8)
  ret i32 0

10:                                               ; preds = %0, %10
  %.017 = phi double [ 0.000000e+00, %0 ], [ %.0., %10 ]
  %.01216 = phi double [ %6, %0 ], [ %..012, %10 ]
  %.01415 = phi i32 [ 0, %0 ], [ %20, %10 ]
  %11 = fsub double %.01216, %.017
  %12 = fdiv double %11, 3.000000e+00
  %13 = fadd double %.017, %12
  %14 = fsub double %.01216, %12
  %15 = tail call noundef double @_Z4calcd(double noundef %13)
  %16 = tail call noundef double @_Z4calcd(double noundef %14)
  %17 = fsub double %15, %16
  %18 = tail call noundef i32 @_Z4dcmpd(double noundef %17)
  %19 = icmp sgt i32 %18, 0
  %..012 = select i1 %19, double %14, double %.01216
  %.0. = select i1 %19, double %.017, double %13
  %20 = add nuw nsw i32 %.01415, 1
  %exitcond.not = icmp eq i32 %20, 100
  br i1 %exitcond.not, label %7, label %10, !llvm.loop !9
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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 = { 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 norecurse 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 = { nofree 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass