; LLVM IR from DionysiosB/CodeForces :: 0800-0899 (808B-AverageSleepTime)

; 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 [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

12:                                               ; preds = %64, %0
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = load i64, ptr %2, align 8, !tbaa !9
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load i64, ptr %3, align 8, !tbaa !9
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = load i64, ptr %3, align 8, !tbaa !9
  %22 = sub nsw i64 %20, %21
  %23 = add nsw i64 %22, 1
  %24 = icmp slt i64 %19, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %17
  %26 = load i64, ptr %3, align 8, !tbaa !9
  br label %32

27:                                               ; preds = %17
  %28 = load i64, ptr %2, align 8, !tbaa !9
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = sub nsw i64 %28, %29
  %31 = add nsw i64 %30, 1
  br label %32

32:                                               ; preds = %27, %25
  %33 = phi i64 [ %26, %25 ], [ %31, %27 ]
  %34 = sitofp i64 %33 to double
  store double %34, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = load i64, ptr %2, align 8, !tbaa !9
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = sub nsw i64 %36, %37
  %39 = add nsw i64 %38, 1
  %40 = icmp slt i64 %35, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %32
  %42 = load i64, ptr %5, align 8, !tbaa !9
  br label %48

43:                                               ; preds = %32
  %44 = load i64, ptr %2, align 8, !tbaa !9
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = sub nsw i64 %44, %45
  %47 = add nsw i64 %46, 1
  br label %48

48:                                               ; preds = %43, %41
  %49 = phi i64 [ %42, %41 ], [ %47, %43 ]
  %50 = sitofp i64 %49 to double
  store double %50, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %51 = load double, ptr %7, align 8, !tbaa !5
  %52 = load double, ptr %8, align 8, !tbaa !5
  %53 = fcmp olt double %51, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %48
  %55 = load double, ptr %7, align 8, !tbaa !5
  br label %58

56:                                               ; preds = %48
  %57 = load double, ptr %8, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %56, %54
  %59 = phi double [ %55, %54 ], [ %57, %56 ]
  store double %59, ptr %9, align 8, !tbaa !5
  %60 = load double, ptr %9, align 8, !tbaa !5
  %61 = load double, ptr %6, align 8, !tbaa !5
  %62 = load double, ptr %4, align 8, !tbaa !5
  %63 = call double @llvm.fmuladd.f64(double %60, double %61, double %62)
  store double %63, ptr %4, align 8, !tbaa !5
  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 8, ptr %6) #4
  br label %64

64:                                               ; preds = %58
  %65 = load i64, ptr %5, align 8, !tbaa !9
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %5, align 8, !tbaa !9
  br label %12, !llvm.loop !11

67:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %68 = load double, ptr %4, align 8, !tbaa !5
  %69 = load i64, ptr %2, align 8, !tbaa !9
  %70 = load i64, ptr %3, align 8, !tbaa !9
  %71 = sub nsw i64 %69, %70
  %72 = add nsw i64 %71, 1
  %73 = sitofp i64 %72 to double
  %74 = fdiv double %68, %73
  store double %74, ptr %10, align 8, !tbaa !5
  %75 = load double, ptr %10, align 8, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %75)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 = !{!"long", !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 [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %6 = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %13, %.lr.ph ]
  %.0.lcssa = phi double [ 0.000000e+00, %.._crit_edge_crit_edge ], [ %26, %.lr.ph ]
  %.lcssa = phi i64 [ %5, %.._crit_edge_crit_edge ], [ %14, %.lr.ph ]
  %7 = add i64 %.lcssa, 1
  %8 = sub i64 %7, %6
  %9 = sitofp i64 %8 to double
  %10 = fdiv double %.0.lcssa, %9
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.022 = phi double [ %26, %.lr.ph ], [ 0.000000e+00, %0 ]
  %.01321 = phi i64 [ %27, %.lr.ph ], [ 1, %0 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %15 = sub nsw i64 %14, %13
  %.not18 = icmp sgt i64 %13, %15
  %16 = add nsw i64 %15, 1
  %17 = select i1 %.not18, i64 %16, i64 %13
  %18 = sitofp i64 %17 to double
  %19 = sub nsw i64 %14, %.01321
  %.not19 = icmp sgt i64 %.01321, %19
  %20 = add nsw i64 %19, 1
  %21 = select i1 %.not19, i64 %20, i64 %.01321
  %22 = sitofp i64 %21 to double
  %23 = fcmp olt double %18, %22
  %24 = select i1 %23, double %18, double %22
  %25 = load double, ptr %3, align 8, !tbaa !9
  %26 = call double @llvm.fmuladd.f64(double %24, double %25, double %.022)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %27 = add nuw nsw i64 %.01321, 1
  %.not.not = icmp slt i64 %.01321, %14
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

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


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