#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 log(double const);
unsigned timelimit_to_flags(double timelimit) {
  const double tmax = 365 * 24 * 3600;
  const double tstep = 1.05;
  const int nsteps = (1 << 9);
  int x;
  if (timelimit >= tmax)
    return 0;
  if (timelimit <= 1.0e-10)
    return nsteps - 1;
  x = (int)(0.5 + (log(tmax / timelimit) / log(tstep)));
  if (x < 0)
    x = 0;
  if (x >= nsteps)
    x = nsteps - 1;
  return x;
}


x86 assembly (clang, -O0):
<timelimit_to_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xed6(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x200,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xeb5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1161 <timelimit_to_flags+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11eb <timelimit_to_flags+0xdb>
movsd  0xea7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1180 <timelimit_to_flags+0x70>
movl   $0x1ff,-0x4(%rbp)
jmp    11eb <timelimit_to_flags+0xdb>
movsd  0xe78(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xe69(%rip),%xmm0
call   1030 <log@plt>
movsd  -0x30(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe63(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11d1 <timelimit_to_flags+0xc1>
movl   $0x0,-0x28(%rbp)
cmpl   $0x200,-0x28(%rbp)
jl     11e5 <timelimit_to_flags+0xd5>
movl   $0x1ff,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timelimit_to_flags>:
push   %rax
xor    %eax,%eax
ucomisd 0xee5(%rip),%xmm0
jae    116e <timelimit_to_flags+0x5e>
mov    $0x1ff,%eax
movsd  0xede(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    116e <timelimit_to_flags+0x5e>
movsd  0xec8(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <log@plt>
divsd  0xec3(%rip),%xmm0
addsd  0xec3(%rip),%xmm0
cvttsd2si %xmm0,%eax
xor    %ecx,%ecx
test   %eax,%eax
cmovns %eax,%ecx
cmp    $0x1ff,%ecx
mov    $0x1ff,%eax
cmovb  %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @timelimit_to_flags(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double %0, double* %3
store double 3.153600e+07, double* %4
store double 1.050000e+00, double* %5
store i32 512, i32* %6
%8 = load double, double* %3
%9 = fcmp oge double %8, 3.153600e+07
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %32
11: ; preds = %1
%12 = load double, double* %3
%13 = fcmp ole double %12, 1.000000e-10
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 511, i32* %2
br label %32
15: ; preds = %11
%16 = load double, double* %3
%17 = fdiv double 3.153600e+07, %16
%18 = call double @log(double %17)
%19 = call double @log(double 1.050000e+00)
%20 = fdiv double %18, %19
%21 = fadd double 5.000000e-01, %20
%22 = fptosi double %21 to i32
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %15
store i32 0, i32* %7
br label %26
26: ; preds = %25, %15
%27 = load i32, i32* %7
%28 = icmp sge i32 %27, 512
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 511, i32* %7
br label %30
30: ; preds = %29, %26
%31 = load i32, i32* %7
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %14, %10
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @timelimit_to_flags(double %0) {
%2 = fcmp ult double %0, 3.153600e+07
br i1 %2, label %3, label %15
3: ; preds = %1
%4 = fcmp ugt double %0, 1.000000e-10
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = fdiv double 3.153600e+07, %0
%7 = tail call double @log(double %6)
%8 = fdiv double %7, 0x3FA8FB063EF2C7F0
%9 = fadd double %8, 5.000000e-01
%10 = fptosi double %9 to i32
%11 = icmp sgt i32 %10, 0
%12 = select i1 %11, i32 %10, i32 0
%13 = icmp ult i32 %12, 511
%14 = select i1 %13, i32 %12, i32 511
br label %15
15: ; preds = %3, %1, %5
%16 = phi i32 [ %14, %5 ], [ 0, %1 ], [ 511, %3 ]
ret i32 %16
}