; LLVM IR from reyadussalahin/problem-solving :: search/binary_search/codeforces/F701D (Solution)

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

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sitofp i32 %16 to double
  %18 = fadd double 0.000000e+00, %17
  store double %18, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sitofp i32 %19 to double
  %21 = fadd double 0.000000e+00, %20
  store double %21, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add nsw i32 %22, %23
  %25 = sub nsw i32 %24, 1
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = sdiv i32 %25, %26
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %84, %0
  %29 = load double, ptr %8, align 8, !tbaa !5
  %30 = load double, ptr %7, align 8, !tbaa !5
  %31 = fsub double %29, %30
  %32 = fcmp ogt double %31, 1.000000e-09
  br i1 %32, label %33, label %85

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %34 = load double, ptr %7, align 8, !tbaa !5
  %35 = load double, ptr %8, align 8, !tbaa !5
  %36 = fadd double %34, %35
  %37 = fdiv double %36, 2.000000e+00
  store double %37, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %38 = load double, ptr %11, align 8, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sub nsw i32 %39, %40
  %42 = sitofp i32 %41 to double
  %43 = fmul double %38, %42
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = sitofp i32 %44 to double
  %46 = fadd double 0.000000e+00, %45
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = sitofp i32 %47 to double
  %49 = fadd double %46, %48
  %50 = fdiv double %43, %49
  store double %50, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %51 = load double, ptr %11, align 8, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = sitofp i32 %52 to double
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 1
  %56 = sitofp i32 %55 to double
  %57 = load double, ptr %12, align 8, !tbaa !5
  %58 = fmul double %56, %57
  %59 = call double @llvm.fmuladd.f64(double %51, double %53, double %58)
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = sitofp i32 %60 to double
  %62 = fdiv double %59, %61
  store double %62, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %63 = load double, ptr %11, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = sitofp i32 %64 to double
  %66 = fdiv double %63, %65
  %67 = load i32, ptr %3, align 4, !tbaa !9
  %68 = sitofp i32 %67 to double
  %69 = load double, ptr %11, align 8, !tbaa !5
  %70 = fsub double %68, %69
  %71 = load i32, ptr %4, align 4, !tbaa !9
  %72 = sitofp i32 %71 to double
  %73 = fdiv double %70, %72
  %74 = fadd double %66, %73
  store double %74, ptr %14, align 8, !tbaa !5
  %75 = load double, ptr %13, align 8, !tbaa !5
  %76 = load double, ptr %14, align 8, !tbaa !5
  %77 = fadd double %76, 1.000000e-09
  %78 = fcmp ole double %75, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %33
  %80 = load double, ptr %14, align 8, !tbaa !5
  store double %80, ptr %9, align 8, !tbaa !5
  %81 = load double, ptr %11, align 8, !tbaa !5
  store double %81, ptr %7, align 8, !tbaa !5
  br label %84

82:                                               ; preds = %33
  %83 = load double, ptr %11, align 8, !tbaa !5
  store double %83, ptr %8, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %82, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %28, !llvm.loop !11

85:                                               ; preds = %28
  %86 = load double, ptr %9, align 8, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %86)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 speculatable willreturn memory(none) }
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 = !{!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"

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sitofp i32 %7 to double
  %9 = icmp sgt i32 %7, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = add i32 %10, -1
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = add i32 %11, %12
  %14 = sdiv i32 %13, %12
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sub nsw i32 %15, %16
  %18 = sitofp i32 %17 to double
  %19 = insertelement <2 x i32> poison, i32 %15, i64 0
  %20 = insertelement <2 x i32> %19, i32 %16, i64 1
  %21 = sitofp <2 x i32> %20 to <2 x double>
  %22 = extractelement <2 x double> %21, i64 0
  %shift = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %23 = fadd <2 x double> %shift, %21
  %24 = extractelement <2 x double> %23, i64 0
  %25 = sitofp i32 %14 to double
  %26 = add nsw i32 %14, -1
  %27 = sitofp i32 %26 to double
  br label %28

28:                                               ; preds = %.lr.ph, %28
  %.022 = phi double [ 0.000000e+00, %.lr.ph ], [ %.0., %28 ]
  %.01621 = phi double [ %8, %.lr.ph ], [ %..016, %28 ]
  %.01820 = phi double [ %8, %.lr.ph ], [ %.018., %28 ]
  %29 = fadd double %.01621, %.022
  %30 = fmul double %29, 5.000000e-01
  %31 = fmul double %30, %18
  %32 = fdiv double %31, %24
  %33 = fmul double %32, %27
  %34 = call double @llvm.fmuladd.f64(double %30, double %25, double %33)
  %35 = fdiv double %34, %22
  %36 = fsub double %8, %30
  %37 = insertelement <2 x double> poison, double %30, i64 0
  %38 = insertelement <2 x double> %37, double %36, i64 1
  %39 = fdiv <2 x double> %38, %21
  %shift23 = shufflevector <2 x double> %39, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %40 = fadd <2 x double> %39, %shift23
  %41 = extractelement <2 x double> %40, i64 0
  %42 = fadd double %41, 1.000000e-09
  %43 = fcmp ugt double %35, %42
  %.018. = select i1 %43, double %.01820, double %41
  %..016 = select i1 %43, double %30, double %.01621
  %.0. = select i1 %43, double %.022, double %30
  %44 = fsub double %..016, %.0.
  %45 = fcmp ogt double %44, 1.000000e-09
  br i1 %45, label %28, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %28, %0
  %.018.lcssa = phi double [ %8, %0 ], [ %.018., %28 ]
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %.018.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

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

attributes #0 = { mustprogress nofree 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass