#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 ssize_t;

/* Variables and functions */
int size2level(ssize_t size) {
  if (size <= 0) {
    return 0;
  }
  if (size > 2048) {
    return 0;
  }
  if (size < 32 && size > 0) {
    size = 32;
  }
  int i;
  i = 0;
  double test;
  test = (double)size;
  while (test > 1) {
    test = test / 2;
    i++;
  }
  i = i - 5;
  return i;
}


x86 assembly (clang, -O0):
<size2level>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     111d <size2level+0x1d>
movl   $0x0,-0x4(%rbp)
jmp    11ac <size2level+0xac>
cmpl   $0x800,-0x8(%rbp)
jle    1136 <size2level+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11ac <size2level+0xac>
cmpl   $0x20,-0x8(%rbp)
jge    1151 <size2level+0x51>
cmpl   $0x0,-0x8(%rbp)
jle    1151 <size2level+0x51>
movl   $0x20,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119d <size2level+0x9d>
movsd  -0x18(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <size2level+0x62>
mov    -0xc(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<size2level>:
lea    -0x801(%rdi),%ecx
xor    %eax,%eax
cmp    $0xfffff800,%ecx
jb     114d <size2level+0x4d>
cmp    $0x21,%edi
mov    $0x20,%eax
cmovae %edi,%eax
cvtsi2sd %eax,%xmm0
mov    $0xfffffffb,%eax
movsd  0xed4(%rip),%xmm1
movsd  0xed4(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mulsd  %xmm1,%xmm0
add    $0x1,%eax
ucomisd %xmm2,%xmm0
ja     1140 <size2level+0x40>
ret

LLVM IR (-O0):
define i32 @size2level(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %35
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 2048
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 0, i32* %2
br label %35
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 32
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 32, i32* %3
br label %20
20: ; preds = %19, %16, %13
store i32 0, i32* %4
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
store double %22, double* %5
br label %23
23: ; preds = %26, %20
%24 = load double, double* %5
%25 = fcmp ogt double %24, 1.000000e+00
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load double, double* %5
%28 = fdiv double %27, 2.000000e+00
store double %28, double* %5
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %23
31: ; preds = %23
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 5
store i32 %33, i32* %4
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %35
35: ; preds = %31, %12, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @size2level(i32 %0) {
%2 = add i32 %0, -2049
%3 = icmp ult i32 %2, -2048
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = icmp ugt i32 %0, 32
%6 = select i1 %5, i32 %0, i32 32
%7 = sitofp i32 %6 to double
br label %8
8: ; preds = %4, %8
%9 = phi double [ %11, %8 ], [ %7, %4 ]
%10 = phi i32 [ %12, %8 ], [ 0, %4 ]
%11 = fmul double %9, 5.000000e-01
%12 = add nuw nsw i32 %10, 1
%13 = fcmp ogt double %11, 1.000000e+00
br i1 %13, label %8, label %14
14: ; preds = %8
%15 = add nsw i32 %10, -4
br label %16
16: ; preds = %14, %1
%17 = phi i32 [ 0, %1 ], [ %15, %14 ]
ret i32 %17
}