#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_radix(long rad) {
  long cumulative = 1;
  long out;
  for (out = 0; out < 20; out++) {
    if (cumulative == rad) {
      return (out);
    } else {
      cumulative = cumulative * 2;
    }
  }
  fprintf(stderr, "ERROR: Radix %ld not a power of 2\n", rad);
  exit(-1);
}


x86 assembly (clang, -O0):
<get_log2_radix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x14,-0x18(%rbp)
jge    1181 <get_log2_radix+0x61>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    115f <get_log2_radix+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_radix+0x50>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <get_log2_radix+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_radix>:
push   %rax
mov    %rdi,%rdx
cmp    $0x3ff,%rdi
jg     115e <get_log2_radix+0x3e>
cmp    $0x7f,%rdx
jg     11d9 <get_log2_radix+0xb9>
lea    -0x1(%rdx),%rcx
cmp    $0x3f,%rcx
ja     1294 <get_log2_radix+0x174>
xor    %eax,%eax
lea    0xeb2(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
mov    $0x1,%eax
pop    %rcx
ret
cmp    $0x7fff,%rdx
jg     11a2 <get_log2_radix+0x82>
cmp    $0xfff,%rdx
jle    1207 <get_log2_radix+0xe7>
cmp    $0x1000,%rdx
je     125c <get_log2_radix+0x13c>
cmp    $0x2000,%rdx
je     1263 <get_log2_radix+0x143>
cmp    $0x4000,%rdx
jne    1294 <get_log2_radix+0x174>
mov    $0xe,%eax
pop    %rcx
ret
cmp    $0x1ffff,%rdx
jle    1220 <get_log2_radix+0x100>
cmp    $0x20000,%rdx
je     126a <get_log2_radix+0x14a>
cmp    $0x40000,%rdx
je     1271 <get_log2_radix+0x151>
cmp    $0x80000,%rdx
jne    1294 <get_log2_radix+0x174>
mov    $0x13,%eax
pop    %rcx
ret
cmp    $0x80,%rdx
je     1278 <get_log2_radix+0x158>
cmp    $0x100,%rdx
je     127f <get_log2_radix+0x15f>
cmp    $0x200,%rdx
jne    1294 <get_log2_radix+0x174>
mov    $0x9,%eax
pop    %rcx
ret
cmp    $0x400,%rdx
je     1286 <get_log2_radix+0x166>
cmp    $0x800,%rdx
jne    1294 <get_log2_radix+0x174>
mov    $0xb,%eax
pop    %rcx
ret
cmp    $0x8000,%rdx
je     128d <get_log2_radix+0x16d>
cmp    $0x10000,%rdx
jne    1294 <get_log2_radix+0x174>
mov    $0x10,%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    $0xc,%eax
pop    %rcx
ret
mov    $0xd,%eax
pop    %rcx
ret
mov    $0x11,%eax
pop    %rcx
ret
mov    $0x12,%eax
pop    %rcx
ret
mov    $0x7,%eax
pop    %rcx
ret
mov    $0x8,%eax
pop    %rcx
ret
mov    $0xa,%eax
pop    %rcx
ret
mov    $0xf,%eax
pop    %rcx
ret
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: Radix %ld not a power of 2\0A\00"
define i64 @get_log2_radix(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, 20
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 ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: Radix %ld not a power of 2\0A\00"
define i64 @get_log2_radix(i64 %0) {
switch i64 %0, label %23 [
i64 1, label %21
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
]
2: ; preds = %1
br label %21
3: ; preds = %1
br label %21
4: ; preds = %1
br label %21
5: ; preds = %1
br label %21
6: ; preds = %1
br label %21
7: ; preds = %1
br label %21
8: ; preds = %1
br label %21
9: ; preds = %1
br label %21
10: ; preds = %1
br label %21
11: ; preds = %1
br label %21
12: ; preds = %1
br label %21
13: ; preds = %1
br label %21
14: ; preds = %1
br label %21
15: ; preds = %1
br label %21
16: ; preds = %1
br label %21
17: ; preds = %1
br label %21
18: ; preds = %1
br label %21
19: ; preds = %1
br label %21
20: ; preds = %1
br label %21
21: ; preds = %1, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3, %2
%22 = 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 ]
ret i64 %22
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 %0)
%26 = tail call i32 @exit(i32 -1)
unreachable
}