; LLVM IR from DionysiosB/CodeForces :: 0900-0999 (936A-SaveEnergy)

; 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 [14 x i8], align 1
@.str.1 = 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 i64, align 8
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = icmp slt i64 %10, %11
  br i1 %12, label %13, label %23

13:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = add nsw i64 %14, %15
  %17 = sub nsw i64 %16, 1
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = sdiv i64 %17, %18
  store i64 %19, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = mul nsw i64 %21, %20
  store i64 %22, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %23

23:                                               ; preds = %13, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = sitofp i64 %24 to double
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = sub nsw i64 %26, %27
  %29 = sitofp i64 %28 to double
  %30 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %29, double %25)
  store double %30, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %31 = load double, ptr %4, align 8, !tbaa !9
  %32 = load double, ptr %6, align 8, !tbaa !9
  %33 = fdiv double %31, %32
  %34 = fptosi double %33 to i64
  store i64 %34, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = mul nsw i64 %35, %36
  %38 = sitofp i64 %37 to double
  store double %38, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = sitofp i64 %39 to double
  %41 = load double, ptr %6, align 8, !tbaa !9
  %42 = load double, ptr %4, align 8, !tbaa !9
  %43 = fneg double %40
  %44 = call double @llvm.fmuladd.f64(double %43, double %41, double %42)
  store double %44, ptr %4, align 8, !tbaa !9
  %45 = load double, ptr %4, align 8, !tbaa !9
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %47 = sitofp i64 %46 to double
  %48 = fcmp olt double %45, %47
  br i1 %48, label %49, label %53

49:                                               ; preds = %23
  %50 = load double, ptr %4, align 8, !tbaa !9
  %51 = load double, ptr %8, align 8, !tbaa !9
  %52 = fadd double %51, %50
  store double %52, ptr %8, align 8, !tbaa !9
  br label %68

53:                                               ; preds = %23
  %54 = load double, ptr %4, align 8, !tbaa !9
  %55 = load double, ptr %6, align 8, !tbaa !9
  %56 = fcmp ole double %54, %55
  br i1 %56, label %57, label %67

57:                                               ; preds = %53
  %58 = load i64, ptr %2, align 8, !tbaa !5
  %59 = sitofp i64 %58 to double
  %60 = load double, ptr %4, align 8, !tbaa !9
  %61 = load i64, ptr %2, align 8, !tbaa !5
  %62 = sitofp i64 %61 to double
  %63 = fsub double %60, %62
  %64 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %63, double %59)
  %65 = load double, ptr %8, align 8, !tbaa !9
  %66 = fadd double %65, %64
  store double %66, ptr %8, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %57, %53
  br label %68

68:                                               ; preds = %67, %49
  %69 = load double, ptr %8, align 8, !tbaa !9
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %69)
  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
  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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; 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 [14 x i8], align 1
@.str.1 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = icmp slt i64 %5, %6
  br i1 %7, label %8, label %13

8:                                                ; preds = %0
  %9 = add nsw i64 %6, %5
  %.fr12 = freeze i64 %9
  %10 = add i64 %.fr12, -1
  %11 = srem i64 %10, %5
  %12 = sub nsw i64 %10, %11
  store i64 %12, ptr %2, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %8, %0
  %14 = phi i64 [ %12, %8 ], [ %5, %0 ]
  %15 = sitofp i64 %6 to double
  %16 = sub nsw i64 %14, %6
  %17 = sitofp i64 %16 to double
  %18 = call double @llvm.fmuladd.f64(double %17, double 5.000000e-01, double %15)
  %19 = load double, ptr %3, align 8, !tbaa !9
  %20 = fdiv double %19, %18
  %21 = fptosi double %20 to i64
  %22 = mul nsw i64 %14, %21
  %23 = sitofp i64 %22 to double
  %24 = sitofp i64 %21 to double
  %25 = fneg double %24
  %26 = call double @llvm.fmuladd.f64(double %25, double %18, double %19)
  store double %26, ptr %3, align 8, !tbaa !9
  %27 = fcmp olt double %26, %15
  br i1 %27, label %28, label %30

28:                                               ; preds = %13
  %29 = fadd double %26, %23
  br label %36

30:                                               ; preds = %13
  %31 = fcmp ugt double %26, %18
  br i1 %31, label %36, label %32

32:                                               ; preds = %30
  %33 = fsub double %26, %15
  %34 = call double @llvm.fmuladd.f64(double %33, double 2.000000e+00, double %15)
  %35 = fadd double %34, %23
  br label %36

36:                                               ; preds = %30, %32, %28
  %.0 = phi double [ %29, %28 ], [ %35, %32 ], [ %23, %30 ]
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %.0)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  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
}

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass