#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ stderr;
unsigned int log_base_2(unsigned int x) {
  unsigned int s, r;
  r = 0;
  s = 1;
  while (s < x) {
    r++;
    s *= 2;
  }
  if (s > x) {
    fprintf(stderr,
            "log_base_2: %x no es un entero potencia de 2 mayor que 0\n", x);
    exit(-1);
  }
  return r;
}


x86 assembly (clang, -O0):
<log_base_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    115c <log_base_2+0x3c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <log_base_2+0x19>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jbe    118a <log_base_2+0x6a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe85(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_base_2>:
mov    %edi,%edx
cmp    $0x2,%edi
jb     113b <log_base_2+0x1b>
mov    $0x1,%ecx
xor    %eax,%eax
xchg   %ax,%ax
add    $0x1,%eax
add    %ecx,%ecx
cmp    %edx,%ecx
jb     1130 <log_base_2+0x10>
jmp    1142 <log_base_2+0x22>
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %edx,%ecx
ja     1147 <log_base_2+0x27>
ret
push   %rax
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [58 x i8] c"log_base_2: %x no es un entero potencia de 2 mayor que 0\0A\00"
define i32 @log_base_2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 1, i32* %3
br label %5
5: ; preds = %9, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp ult i32 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = load i32, i32* %4
%11 = add i32 %10, 1
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = mul i32 %12, 2
store i32 %13, i32* %3
br label %5
14: ; preds = %5
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp ugt i32 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* %2
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %14
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [58 x i8] c"log_base_2: %x no es un entero potencia de 2 mayor que 0\0A\00"
define i32 @log_base_2(i32 %0) {
%2 = icmp ugt i32 %0, 1
br i1 %2, label %3, label %9
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ 0, %1 ]
%5 = phi i32 [ %7, %3 ], [ 1, %1 ]
%6 = add i32 %4, 1
%7 = shl i32 %5, 1
%8 = icmp ult i32 %7, %0
br i1 %8, label %3, label %9
9: ; preds = %3, %1
%10 = phi i32 [ 1, %1 ], [ %7, %3 ]
%11 = phi i32 [ 0, %1 ], [ %6, %3 ]
%12 = icmp ugt i32 %10, %0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %0)
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %9
ret i32 %11
}