#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 */
int abs(int);
int lengthBinaryToAllocate(int decimal) {
  unsigned int lengthToAllocate = 0;
  int residue = 1;
  int TEMP;
  if (decimal < 0) {
    TEMP = abs(decimal);
  } else if (decimal == 0 || decimal == 1) {
    return 1;
  } else {
    TEMP = decimal;
  }
  while (residue > 0) {
    residue = TEMP - (1 << lengthToAllocate);
    lengthToAllocate++;
  }
  return lengthToAllocate;
}


x86 assembly (clang, -O0):
<lengthBinaryToAllocate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1143 <lengthBinaryToAllocate+0x33>
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x14(%rbp)
jmp    116e <lengthBinaryToAllocate+0x5e>
cmpl   $0x0,-0x8(%rbp)
je     1157 <lengthBinaryToAllocate+0x47>
cmpl   $0x1,-0x8(%rbp)
jne    1163 <lengthBinaryToAllocate+0x53>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <lengthBinaryToAllocate+0x95>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    116e <lengthBinaryToAllocate+0x5e>
jmp    1173 <lengthBinaryToAllocate+0x63>
cmpl   $0x0,-0x10(%rbp)
jle    119f <lengthBinaryToAllocate+0x8f>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1173 <lengthBinaryToAllocate+0x63>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lengthBinaryToAllocate>:
test   %edi,%edi
js     1110 <lengthBinaryToAllocate+0x10>
mov    $0x1,%ecx
cmp    $0x2,%edi
jae    1112 <lengthBinaryToAllocate+0x12>
jmp    1130 <lengthBinaryToAllocate+0x30>
neg    %edi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xffffffff,%eax
shl    %cl,%eax
add    %edi,%eax
add    $0x1,%ecx
test   %eax,%eax
jg     1120 <lengthBinaryToAllocate+0x20>
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @lengthBinaryToAllocate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @abs(i32 %10)
store i32 %11, i32* %6
br label %22
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15, %12
store i32 1, i32* %2
br label %35
19: ; preds = %15
%20 = load i32, i32* %3
store i32 %20, i32* %6
br label %21
21: ; preds = %19
br label %22
22: ; preds = %21, %9
br label %23
23: ; preds = %26, %22
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = shl i32 1, %28
%30 = sub nsw i32 %27, %29
store i32 %30, i32* %5
%31 = load i32, i32* %4
%32 = add i32 %31, 1
store i32 %32, i32* %4
br label %23
33: ; preds = %23
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %18
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @lengthBinaryToAllocate(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = sub nsw i32 0, %0
br label %7
5: ; preds = %1
%6 = icmp ult i32 %0, 2
br i1 %6, label %15, label %7
7: ; preds = %5, %3
%8 = phi i32 [ %4, %3 ], [ %0, %5 ]
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ 0, %7 ], [ %13, %9 ]
%11 = shl nsw i32 -1, %10
%12 = add i32 %11, %8
%13 = add i32 %10, 1
%14 = icmp sgt i32 %12, 0
br i1 %14, label %9, label %15
15: ; preds = %9, %5
%16 = phi i32 [ 1, %5 ], [ %13, %9 ]
ret i32 %16
}