#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 ParseGolombCode(unsigned char const *, int, int *, int);
unsigned long ue(const unsigned char *code, int bits_offset, int total_bits,
                 int *code_bits) {
  int len, info;
  *code_bits = 0;
  len = ParseGolombCode(code, bits_offset, &info,
                        (total_bits >> 3) + ((total_bits & 0x7) ? 1 : 0));
  if (len == -1)
    return 0;
  *code_bits = len;
  return (1 << (len >> 1)) + info - 1;
}


x86 assembly (clang, -O0):
<ue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%ecx
sar    $0x3,%ecx
mov    -0x18(%rbp),%r8d
and    $0x7,%r8d
xor    %eax,%eax
mov    $0x1,%edx
cmp    $0x0,%r8d
cmovne %edx,%eax
add    %eax,%ecx
lea    -0x28(%rbp),%rdx
call   1030 <ParseGolombCode@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1178 <ue+0x68>
movq   $0x0,-0x8(%rbp)
jmp    119a <ue+0x8a>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%ecx
sar    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
add    -0x28(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ue>:
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
movl   $0x0,(%rcx)
mov    %edx,%ecx
sar    $0x3,%ecx
and    $0x7,%edx
cmp    $0x1,%edx
sbb    $0xffffffff,%ecx
lea    0xc(%rsp),%rdx
call   1030 <ParseGolombCode@plt>
cmp    $0xffffffff,%eax
je     1153 <ue+0x43>
mov    %eax,(%rbx)
shr    %eax
mov    $0xffffffff,%edx
mov    %eax,%ecx
shl    %cl,%edx
not    %edx
add    0xc(%rsp),%edx
movslq %edx,%rax
jmp    1155 <ue+0x45>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @ue(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load i32*, i32** %9
store i32 0, i32* %12
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = ashr i32 %15, 3
%17 = load i32, i32* %8
%18 = and i32 %17, 7
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 1, i32 0
%22 = add nsw i32 %16, %21
%23 = call i32 @ParseGolombCode(i8* %13, i32 %14, i32* %11, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %4
store i64 0, i64* %5
br label %37
27: ; preds = %4
%28 = load i32, i32* %10
%29 = load i32*, i32** %9
store i32 %28, i32* %29
%30 = load i32, i32* %10
%31 = ashr i32 %30, 1
%32 = shl i32 1, %31
%33 = load i32, i32* %11
%34 = add nsw i32 %32, %33
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
store i64 %36, i64* %5
br label %37
37: ; preds = %27, %26
%38 = load i64, i64* %5
ret i64 %38
}

LLVM IR (-O2):
define i64 @ue(i8* %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 0, i32* %3
%7 = ashr i32 %2, 3
%8 = and i32 %2, 7
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
%11 = add nsw i32 %7, %10
%12 = call i32 @ParseGolombCode(i8* %0, i32 %1, i32* %5, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %21, label %14
14: ; preds = %4
store i32 %12, i32* %3
%15 = ashr i32 %12, 1
%16 = load i32, i32* %5
%17 = shl nsw i32 -1, %15
%18 = xor i32 %17, -1
%19 = add i32 %16, %18
%20 = sext i32 %19 to i64
br label %21
21: ; preds = %4, %14
%22 = phi i64 [ %20, %14 ], [ 0, %4 ]
ret i64 %22
}