; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (2438)

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

@x = external dso_local global double, align 8
@y = external dso_local global double, align 8
@l = external dso_local global double, align 8
@d = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %7

7:                                                ; preds = %60, %58, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x, ptr noundef @y, ptr noundef @l, ptr noundef @d)
  %9 = xor i32 %8, -1
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %61

11:                                               ; preds = %7
  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
  %12 = call double @acos(double noundef -1.000000e+00) #5
  %13 = fdiv double %12, 2.000000e+00
  store double %13, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %14 = load double, ptr @x, align 8, !tbaa !5
  %15 = load double, ptr @d, align 8, !tbaa !5
  %16 = fcmp olt double %14, %15
  br i1 %16, label %21, label %17

17:                                               ; preds = %11
  %18 = load double, ptr @y, align 8, !tbaa !5
  %19 = load double, ptr @d, align 8, !tbaa !5
  %20 = fcmp olt double %18, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %17, %11
  %22 = call i32 @puts(ptr noundef @.str.1)
  store i32 2, ptr %6, align 4
  br label %58, !llvm.loop !9

23:                                               ; preds = %17
  br label %24

24:                                               ; preds = %47, %23
  %25 = load double, ptr %3, align 8, !tbaa !5
  %26 = load double, ptr %2, align 8, !tbaa !5
  %27 = fsub double %25, %26
  %28 = fcmp ogt double %27, 1.000000e-08
  br i1 %28, label %29, label %48

29:                                               ; preds = %24
  %30 = load double, ptr %2, align 8, !tbaa !5
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = fadd double %30, %31
  %33 = fdiv double %32, 2.000000e+00
  store double %33, ptr %4, align 8, !tbaa !5
  %34 = load double, ptr %4, align 8, !tbaa !5
  %35 = load double, ptr %3, align 8, !tbaa !5
  %36 = fadd double %34, %35
  %37 = fdiv double %36, 2.000000e+00
  store double %37, ptr %5, align 8, !tbaa !5
  %38 = load double, ptr %4, align 8, !tbaa !5
  %39 = call noundef double @_Z5solved(double noundef %38)
  %40 = load double, ptr %5, align 8, !tbaa !5
  %41 = call noundef double @_Z5solved(double noundef %40)
  %42 = fcmp ogt double %39, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %29
  %44 = load double, ptr %5, align 8, !tbaa !5
  store double %44, ptr %3, align 8, !tbaa !5
  br label %47

45:                                               ; preds = %29
  %46 = load double, ptr %4, align 8, !tbaa !5
  store double %46, ptr %2, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %43
  br label %24, !llvm.loop !11

48:                                               ; preds = %24
  %49 = load double, ptr %4, align 8, !tbaa !5
  %50 = call noundef double @_Z5solved(double noundef %49)
  %51 = load double, ptr @y, align 8, !tbaa !5
  %52 = fcmp olt double %50, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %48
  %54 = call i32 @puts(ptr noundef @.str.2)
  br label %57

55:                                               ; preds = %48
  %56 = call i32 @puts(ptr noundef @.str.1)
  br label %57

57:                                               ; preds = %55, %53
  store i32 0, ptr %6, align 4
  br label %58

58:                                               ; preds = %57, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %59 = load i32, ptr %6, align 4
  switch i32 %59, label %62 [
    i32 0, label %60
    i32 2, label %7
  ]

60:                                               ; preds = %58
  br label %7, !llvm.loop !9

61:                                               ; preds = %7
  ret i32 0

62:                                               ; preds = %58
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nounwind
declare double @acos(double noundef) #4

declare i32 @puts(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 #2 = { "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 willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = 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"

@x = external dso_local global double, align 8
@y = external dso_local global double, align 8
@l = external dso_local global double, align 8
@d = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x, ptr noundef nonnull @y, ptr noundef nonnull @l, ptr noundef nonnull @d)
  %.not19 = icmp eq i32 %1, -1
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %20
  %2 = load double, ptr @x, align 8, !tbaa !5
  %3 = load double, ptr @d, align 8, !tbaa !5
  %4 = fcmp olt double %2, %3
  %5 = load double, ptr @y, align 8
  %6 = fcmp olt double %5, %3
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %20, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph, %.preheader
  %.018 = phi double [ %.0., %.preheader ], [ 0.000000e+00, %.lr.ph ]
  %.01317 = phi double [ %..013, %.preheader ], [ 0x3FF921FB54442D18, %.lr.ph ]
  %7 = fadd double %.01317, %.018
  %8 = fmul double %7, 5.000000e-01
  %9 = fadd double %.01317, %8
  %10 = fmul double %9, 5.000000e-01
  %11 = tail call noundef double @_Z5solved(double noundef %8)
  %12 = tail call noundef double @_Z5solved(double noundef %10)
  %13 = fcmp ogt double %11, %12
  %..013 = select i1 %13, double %10, double %.01317
  %.0. = select i1 %13, double %.018, double %8
  %14 = fsub double %..013, %.0.
  %15 = fcmp ogt double %14, 1.000000e-08
  br i1 %15, label %.preheader, label %16, !llvm.loop !11

16:                                               ; preds = %.preheader
  %17 = tail call noundef double @_Z5solved(double noundef %8)
  %18 = load double, ptr @y, align 8, !tbaa !5
  %19 = fcmp olt double %17, %18
  %.str.2..str.1 = select i1 %19, ptr @.str.2, ptr @.str.1
  br label %20

20:                                               ; preds = %16, %.lr.ph
  %.str.2.sink = phi ptr [ @.str.1, %.lr.ph ], [ %.str.2..str.1, %16 ]
  %21 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  %22 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x, ptr noundef nonnull @y, ptr noundef nonnull @l, ptr noundef nonnull @d)
  %.not = icmp eq i32 %22, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %20, %0
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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 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 #2 = { 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" }

!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"}
!11 = distinct !{!11, !10}


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