#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 */
scalar_t__ readBits(int);
int codeToLength(int code) {
  if (code == 285) {
    return 258;
  }
  if (code < 265) {
    return code - 254;
  }
  int bits = (code - 261) >> 2;
  code -= 261 + (bits * 4);
  code <<= bits;
  code += (1 << (bits + 2)) + 3;
  code += readBits(bits);
  return code;
}


x86 assembly (clang, -O0):
<codeToLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x11d,-0x8(%rbp)
jne    1134 <codeToLength+0x24>
movl   $0x102,-0x4(%rbp)
jmp    11af <codeToLength+0x9f>
cmpl   $0x109,-0x8(%rbp)
jge    1151 <codeToLength+0x41>
mov    -0x8(%rbp),%eax
sub    $0xfe,%eax
mov    %eax,-0x4(%rbp)
jmp    11af <codeToLength+0x9f>
mov    -0x8(%rbp),%eax
sub    $0x105,%eax
sar    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
add    $0x105,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
mov    $0x1,%eax
shl    %cl,%eax
add    $0x3,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <readBits@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<codeToLength>:
mov    $0x102,%eax
cmp    $0x11d,%edi
je     1155 <codeToLength+0x45>
cmp    $0x108,%edi
jg     112e <codeToLength+0x1e>
add    $0xffffff02,%edi
mov    %edi,%eax
ret
push   %rbx
add    $0xfffffefb,%edi
mov    %edi,%ecx
shr    $0x2,%ecx
and    $0x3,%edi
shl    %cl,%edi
mov    $0x4,%ebx
shl    %cl,%ebx
add    %edi,%ebx
mov    %ecx,%edi
call   1030 <readBits@plt>
add    %ebx,%eax
add    $0x3,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @codeToLength(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 285
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 258, i32* %2
br label %39
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 265
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 254
store i32 %13, i32* %2
br label %39
14: ; preds = %8
%15 = load i32, i32* %3
%16 = sub nsw i32 %15, 261
%17 = ashr i32 %16, 2
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 4
%20 = add nsw i32 261, %19
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, %20
store i32 %22, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = shl i32 %24, %23
store i32 %25, i32* %3
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 2
%28 = shl i32 1, %27
%29 = add nsw i32 %28, 3
%30 = load i32, i32* %3
%31 = add nsw i32 %30, %29
store i32 %31, i32* %3
%32 = load i32, i32* %4
%33 = call i64 @readBits(i32 %32)
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %3
%38 = load i32, i32* %3
store i32 %38, i32* %2
br label %39
39: ; preds = %14, %11, %7
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
define i32 @codeToLength(i32 %0) {
%2 = icmp eq i32 %0, 285
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = icmp slt i32 %0, 265
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = add nsw i32 %0, -254
br label %18
7: ; preds = %3
%8 = add nsw i32 %0, -261
%9 = lshr i32 %8, 2
%10 = and i32 %8, 3
%11 = shl i32 %10, %9
%12 = shl i32 4, %9
%13 = or i32 %12, 3
%14 = add nsw i32 %13, %11
%15 = tail call i64 @readBits(i32 %9)
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
br label %18
18: ; preds = %1, %7, %5
%19 = phi i32 [ %6, %5 ], [ %17, %7 ], [ 258, %1 ]
ret i32 %19
}