#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 *, long);
int /*<<< orphan*/ stderr;
long get_log2_keys(long num_keys) {
  long cumulative = 1;
  long out;
  for (out = 0; out < 30; out++) {
    if (cumulative == num_keys) {
      return (out);
    } else {
      cumulative = cumulative * 2;
    }
  }
  fprintf(stderr, "ERROR: Number of keys %ld not a power of 2\n", num_keys);
  exit(-1);
}


x86 assembly (clang, -O0):
<get_log2_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x1e,-0x18(%rbp)
jge    1181 <get_log2_keys+0x61>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    115f <get_log2_keys+0x3f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1170 <get_log2_keys+0x50>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <get_log2_keys+0x1c>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<get_log2_keys>:
push   %rax
mov    %rdi,%rdx
cmp    $0x7fff,%rdi
jg     116e <get_log2_keys+0x4e>
cmp    $0x7f,%rdx
jle    11b2 <get_log2_keys+0x92>
cmp    $0x7ff,%rdx
jg     1214 <get_log2_keys+0xf4>
cmp    $0x1ff,%rdx
jg     129e <get_log2_keys+0x17e>
cmp    $0x80,%rdx
je     133f <get_log2_keys+0x21f>
cmp    $0x100,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x8,%eax
pop    %rcx
ret
cmp    $0x3fffff,%rdx
jle    11d9 <get_log2_keys+0xb9>
cmp    $0x3ffffff,%rdx
jg     1242 <get_log2_keys+0x122>
cmp    $0xffffff,%rdx
jg     12bf <get_log2_keys+0x19f>
cmp    $0x400000,%rdx
je     1346 <get_log2_keys+0x226>
cmp    $0x800000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x17,%eax
pop    %rcx
ret
lea    -0x1(%rdx),%rcx
cmp    $0x3f,%rcx
ja     13b6 <get_log2_keys+0x296>
xor    %eax,%eax
lea    0xe37(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
mov    $0x1,%eax
pop    %rcx
ret
cmp    $0x3ffff,%rdx
jle    1270 <get_log2_keys+0x150>
cmp    $0xfffff,%rdx
jg     12e0 <get_log2_keys+0x1c0>
cmp    $0x40000,%rdx
je     1370 <get_log2_keys+0x250>
cmp    $0x80000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x13,%eax
pop    %rcx
ret
cmp    $0x1fff,%rdx
jg     1301 <get_log2_keys+0x1e1>
cmp    $0x800,%rdx
je     1377 <get_log2_keys+0x257>
cmp    $0x1000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0xc,%eax
pop    %rcx
ret
cmp    $0xfffffff,%rdx
jg     1322 <get_log2_keys+0x202>
cmp    $0x4000000,%rdx
je     137e <get_log2_keys+0x25e>
cmp    $0x8000000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x1b,%eax
pop    %rcx
ret
cmp    $0x8000,%rdx
je     1385 <get_log2_keys+0x265>
cmp    $0x10000,%rdx
je     138c <get_log2_keys+0x26c>
cmp    $0x20000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x11,%eax
pop    %rcx
ret
cmp    $0x200,%rdx
je     1393 <get_log2_keys+0x273>
cmp    $0x400,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0xa,%eax
pop    %rcx
ret
cmp    $0x1000000,%rdx
je     139a <get_log2_keys+0x27a>
cmp    $0x2000000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x19,%eax
pop    %rcx
ret
cmp    $0x100000,%rdx
je     13a1 <get_log2_keys+0x281>
cmp    $0x200000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x15,%eax
pop    %rcx
ret
cmp    $0x2000,%rdx
je     13a8 <get_log2_keys+0x288>
cmp    $0x4000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0xe,%eax
pop    %rcx
ret
cmp    $0x10000000,%rdx
je     13af <get_log2_keys+0x28f>
cmp    $0x20000000,%rdx
jne    13b6 <get_log2_keys+0x296>
mov    $0x1d,%eax
pop    %rcx
ret
mov    $0x7,%eax
pop    %rcx
ret
mov    $0x16,%eax
pop    %rcx
ret
mov    $0x2,%eax
pop    %rcx
ret
mov    $0x3,%eax
pop    %rcx
ret
mov    $0x4,%eax
pop    %rcx
ret
mov    $0x5,%eax
pop    %rcx
ret
mov    $0x6,%eax
pop    %rcx
ret
mov    $0x12,%eax
pop    %rcx
ret
mov    $0xb,%eax
pop    %rcx
ret
mov    $0x1a,%eax
pop    %rcx
ret
mov    $0xf,%eax
pop    %rcx
ret
mov    $0x10,%eax
pop    %rcx
ret
mov    $0x9,%eax
pop    %rcx
ret
mov    $0x18,%eax
pop    %rcx
ret
mov    $0x14,%eax
pop    %rcx
ret
mov    $0xd,%eax
pop    %rcx
ret
mov    $0x1c,%eax
pop    %rcx
ret
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
lea    0xd3a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR: Number of keys %ld not a power of 2\0A\00"
define i64 @get_log2_keys(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 1, i64* %3
store i64 0, i64* %4
br label %5
5: ; preds = %18, %1
%6 = load i64, i64* %4
%7 = icmp slt i64 %6, 30
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i64, i64* %3
%10 = load i64, i64* %2
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i64, i64* %4
ret i64 %13
14: ; preds = %8
%15 = load i64, i64* %3
%16 = mul nsw i64 %15, 2
store i64 %16, i64* %3
br label %17
17: ; preds = %14
br label %18
18: ; preds = %17
%19 = load i64, i64* %4
%20 = add nsw i64 %19, 1
store i64 %20, i64* %4
br label %5
21: ; preds = %5
%22 = load i32, i32* @stderr
%23 = load i64, i64* %2
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR: Number of keys %ld not a power of 2\0A\00"
define i64 @get_log2_keys(i64 %0) {
switch i64 %0, label %33 [
i64 1, label %31
i64 2, label %2
i64 4, label %3
i64 8, label %4
i64 16, label %5
i64 32, label %6
i64 64, label %7
i64 128, label %8
i64 256, label %9
i64 512, label %10
i64 1024, label %11
i64 2048, label %12
i64 4096, label %13
i64 8192, label %14
i64 16384, label %15
i64 32768, label %16
i64 65536, label %17
i64 131072, label %18
i64 262144, label %19
i64 524288, label %20
i64 1048576, label %21
i64 2097152, label %22
i64 4194304, label %23
i64 8388608, label %24
i64 16777216, label %25
i64 33554432, label %26
i64 67108864, label %27
i64 134217728, label %28
i64 268435456, label %29
i64 536870912, label %30
]
2: ; preds = %1
br label %31
3: ; preds = %1
br label %31
4: ; preds = %1
br label %31
5: ; preds = %1
br label %31
6: ; preds = %1
br label %31
7: ; preds = %1
br label %31
8: ; preds = %1
br label %31
9: ; preds = %1
br label %31
10: ; preds = %1
br label %31
11: ; preds = %1
br label %31
12: ; preds = %1
br label %31
13: ; preds = %1
br label %31
14: ; preds = %1
br label %31
15: ; preds = %1
br label %31
16: ; preds = %1
br label %31
17: ; preds = %1
br label %31
18: ; preds = %1
br label %31
19: ; preds = %1
br label %31
20: ; preds = %1
br label %31
21: ; preds = %1
br label %31
22: ; preds = %1
br label %31
23: ; preds = %1
br label %31
24: ; preds = %1
br label %31
25: ; preds = %1
br label %31
26: ; preds = %1
br label %31
27: ; preds = %1
br label %31
28: ; preds = %1
br label %31
29: ; preds = %1
br label %31
30: ; preds = %1
br label %31
31: ; preds = %1, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3, %2
%32 = phi i64 [ 0, %1 ], [ 1, %2 ], [ 2, %3 ], [ 3, %4 ], [ 4, %5 ], [ 5, %6 ], [ 6, %7 ], [ 7, %8 ], [ 8, %9 ], [ 9, %10 ], [ 10, %11 ], [ 11, %12 ], [ 12, %13 ], [ 13, %14 ], [ 14, %15 ], [ 15, %16 ], [ 16, %17 ], [ 17, %18 ], [ 18, %19 ], [ 19, %20 ], [ 20, %21 ], [ 21, %22 ], [ 22, %23 ], [ 23, %24 ], [ 24, %25 ], [ 25, %26 ], [ 26, %27 ], [ 27, %28 ], [ 28, %29 ], [ 29, %30 ]
ret i64 %32
33: ; preds = %1
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %0)
%36 = tail call i32 @exit(i32 -1)
unreachable
}