#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 binary_search_unsigend_long(unsigned long *, unsigned long, int);
unsigned long pow(int, int /*<<< orphan*/);
int floor_log2(unsigned long N) {
  if (N == 0)
    return -1;
  unsigned long pow_set[64];
  for (int i = 0; i < 64; (pow_set[i - 1] = pow(2, i++)))
    ;
  return binary_search_unsigend_long(pow_set, N, 64);
}


x86 assembly (clang, -O0):
<floor_log2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <floor_log2+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <floor_log2+0x90>
movl   $0x0,-0x214(%rbp)
cmpl   $0x40,-0x214(%rbp)
jge    1198 <floor_log2+0x78>
jmp    1162 <floor_log2+0x42>
mov    -0x214(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %rax,%rcx
mov    -0x214(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rcx,-0x210(%rbp,%rax,8)
ff
jmp    1150 <floor_log2+0x30>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1030 <binary_search_unsigend_long@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floor_log2>:
test   %rdi,%rdi
je     11ab <floor_log2+0x8b>
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
mov    %rax,(%rsp,%rbx,8)
lea    0x1(%rbx),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %rax,0x8(%rsp,%rbx,8)
lea    0x2(%rbx),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %rax,0x10(%rsp,%rbx,8)
lea    0x3(%rbx),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %rax,0x18(%rsp,%rbx,8)
add    $0x4,%rbx
cmp    $0x40,%rbx
jne    1140 <floor_log2+0x20>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <binary_search_unsigend_long@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @floor_log2(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca [64 x i64]
%5 = alloca i32
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %26
9: ; preds = %1
store i32 0, i32* %5
br label %10
10: ; preds = %14, %9
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 64
br i1 %12, label %13, label %22
13: ; preds = %10
br label %14
14: ; preds = %13
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
%17 = call i64 @pow(i32 2, i32 %15)
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [64 x i64], [64 x i64]* %4, i64 0, i64 %20
store i64 %17, i64* %21
br label %10
22: ; preds = %10
%23 = getelementptr inbounds [64 x i64], [64 x i64]* %4, i64 0, i64 0
%24 = load i64, i64* %3
%25 = call i32 @binary_search_unsigend_long(i64* %23, i64 %24, i32 64)
store i32 %25, i32* %2
br label %26
26: ; preds = %22, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @floor_log2(i64 %0) {
%2 = alloca [64 x i64]
%3 = icmp eq i64 %0, 0
br i1 %3, label %28, label %4
4: ; preds = %1
%5 = bitcast [64 x i64]* %2 to i8*
br label %9
6: ; preds = %9
%7 = getelementptr inbounds [64 x i64], [64 x i64]* %2, i64 0, i64 0
%8 = call i32 @binary_search_unsigend_long(i64* %7, i64 %0, i32 64)
br label %28
9: ; preds = %9, %4
%10 = phi i64 [ 0, %4 ], [ %23, %9 ]
%11 = or i64 %10, 1
%12 = trunc i64 %10 to i32
%13 = tail call i64 @pow(i32 2, i32 %12)
%14 = getelementptr inbounds [64 x i64], [64 x i64]* %2, i64 0, i64 %10
store i64 %13, i64* %14
%15 = or i64 %10, 2
%16 = trunc i64 %11 to i32
%17 = tail call i64 @pow(i32 2, i32 %16)
%18 = getelementptr inbounds [64 x i64], [64 x i64]* %2, i64 0, i64 %11
store i64 %17, i64* %18
%19 = or i64 %10, 3
%20 = trunc i64 %15 to i32
%21 = tail call i64 @pow(i32 2, i32 %20)
%22 = getelementptr inbounds [64 x i64], [64 x i64]* %2, i64 0, i64 %15
store i64 %21, i64* %22
%23 = add nuw nsw i64 %10, 4
%24 = trunc i64 %19 to i32
%25 = tail call i64 @pow(i32 2, i32 %24)
%26 = getelementptr inbounds [64 x i64], [64 x i64]* %2, i64 0, i64 %19
store i64 %25, i64* %26
%27 = icmp eq i64 %23, 64
br i1 %27, label %6, label %9
28: ; preds = %1, %6
%29 = phi i32 [ %8, %6 ], [ -1, %1 ]
ret i32 %29
}