; LLVM IR from DionysiosB/CodeForces :: 1300-1399 (1359C-MixingWater)

; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 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 i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca x86_fp80, align 16
  %8 = alloca x86_fp80, align 16
  %9 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %11

11:                                               ; preds = %108, %0
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = add nsw i64 %12, -1
  store i64 %13, ptr %2, align 8, !tbaa !5
  %14 = icmp ne i64 %12, 0
  br i1 %14, label %15, label %109

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = icmp sge i64 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = call i32 @puts(ptr noundef @.str.2)
  br label %108

22:                                               ; preds = %15
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = mul nsw i64 2, %23
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = add nsw i64 %25, %26
  %28 = icmp sle i64 %24, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %22
  %30 = call i32 @puts(ptr noundef @.str.3)
  br label %107

31:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = sub nsw i64 %32, %33
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = mul nsw i64 2, %35
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = sub nsw i64 %36, %37
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = sub nsw i64 %38, %39
  %41 = sdiv i64 %34, %40
  store i64 %41, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = sitofp i64 %42 to double
  %44 = fadd double %43, 1.000000e+00
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = sitofp i64 %45 to double
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = mul nsw i64 %47, %48
  %50 = sitofp i64 %49 to double
  %51 = call double @llvm.fmuladd.f64(double %44, double %46, double %50)
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = sitofp i64 %52 to double
  %54 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %53, double 1.000000e+00)
  %55 = fdiv double %51, %54
  %56 = load i64, ptr %5, align 8, !tbaa !5
  %57 = sitofp i64 %56 to double
  %58 = fsub double %55, %57
  %59 = fpext double %58 to x86_fp80
  store x86_fp80 %59, ptr %7, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = sitofp i64 %60 to double
  %62 = fadd double %61, 2.000000e+00
  %63 = load i64, ptr %3, align 8, !tbaa !5
  %64 = sitofp i64 %63 to double
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = add nsw i64 %65, 1
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = mul nsw i64 %66, %67
  %69 = sitofp i64 %68 to double
  %70 = call double @llvm.fmuladd.f64(double %62, double %64, double %69)
  %71 = load i64, ptr %6, align 8, !tbaa !9
  %72 = sitofp i64 %71 to double
  %73 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %72, double 3.000000e+00)
  %74 = fdiv double %70, %73
  %75 = load i64, ptr %5, align 8, !tbaa !5
  %76 = sitofp i64 %75 to double
  %77 = fsub double %74, %76
  %78 = fpext double %77 to x86_fp80
  store x86_fp80 %78, ptr %8, align 16, !tbaa !11
  %79 = load x86_fp80, ptr %7, align 16, !tbaa !11
  %80 = fcmp ogt x86_fp80 %79, 0xK00000000000000000000
  br i1 %80, label %81, label %83

81:                                               ; preds = %31
  %82 = load x86_fp80, ptr %7, align 16, !tbaa !11
  br label %86

83:                                               ; preds = %31
  %84 = load x86_fp80, ptr %7, align 16, !tbaa !11
  %85 = fneg x86_fp80 %84
  br label %86

86:                                               ; preds = %83, %81
  %87 = phi x86_fp80 [ %82, %81 ], [ %85, %83 ]
  store x86_fp80 %87, ptr %7, align 16, !tbaa !11
  %88 = load x86_fp80, ptr %8, align 16, !tbaa !11
  %89 = fcmp ogt x86_fp80 %88, 0xK00000000000000000000
  br i1 %89, label %90, label %92

90:                                               ; preds = %86
  %91 = load x86_fp80, ptr %8, align 16, !tbaa !11
  br label %95

92:                                               ; preds = %86
  %93 = load x86_fp80, ptr %8, align 16, !tbaa !11
  %94 = fneg x86_fp80 %93
  br label %95

