#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double calcEntriesUptoAgeT(int, double, double);
double calcTGivenW(int, double);
int calcWinsizeGivenUptoageEntries(int n, double desiredAge,
                                   int desiredEntriesNum) {
  if (n <= 0)
    return 0;
  if (desiredAge <= 0)
    return 0;
  if (desiredEntriesNum >= n)
    return 0;
  double N = n;
  int maxW = n + 1;
  int w = 1;
  for (; w < maxW; w++) {
    double T = calcTGivenW(n, (double)w);
    double e = calcEntriesUptoAgeT(n, T, desiredAge);
    if (e >= desiredEntriesNum)
      break;
  }
  if (w == maxW) {
    return 0;
  }
  return w;
}


x86 assembly (clang, -O0):
<calcWinsizeGivenUptoageEntries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1149 <calcWinsizeGivenUptoageEntries+0x29>
movl   $0x0,-0x4(%rbp)
jmp    1214 <calcWinsizeGivenUptoageEntries+0xf4>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1163 <calcWinsizeGivenUptoageEntries+0x43>
movl   $0x0,-0x4(%rbp)
jmp    1214 <calcWinsizeGivenUptoageEntries+0xf4>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     117b <calcWinsizeGivenUptoageEntries+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1214 <calcWinsizeGivenUptoageEntries+0xf4>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f6 <calcWinsizeGivenUptoageEntries+0xd6>
mov    -0x8(%rbp),%edi
cvtsi2sdl -0x28(%rbp),%xmm0
call   1030 <calcTGivenW@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <calcEntriesUptoAgeT@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     11e3 <calcWinsizeGivenUptoageEntries+0xc3>
jmp    11f6 <calcWinsizeGivenUptoageEntries+0xd6>
jmp    11e8 <calcWinsizeGivenUptoageEntries+0xc8>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1195 <calcWinsizeGivenUptoageEntries+0x75>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    120e <calcWinsizeGivenUptoageEntries+0xee>
movl   $0x0,-0x4(%rbp)
jmp    1214 <calcWinsizeGivenUptoageEntries+0xf4>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcWinsizeGivenUptoageEntries>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
test   %edi,%edi
jle    11b1 <calcWinsizeGivenUptoageEntries+0x91>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    11b1 <calcWinsizeGivenUptoageEntries+0x91>
mov    %edi,%ebx
cmp    %edi,%esi
jge    11b1 <calcWinsizeGivenUptoageEntries+0x91>
movsd  %xmm0,0x10(%rsp)
lea    0x1(%rbx),%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%r15d
neg    %r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mov    %ebx,%edi
call   1030 <calcTGivenW@plt>
mov    %ebx,%edi
movsd  0x10(%rsp),%xmm1
call   1040 <calcEntriesUptoAgeT@plt>
ucomisd 0x8(%rsp),%xmm0
jae    11a9 <calcWinsizeGivenUptoageEntries+0x89>
lea    (%r15,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1170 <calcWinsizeGivenUptoageEntries+0x50>
mov    %r14d,%ebp
xor    %eax,%eax
cmp    %r14d,%ebp
cmovne %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calcWinsizeGivenUptoageEntries(i32 %0, double %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %5
store double %1, double* %6
store i32 %2, i32* %7
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %59
16: ; preds = %3
%17 = load double, double* %6
%18 = fcmp ole double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 0, i32* %4
br label %59
20: ; preds = %16
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = icmp sge i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %4
br label %59
25: ; preds = %20
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to double
store double %27, double* %8
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
store i32 1, i32* %10
br label %30
30: ; preds = %49, %25
%31 = load i32, i32* %10
%32 = load i32, i32* %9
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load i32, i32* %5
%36 = load i32, i32* %10
%37 = sitofp i32 %36 to double
%38 = call double @calcTGivenW(i32 %35, double %37)
store double %38, double* %11
%39 = load i32, i32* %5
%40 = load double, double* %11
%41 = load double, double* %6
%42 = call double @calcEntriesUptoAgeT(i32 %39, double %40, double %41)
store double %42, double* %12
%43 = load double, double* %12
%44 = load i32, i32* %7
%45 = sitofp i32 %44 to double
%46 = fcmp oge double %43, %45
br i1 %46, label %47, label %48
47: ; preds = %34
br label %52
48: ; preds = %34
br label %49
49: ; preds = %48
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %30
52: ; preds = %47, %30
%53 = load i32, i32* %10
%54 = load i32, i32* %9
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %57
56: ; preds = %52
store i32 0, i32* %4
br label %59
57: ; preds = %52
%58 = load i32, i32* %10
store i32 %58, i32* %4
br label %59
59: ; preds = %57, %56, %24, %19, %15
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
define i32 @calcWinsizeGivenUptoageEntries(i32 %0, double %1, i32 %2) {
%4 = icmp sgt i32 %0, 0
%5 = fcmp ugt double %1, 0.000000e+00
%6 = and i1 %4, %5
%7 = icmp slt i32 %2, %0
%8 = and i1 %6, %7
br i1 %8, label %9, label %25
9: ; preds = %3
%10 = add nuw i32 %0, 1
%11 = sitofp i32 %2 to double
br label %12
12: ; preds = %9, %18
%13 = phi i32 [ 1, %9 ], [ %19, %18 ]
%14 = sitofp i32 %13 to double
%15 = tail call double @calcTGivenW(i32 %0, double %14)
%16 = tail call double @calcEntriesUptoAgeT(i32 %0, double %15, double %1)
%17 = fcmp ult double %16, %11
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = add nuw i32 %13, 1
%20 = icmp eq i32 %13, %0
br i1 %20, label %21, label %12
21: ; preds = %18, %12
%22 = phi i32 [ %10, %18 ], [ %13, %12 ]
%23 = icmp eq i32 %22, %10
%24 = select i1 %23, i32 0, i32 %22
br label %25
25: ; preds = %3, %21
%26 = phi i32 [ %24, %21 ], [ 0, %3 ]
ret i32 %26
}