#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 read_bits(unsigned char *, int, int *);
signed int se_v(unsigned char bytes[], int *bit_offset) {
  signed int b;
  int leadingZeroBits = -1;
  signed int codeNum;
  for (b = 0; !b; leadingZeroBits++) {
    b = read_bits(bytes, 1, bit_offset);
  }
  codeNum = (1 << leadingZeroBits) - 1 +
            read_bits(bytes, leadingZeroBits, bit_offset);
  return codeNum;
}


x86 assembly (clang, -O0):
<se_v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1144 <se_v+0x34>
jmp    1167 <se_v+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1,%esi
call   1030 <read_bits@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112e <se_v+0x1e>
mov    -0x18(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <read_bits@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<se_v>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1030 <read_bits@plt>
add    $0x1,%ebp
test   %eax,%eax
je     1130 <se_v+0x20>
mov    $0xffffffff,%r15d
mov    %ebp,%ecx
shl    %cl,%r15d
not    %r15d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <read_bits@plt>
add    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @se_v(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 -1, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %16, %2
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i32*, i32** %4
%15 = call i32 @read_bits(i8* %13, i32 1, i32* %14)
store i32 %15, i32* %5
br label %16
16: ; preds = %12
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %8
19: ; preds = %8
%20 = load i32, i32* %6
%21 = shl i32 1, %20
%22 = sub nsw i32 %21, 1
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = load i32*, i32** %4
%26 = call i32 @read_bits(i8* %23, i32 %24, i32* %25)
%27 = add nsw i32 %22, %26
store i32 %27, i32* %7
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
define i32 @se_v(i8* %0, i32* %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ -1, %2 ], [ %6, %3 ]
%5 = tail call i32 @read_bits(i8* %0, i32 1, i32* %1)
%6 = add nsw i32 %4, 1
%7 = icmp eq i32 %5, 0
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = shl nsw i32 -1, %6
%10 = xor i32 %9, -1
%11 = tail call i32 @read_bits(i8* %0, i32 %6, i32* %1)
%12 = add nsw i32 %11, %10
ret i32 %12
}