#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 scalar_t__ uint64_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ __BYTE_ORDER;
scalar_t__ __LITTLE_ENDIAN;
unsigned int log2(uint64_t val) {
  union {
    uint32_t u[2];
    uint64_t v;
  } t;
  t.v = val;
  return t.u[__BYTE_ORDER == __LITTLE_ENDIAN]
             ? log2(t.u[__BYTE_ORDER == __LITTLE_ENDIAN]) + 32
             : log2(t.u[__BYTE_ORDER != __LITTLE_ENDIAN]);
}


x86 assembly (clang, -O0):
<log2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%rax
mov    0x2ec3(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
cmpq   $0x0,-0x18(%rbp,%rax,8)
je     1181 <log2+0x71>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    0x2e99(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x18(%rbp,%rax,8),%rdi
call   1030 <log2@plt>
add    $0x20,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <log2+0x9c>
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x18(%rbp,%rax,8),%rdi
call   1030 <log2@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log2>:
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    0x2eb8(%rip),%rax
mov    (%rax),%rax
mov    0x2ece(%rip),%rcx
mov    (%rcx),%rcx
xor    %edx,%edx
cmp    %rcx,%rax
sete   %dl
mov    0x8(%rsp,%rdx,8),%rdi
test   %rdi,%rdi
je     114c <log2+0x3c>
call   1030 <log2@plt>
add    $0x20,%eax
add    $0x18,%rsp
ret
xor    %edx,%edx
cmp    %rcx,%rax
setne  %dl
mov    0x8(%rsp,%rdx,8),%rdi
add    $0x18,%rsp
jmp    1030 <log2@plt>

LLVM IR (-O0):
%union.anon = type { [2 x i64] }
@__BYTE_ORDER = global i64 0
@__LITTLE_ENDIAN = global i64 0
define i32 @log2(i64 %0) {
%2 = alloca i64
%3 = alloca %union.anon
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = bitcast %union.anon* %3 to i64*
store i64 %4, i64* %5
%6 = bitcast %union.anon* %3 to [2 x i64]*
%7 = load i64, i64* @__BYTE_ORDER
%8 = load i64, i64* @__LITTLE_ENDIAN
%9 = icmp eq i64 %7, %8
%10 = zext i1 %9 to i32
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 %11
%13 = load i64, i64* %12
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %1
%16 = bitcast %union.anon* %3 to [2 x i64]*
%17 = load i64, i64* @__BYTE_ORDER
%18 = load i64, i64* @__LITTLE_ENDIAN
%19 = icmp eq i64 %17, %18
%20 = zext i1 %19 to i32
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2 x i64], [2 x i64]* %16, i64 0, i64 %21
%23 = load i64, i64* %22
%24 = call i32 @log2(i64 %23)
%25 = add i32 %24, 32
br label %36
26: ; preds = %1
%27 = bitcast %union.anon* %3 to [2 x i64]*
%28 = load i64, i64* @__BYTE_ORDER
%29 = load i64, i64* @__LITTLE_ENDIAN
%30 = icmp ne i64 %28, %29
%31 = zext i1 %30 to i32
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2 x i64], [2 x i64]* %27, i64 0, i64 %32
%34 = load i64, i64* %33
%35 = call i32 @log2(i64 %34)
br label %36
36: ; preds = %26, %15
%37 = phi i32 [ %25, %15 ], [ %35, %26 ]
ret i32 %37
}

LLVM IR (-O2):
%union.anon = type { [2 x i64] }
@__BYTE_ORDER = global i64 0
@__LITTLE_ENDIAN = global i64 0
define i32 @log2(i64 %0) {
%2 = alloca %union.anon
%3 = bitcast %union.anon* %2 to i8*
%4 = getelementptr inbounds %union.anon, %union.anon* %2, i64 0, i32 0, i64 0
store i64 %0, i64* %4
%5 = load i64, i64* @__BYTE_ORDER
%6 = load i64, i64* @__LITTLE_ENDIAN
%7 = icmp eq i64 %5, %6
%8 = zext i1 %7 to i64
%9 = getelementptr inbounds %union.anon, %union.anon* %2, i64 0, i32 0, i64 %8
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = tail call i32 @log2(i64 %10)
%14 = add i32 %13, 32
br label %21
15: ; preds = %1
%16 = icmp ne i64 %5, %6
%17 = zext i1 %16 to i64
%18 = getelementptr inbounds %union.anon, %union.anon* %2, i64 0, i32 0, i64 %17
%19 = load i64, i64* %18
%20 = tail call i32 @log2(i64 %19)
br label %21
21: ; preds = %15, %12
%22 = phi i32 [ %14, %12 ], [ %20, %15 ]
ret i32 %22
}