95:                                               ; preds = %92, %90
  %96 = phi x86_fp80 [ %91, %90 ], [ %94, %92 ]
  store x86_fp80 %96, ptr %8, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %97 = load i64, ptr %6, align 8, !tbaa !9
  %98 = load x86_fp80, ptr %8, align 16, !tbaa !11
  %99 = load x86_fp80, ptr %7, align 16, !tbaa !11
  %100 = fcmp olt x86_fp80 %98, %99
  %101 = zext i1 %100 to i64
  %102 = add nsw i64 %97, %101
  %103 = mul nsw i64 2, %102
  %104 = add nsw i64 %103, 1
  store i64 %104, ptr %9, align 8, !tbaa !9
  %105 = load i64, ptr %9, align 8, !tbaa !9
  %106 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %105)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %107

107:                                              ; preds = %95, %29
  br label %108

108:                                              ; preds = %107, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %11, !llvm.loop !13

109:                                              ; preds = %11
  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

declare i32 @puts(ptr noundef) #2

; 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

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

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 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 i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = add nsw i64 %6, -1
  store i64 %7, ptr %1, align 8, !tbaa !5
  %.not20 = icmp eq i64 %6, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %61
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %.not18 = icmp slt i64 %9, %10
  br i1 %.not18, label %13, label %11

11:                                               ; preds = %.lr.ph
  %12 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %61

13:                                               ; preds = %.lr.ph
  %14 = shl nsw i64 %9, 1
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = add nsw i64 %15, %10
  %.not19 = icmp sgt i64 %14, %16
  br i1 %.not19, label %19, label %17

17:                                               ; preds = %13
  %18 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %61

19:                                               ; preds = %13
  %20 = sub nsw i64 %10, %9
  %21 = sub i64 %14, %16
  %22 = sdiv i64 %20, %21
  %23 = sitofp i64 %22 to double
  %24 = sitofp i64 %10 to double
  %25 = sitofp i64 %9 to double
  %26 = add nsw i64 %22, 1
  %27 = insertelement <2 x double> poison, double %23, i64 0
  %28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
  %29 = fadd <2 x double> %28, <double 2.000000e+00, double 1.000000e+00>
  %30 = insertelement <2 x i64> poison, i64 %26, i64 0
  %31 = insertelement <2 x i64> %30, i64 %22, i64 1
  %32 = insertelement <2 x i64> poison, i64 %15, i64 0
  %33 = shufflevector <2 x i64> %32, <2 x i64> poison, <2 x i32> zeroinitializer
  %34 = mul nsw <2 x i64> %31, %33
  %35 = sitofp <2 x i64> %34 to <2 x double>
  %36 = insertelement <2 x double> poison, double %24, i64 0
  %37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> zeroinitializer
  %38 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %29, <2 x double> %37, <2 x double> %35)
  %39 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> <double 3.000000e+00, double 1.000000e+00>)
  %40 = fdiv <2 x double> %38, %39
  %41 = insertelement <2 x double> poison, double %25, i64 0
  %42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> zeroinitializer
  %43 = fsub <2 x double> %40, %42
  %44 = extractelement <2 x double> %43, i64 1
  %45 = fpext double %44 to x86_fp80
  %46 = extractelement <2 x double> %43, i64 0
  %47 = fpext double %46 to x86_fp80
  %48 = fneg x86_fp80 %45
  %49 = fcmp ogt <2 x double> %43, zeroinitializer
  %50 = extractelement <2 x i1> %49, i64 1
  %51 = select i1 %50, x86_fp80 %45, x86_fp80 %48
  %52 = fneg x86_fp80 %47
  %53 = extractelement <2 x i1> %49, i64 0
  %54 = select i1 %53, x86_fp80 %47, x86_fp80 %52
  %55 = fcmp olt x86_fp80 %54, %51
  %56 = zext i1 %55 to i64
  %57 = add nsw i64 %22, %56
  %58 = shl nsw i64 %57, 1
  %59 = or disjoint i64 %58, 1
  %60 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %59)
  br label %61

61:                                               ; preds = %17, %19, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %62 = load i64, ptr %1, align 8, !tbaa !5
  %63 = add nsw i64 %62, -1
  store i64 %63, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %62, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %61, %0
  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: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass