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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int clz(int);
uint32_t binlog(uint32_t x) {
  uint32_t k;
  k = (x == 0) ? 31 : clz(x);
  assert(k < 32);
  return (x & (~0x80000000u >> k)) ? 32 - k : 31 - k;
}


x86 assembly (clang, -O0):
<binlog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1142 <binlog+0x22>
mov    $0x1f,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <binlog+0x2d>
mov    -0x4(%rbp),%edi
call   1030 <clz@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x7fffffff,%edx
shr    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     118e <binlog+0x6e>
mov    $0x20,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1199 <binlog+0x79>
mov    $0x1f,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binlog>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
test   %edi,%edi
je     1134 <binlog+0x14>
mov    %ebx,%edi
call   1030 <clz@plt>
mov    %eax,%ebp
jmp    1139 <binlog+0x19>
mov    $0x1f,%ebp
xor    %edi,%edi
cmp    $0x20,%ebp
setl   %dil
call   1040 <assert@plt>
mov    %ebp,%ecx
shl    %cl,%ebx
and    $0x7fffffff,%ebx
cmp    $0x1,%ebx
sbb    %eax,%eax
sub    %ebp,%eax
add    $0x20,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @binlog(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
br label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32 @clz(i32 %8)
br label %10
10: ; preds = %7, %6
%11 = phi i32 [ 31, %6 ], [ %9, %7 ]
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 32
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = lshr i32 2147483647, %17
%19 = and i32 %16, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %10
%22 = load i32, i32* %3
%23 = sub nsw i32 32, %22
br label %27
24: ; preds = %10
%25 = load i32, i32* %3
%26 = sub nsw i32 31, %25
br label %27
27: ; preds = %24, %21
%28 = phi i32 [ %23, %21 ], [ %26, %24 ]
ret i32 %28
}

LLVM IR (-O2):
define i32 @binlog(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 @clz(i32 %0)
br label %5
5: ; preds = %1, %3
%6 = phi i32 [ %4, %3 ], [ 31, %1 ]
%7 = icmp slt i32 %6, 32
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = lshr i32 2147483647, %6
%11 = and i32 %10, %0
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 31, i32 32
%14 = sub nsw i32 %13, %6
ret i32 %14
}