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

/* Variables and functions */
int nlz32(scalar_t__ const);
int bitLength(const uint32_t v[], int sz_in_32bit_words) {
  int x = sz_in_32bit_words - 1;
  while ((v[x] == 0) && (x > 0))
    x = x - 1;
  return (x * 32) + (32 - nlz32(v[x]));
}


x86 assembly (clang, -O0):
<bitLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
xor    %eax,%eax
cmpq   $0x0,(%rcx,%rdx,8)
mov    %al,-0x11(%rbp)
jne    114a <bitLength+0x3a>
cmpl   $0x0,-0x10(%rbp)
setg   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    115a <bitLength+0x4a>
jmp    1168 <bitLength+0x58>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1128 <bitLength+0x18>
mov    -0x10(%rbp),%eax
shl    $0x5,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <nlz32@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%eax
mov    $0x20,%ecx
sub    %edx,%ecx
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitLength>:
push   %rbx
movslq %esi,%rcx
mov    %ecx,%ebx
shl    $0x5,%ebx
add    $0x20,%ebx
nopl   0x0(%rax)
mov    -0x8(%rdi,%rcx,8),%rax
add    $0xffffffe0,%ebx
test   %rax,%rax
jne    113a <bitLength+0x2a>
lea    -0x1(%rcx),%rdx
cmp    $0x1,%rcx
mov    %rdx,%rcx
jg     1120 <bitLength+0x10>
mov    %rax,%rdi
call   1030 <nlz32@plt>
sub    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @bitLength(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %5
br label %8
8: ; preds = %20, %2
%9 = load i64*, i64** %3
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i64, i64* %9, i64 %11
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br label %18
18: ; preds = %15, %8
%19 = phi i1 [ false, %8 ], [ %17, %15 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %5
br label %8
23: ; preds = %18
%24 = load i32, i32* %5
%25 = mul nsw i32 %24, 32
%26 = load i64*, i64** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %26, i64 %28
%30 = load i64, i64* %29
%31 = call i32 @nlz32(i64 %30)
%32 = sub nsw i32 32, %31
%33 = add nsw i32 %25, %32
ret i32 %33
}

LLVM IR (-O2):
define i32 @bitLength(i64* nocapture %0, i32 %1) {
%3 = sext i32 %1 to i64
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ %6, %4 ], [ %3, %2 ]
%6 = add nsw i64 %5, -1
%7 = getelementptr inbounds i64, i64* %0, i64 %6
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
%10 = icmp sgt i64 %5, 1
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %4, label %12
12: ; preds = %4
%13 = trunc i64 %6 to i32
%14 = shl nsw i32 %13, 5
%15 = tail call i32 @nlz32(i64 %8)
%16 = add i32 %14, 32
%17 = sub i32 %16, %15
ret i32 %17
}