#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 */
struct blockbuilder {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ putbits(struct blockbuilder *, int, int);
void putlitlength(struct blockbuilder *bb, int v) {
  if (v == 0) {
    putbits(bb, 0, 1);
  } else if (v <= 2) {
    putbits(bb, 1, 1);
    putbits(bb, 0, 2);
    putbits(bb, (v - 1) ^ 0, 1);
  } else if (v <= 6) {
    putbits(bb, 1, 1);
    putbits(bb, 1, 2);
    putbits(bb, (v - 3) ^ 0, 2);
  } else if (v <= 22) {
    putbits(bb, 1, 1);
    putbits(bb, 2, 2);
    putbits(bb, (v - 7) ^ 0, 4);
  } else {
    putbits(bb, 1, 1);
    putbits(bb, 3, 2);
    putbits(bb, (v - 23) ^ 0, 6);
  }
}


x86 assembly (clang, -O0):
<putlitlength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    113e <putlitlength+0x2e>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <putbits@plt>
jmp    125c <putlitlength+0x14c>
cmpl   $0x2,-0xc(%rbp)
jg     1184 <putlitlength+0x74>
mov    -0x8(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    $0x0,%esi
mov    $0x1,%edx
call   1030 <putbits@plt>
jmp    1257 <putlitlength+0x147>
cmpl   $0x6,-0xc(%rbp)
jg     11cd <putlitlength+0xbd>
mov    -0x8(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x3,%esi
xor    $0x0,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
jmp    1252 <putlitlength+0x142>
cmpl   $0x16,-0xc(%rbp)
jg     1213 <putlitlength+0x103>
mov    -0x8(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x7,%esi
xor    $0x0,%esi
mov    $0x4,%edx
call   1030 <putbits@plt>
jmp    124d <putlitlength+0x13d>
mov    -0x8(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x17,%esi
xor    $0x0,%esi
mov    $0x6,%edx
call   1030 <putbits@plt>
jmp    1252 <putlitlength+0x142>
jmp    1257 <putlitlength+0x147>
jmp    125c <putlitlength+0x14c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putlitlength>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %esi,%esi
je     114d <putlitlength+0x3d>
mov    %esi,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
cmp    $0x2,%ebx
jg     1163 <putlitlength+0x53>
call   1030 <putbits@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
jmp    1152 <putlitlength+0x42>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putbits@plt>
cmp    $0x6,%ebx
ja     118e <putlitlength+0x7e>
call   1030 <putbits@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
add    $0xfffffffd,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
jmp    1157 <putlitlength+0x47>
call   1030 <putbits@plt>
mov    %r14,%rdi
cmp    $0x16,%ebx
ja     11b9 <putlitlength+0xa9>
mov    $0x2,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
add    $0xfffffff9,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x4,%edx
jmp    1157 <putlitlength+0x47>
mov    $0x3,%esi
mov    $0x2,%edx
call   1030 <putbits@plt>
add    $0xffffffe9,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x6,%edx
jmp    1157 <putlitlength+0x47>

LLVM IR (-O0):
%struct.blockbuilder = type { i32 }
define void @putlitlength(%struct.blockbuilder* %0, i32 %1) {
%3 = alloca %struct.blockbuilder*
%4 = alloca i32
store %struct.blockbuilder* %0, %struct.blockbuilder** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%9 = call i32 @putbits(%struct.blockbuilder* %8, i32 0, i32 1)
br label %62
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 2
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%15 = call i32 @putbits(%struct.blockbuilder* %14, i32 1, i32 1)
%16 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%17 = call i32 @putbits(%struct.blockbuilder* %16, i32 0, i32 2)
%18 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = xor i32 %20, 0
%22 = call i32 @putbits(%struct.blockbuilder* %18, i32 %21, i32 1)
br label %61
23: ; preds = %10
%24 = load i32, i32* %4
%25 = icmp sle i32 %24, 6
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%28 = call i32 @putbits(%struct.blockbuilder* %27, i32 1, i32 1)
%29 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%30 = call i32 @putbits(%struct.blockbuilder* %29, i32 1, i32 2)
%31 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 3
%34 = xor i32 %33, 0
%35 = call i32 @putbits(%struct.blockbuilder* %31, i32 %34, i32 2)
br label %60
36: ; preds = %23
%37 = load i32, i32* %4
%38 = icmp sle i32 %37, 22
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%41 = call i32 @putbits(%struct.blockbuilder* %40, i32 1, i32 1)
%42 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%43 = call i32 @putbits(%struct.blockbuilder* %42, i32 2, i32 2)
%44 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%45 = load i32, i32* %4
%46 = sub nsw i32 %45, 7
%47 = xor i32 %46, 0
%48 = call i32 @putbits(%struct.blockbuilder* %44, i32 %47, i32 4)
br label %59
49: ; preds = %36
%50 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%51 = call i32 @putbits(%struct.blockbuilder* %50, i32 1, i32 1)
%52 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%53 = call i32 @putbits(%struct.blockbuilder* %52, i32 3, i32 2)
%54 = load %struct.blockbuilder*, %struct.blockbuilder** %3
%55 = load i32, i32* %4
%56 = sub nsw i32 %55, 23
%57 = xor i32 %56, 0
%58 = call i32 @putbits(%struct.blockbuilder* %54, i32 %57, i32 6)
br label %59
59: ; preds = %49, %39
br label %60
60: ; preds = %59, %26
br label %61
61: ; preds = %60, %13
br label %62
62: ; preds = %61, %7
ret void
}

LLVM IR (-O2):
%struct.blockbuilder = type { i32 }
define void @putlitlength(%struct.blockbuilder* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 0, i32 1)
br label %31
6: ; preds = %2
%7 = icmp slt i32 %1, 3
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 1, i32 1)
%10 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 0, i32 2)
%11 = add nsw i32 %1, -1
%12 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 %11, i32 1)
br label %31
13: ; preds = %6
%14 = icmp ult i32 %1, 7
br i1 %14, label %15, label %20
15: ; preds = %13
%16 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 1, i32 1)
%17 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 1, i32 2)
%18 = add nsw i32 %1, -3
%19 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 %18, i32 2)
br label %31
20: ; preds = %13
%21 = icmp ult i32 %1, 23
%22 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 1, i32 1)
br i1 %21, label %23, label %27
23: ; preds = %20
%24 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 2, i32 2)
%25 = add nsw i32 %1, -7
%26 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 %25, i32 4)
br label %31
27: ; preds = %20
%28 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 3, i32 2)
%29 = add nsw i32 %1, -23
%30 = tail call i32 @putbits(%struct.blockbuilder* %0, i32 %29, i32 6)
br label %31
31: ; preds = %8, %23, %27, %15, %4
ret void
}