#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 */
typedef int uint64_t;

/* Variables and functions */
int compute_Y(int, double);
double convert_from_limit_time_window(int, int);
void convert_to_limit_time_window(double time, uint64_t *Y, uint64_t *F) {
  uint64_t current_Y = 0;
  uint64_t current_F = 0;
  double current_time = 0.0;
  double current_delta = 0.0;
  double delta = 2147483648.0;
  for (current_F = 0; current_F < 4; ++current_F) {
    current_Y = compute_Y(current_F, time);
    current_time = convert_from_limit_time_window(current_Y, current_F);
    current_delta = time - current_time;
    if (current_delta >= 0 && current_delta < delta) {
      delta = current_delta;
      *F = current_F;
      *Y = current_Y;
    }
  }
}


x86 assembly (clang, -O0):
<convert_to_limit_time_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xea5(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11f5 <convert_to_limit_time_window+0xd5>
mov    -0x20(%rbp),%edi
movsd  -0x8(%rbp),%xmm0
call   1030 <compute_Y@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <convert_from_limit_time_window@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e2 <convert_to_limit_time_window+0xc2>
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e2 <convert_to_limit_time_window+0xc2>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e7 <convert_to_limit_time_window+0xc7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1167 <convert_to_limit_time_window+0x47>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_to_limit_time_window>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1030 <compute_Y@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1040 <convert_from_limit_time_window@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,(%rsp)
jb     1187 <convert_to_limit_time_window+0x67>
movsd  0xe8d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1187 <convert_to_limit_time_window+0x67>
movl   $0x0,(%r14)
mov    %ebp,(%rbx)
movsd  %xmm1,(%rsp)
mov    $0x1,%edi
movapd %xmm2,%xmm0
call   1030 <compute_Y@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <convert_from_limit_time_window@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
ucomisd 0xe4f(%rip),%xmm1
jb     11d4 <convert_to_limit_time_window+0xb4>
movsd  (%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d4 <convert_to_limit_time_window+0xb4>
movl   $0x1,(%r14)
mov    %ebp,(%rbx)
movsd  %xmm1,(%rsp)
mov    $0x2,%edi
movapd %xmm2,%xmm0
call   1030 <compute_Y@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x2,%esi
call   1040 <convert_from_limit_time_window@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1221 <convert_to_limit_time_window+0x101>
movsd  (%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1221 <convert_to_limit_time_window+0x101>
movl   $0x2,(%r14)
mov    %ebp,(%rbx)
movsd  %xmm1,(%rsp)
mov    $0x3,%edi
movapd %xmm2,%xmm0
call   1030 <compute_Y@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x3,%esi
call   1040 <convert_from_limit_time_window@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
ucomisd 0xdb9(%rip),%xmm1
jb     1265 <convert_to_limit_time_window+0x145>
movsd  (%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1265 <convert_to_limit_time_window+0x145>
movl   $0x3,(%r14)
mov    %ebp,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @convert_to_limit_time_window(double %0, i32* %1, i32* %2) {
%4 = alloca double
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store double 0x41E0000000000000, double* %11
store i32 0, i32* %8
br label %12
12: ; preds = %38, %3
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = load i32, i32* %8
%17 = load double, double* %4
%18 = call i32 @compute_Y(i32 %16, double %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = call double @convert_from_limit_time_window(i32 %19, i32 %20)
store double %21, double* %9
%22 = load double, double* %4
%23 = load double, double* %9
%24 = fsub double %22, %23
store double %24, double* %10
%25 = load double, double* %10
%26 = fcmp oge double %25, 0.000000e+00
br i1 %26, label %27, label %37
27: ; preds = %15
%28 = load double, double* %10
%29 = load double, double* %11
%30 = fcmp olt double %28, %29
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load double, double* %10
store double %32, double* %11
%33 = load i32, i32* %8
%34 = load i32*, i32** %6
store i32 %33, i32* %34
%35 = load i32, i32* %7
%36 = load i32*, i32** %5
store i32 %35, i32* %36
br label %37
37: ; preds = %31, %27, %15
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %12
41: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @convert_to_limit_time_window(double %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @compute_Y(i32 0, double %0)
%5 = tail call double @convert_from_limit_time_window(i32 %4, i32 0)
%6 = fsub double %0, %5
%7 = fcmp oge double %6, 0.000000e+00
%8 = fcmp olt double %6, 0x41E0000000000000
%9 = and i1 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 0, i32* %2
store i32 %4, i32* %1
br label %11
11: ; preds = %3, %10
%12 = phi double [ %6, %10 ], [ 0x41E0000000000000, %3 ]
%13 = tail call i32 @compute_Y(i32 1, double %0)
%14 = tail call double @convert_from_limit_time_window(i32 %13, i32 1)
%15 = fsub double %0, %14
%16 = fcmp oge double %15, 0.000000e+00
%17 = fcmp olt double %15, %12
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 1, i32* %2
store i32 %13, i32* %1
br label %20
20: ; preds = %19, %11
%21 = phi double [ %15, %19 ], [ %12, %11 ]
%22 = tail call i32 @compute_Y(i32 2, double %0)
%23 = tail call double @convert_from_limit_time_window(i32 %22, i32 2)
%24 = fsub double %0, %23
%25 = fcmp oge double %24, 0.000000e+00
%26 = fcmp olt double %24, %21
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 2, i32* %2
store i32 %22, i32* %1
br label %29
29: ; preds = %28, %20
%30 = phi double [ %24, %28 ], [ %21, %20 ]
%31 = tail call i32 @compute_Y(i32 3, double %0)
%32 = tail call double @convert_from_limit_time_window(i32 %31, i32 3)
%33 = fsub double %0, %32
%34 = fcmp oge double %33, 0.000000e+00
%35 = fcmp olt double %33, %30
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 3, i32* %2
store i32 %31, i32* %1
br label %38
38: ; preds = %37, %29
ret void
}