int decode_number(unsigned char **data, unsigned short *len,
                  unsigned char *bitpos) {
  int num_bits;
  printf("decode_number ");
  num_bits = count_ones(6, data, len, bitpos) + 1;
  if (num_bits == 7)
    return 0;
  if (num_bits == 1) {
    if (get_bits(data, len, bitpos, 1))
      num_bits = 1;
    else
      return 1;
  }
  return (1 << num_bits) +
         (~get_bits(data, len, bitpos, num_bits) & ((1 << num_bits) - 1));
}


x86 assembly (clang, -O0):
<decode_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x6,%edi
mov    $0x0,%al
call   1030 <count_ones@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jne    1186 <decode_number+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1213 <decode_number+0xe3>
cmpl   $0x1,-0x24(%rbp)
jne    11ce <decode_number+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x1,%ecx
mov    $0x0,%al
call   1050 <get_bits@plt>
cmp    $0x0,%eax
je     11bd <decode_number+0x8d>
movl   $0x1,-0x24(%rbp)
jmp    11c9 <decode_number+0x99>
movl   $0x1,-0x4(%rbp)
jmp    1213 <decode_number+0xe3>
jmp    11ce <decode_number+0x9e>
mov    -0x24(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x0,%al
call   1050 <get_bits@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
xor    $0xffffffff,%ecx
mov    %ecx,-0x28(%rbp)
mov    -0x24(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x28(%rbp),%ecx
sub    $0x1,%edx
and    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xeb5(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x6,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <count_ones@plt>
lea    0x1(%rax),%ebx
cmp    $0x7,%ebx
je     11bb <decode_number+0x8b>
test   %eax,%eax
jne    1193 <decode_number+0x63>
mov    $0x1,%ebp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
xor    %eax,%eax
call   1050 <get_bits@plt>
test   %eax,%eax
je     11bb <decode_number+0x8b>
mov    $0x1,%r13d
mov    %ebx,%ecx
shl    %cl,%r13d
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <get_bits@plt>
not    %eax
lea    -0x1(%r13),%ebp
and    %eax,%ebp
add    %r13d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"decode_number \00"
define i32 @decode_number(i8** %0, i16* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16*
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %5
store i16* %1, i16** %6
store i8* %2, i8** %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = load i8**, i8*** %5
%11 = load i16*, i16** %6
%12 = load i8*, i8** %7
%13 = call i32 (i32, i8**, i16*, i8*, ...) bitcast (i32 (...)* @count_ones to i32 (i32, i8**, i16*, i8*, ...)*)(i32 6, i8** %10, i16* %11, i8* %12)
%14 = add nsw i32 %13, 1
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 7
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %44
18: ; preds = %3
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = load i16*, i16** %6
%24 = load i8*, i8** %7
%25 = call i32 (i8**, i16*, i8*, i32, ...) bitcast (i32 (...)* @get_bits to i32 (i8**, i16*, i8*, i32, ...)*)(i8** %22, i16* %23, i8* %24, i32 1)
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 1, i32* %8
br label %29
28: ; preds = %21
store i32 1, i32* %4
br label %44
29: ; preds = %27
br label %30
30: ; preds = %29, %18
%31 = load i32, i32* %8
%32 = shl i32 1, %31
%33 = load i8**, i8*** %5
%34 = load i16*, i16** %6
%35 = load i8*, i8** %7
%36 = load i32, i32* %8
%37 = call i32 (i8**, i16*, i8*, i32, ...) bitcast (i32 (...)* @get_bits to i32 (i8**, i16*, i8*, i32, ...)*)(i8** %33, i16* %34, i8* %35, i32 %36)
%38 = xor i32 %37, -1
%39 = load i32, i32* %8
%40 = shl i32 1, %39
%41 = sub nsw i32 %40, 1
%42 = and i32 %38, %41
%43 = add nsw i32 %32, %42
store i32 %43, i32* %4
br label %44
44: ; preds = %30, %28, %17
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [15 x i8] c"decode_number \00"
define i32 @decode_number(i8** %0, i16* %1, i8* %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (i32, i8**, i16*, i8*, ...) bitcast (i32 (...)* @count_ones to i32 (i32, i8**, i16*, i8*, ...)*)(i32 6, i8** %0, i16* %1, i8* %2)
%6 = add nsw i32 %5, 1
%7 = icmp eq i32 %6, 7
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = icmp eq i32 %5, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 (i8**, i16*, i8*, i32, ...) bitcast (i32 (...)* @get_bits to i32 (i8**, i16*, i8*, i32, ...)*)(i8** %0, i16* %1, i8* %2, i32 1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %10, %8
%14 = shl nuw i32 1, %6
%15 = tail call i32 (i8**, i16*, i8*, i32, ...) bitcast (i32 (...)* @get_bits to i32 (i8**, i16*, i8*, i32, ...)*)(i8** %0, i16* %1, i8* %2, i32 %6)
%16 = xor i32 %15, -1
%17 = add nsw i32 %14, -1
%18 = and i32 %17, %16
%19 = add nsw i32 %18, %14
br label %20
20: ; preds = %10, %3, %13
%21 = phi i32 [ %19, %13 ], [ 0, %3 ], [ 1, %10 ]
ret i32 %21
}