#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*/ abort();
int log_base2(int x) {
  int res = 0, value = x;
  if (!value)
    abort();
  while (!(value & 1)) {
    value >>= 1;
    res++;
  }
  if (value != 1)
    abort();
  return res;
}


x86 assembly (clang, -O0):
<log_base2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1139 <log_base2+0x29>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    113e <log_base2+0x2e>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1159 <log_base2+0x49>
jmp    1170 <log_base2+0x60>
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113e <log_base2+0x2e>
cmpl   $0x1,-0xc(%rbp)
je     1181 <log_base2+0x71>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_base2>:
push   %rax
test   %edi,%edi
je     1148 <log_base2+0x38>
xor    %eax,%eax
test   $0x1,%dil
jne    113f <log_base2+0x2f>
xor    %eax,%eax
mov    %edi,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
sar    %ecx
add    $0x1,%eax
test   $0x2,%dil
mov    %ecx,%edi
je     1130 <log_base2+0x20>
jmp    1141 <log_base2+0x31>
mov    %edi,%ecx
cmp    $0x1,%ecx
jne    1148 <log_base2+0x38>
pop    %rcx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @log_base2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* %2
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %1
br label %11
11: ; preds = %16, %10
%12 = load i32, i32* %4
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %4
%18 = ashr i32 %17, 1
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %11
21: ; preds = %11
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %21
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @log_base2(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = and i32 %0, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %15
6: ; preds = %1
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %3, %8
%9 = phi i32 [ %11, %8 ], [ %0, %3 ]
%10 = phi i32 [ %12, %8 ], [ 0, %3 ]
%11 = ashr i32 %9, 1
%12 = add nuw nsw i32 %10, 1
%13 = and i32 %9, 2
%14 = icmp eq i32 %13, 0
br i1 %14, label %8, label %15
15: ; preds = %8, %3
%16 = phi i32 [ 0, %3 ], [ %12, %8 ]
%17 = phi i32 [ %0, %3 ], [ %11, %8 ]
%18 = icmp eq i32 %17, 1
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 (...) @abort()
unreachable
21: ; preds = %15
ret i32 %16
}