#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 zpdec {
  int dummy;
};

/* Variables and functions */
int zp_decode(struct zpdec *, unsigned char *);
unsigned int bzz_decode_bin(struct zpdec *zp, unsigned char *ctx, int b) {
  int n = 1;
  int m = 1 << b;
  ctx = ctx - 1;
  while (n < m)
    n = (n << 1) | zp_decode(zp, ctx + n);
  return n - m;
}


x86 assembly (clang, -O0):
<bzz_decode_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    117b <bzz_decode_bin+0x6b>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
call   1030 <zp_decode@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1143 <bzz_decode_bin+0x33>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bzz_decode_bin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ecx
mov    $0x1,%ebp
mov    $0x1,%ebx
shl    %cl,%ebx
cmp    $0x2,%ebx
jl     1156 <bzz_decode_bin+0x46>
mov    %rsi,%r15
mov    %rdi,%r14
add    $0xffffffffffffffff,%r15
mov    $0x1,%ebp
nopl   0x0(%rax)
movslq %ebp,%rsi
add    %ebp,%ebp
add    %r15,%rsi
mov    %r14,%rdi
call   1030 <zp_decode@plt>
or     %eax,%ebp
cmp    %ebx,%ebp
jl     1140 <bzz_decode_bin+0x30>
sub    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.zpdec = type { i32 }
define i32 @bzz_decode_bin(%struct.zpdec* %0, i8* %1, i32 %2) {
%4 = alloca %struct.zpdec*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.zpdec* %0, %struct.zpdec** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 1, i32* %7
%9 = load i32, i32* %6
%10 = shl i32 1, %9
store i32 %10, i32* %8
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8* %12, i8** %5
br label %13
13: ; preds = %17, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32, i32* %7
%19 = shl i32 %18, 1
%20 = load %struct.zpdec*, %struct.zpdec** %4
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @zp_decode(%struct.zpdec* %20, i8* %24)
%26 = or i32 %19, %25
store i32 %26, i32* %7
br label %13
27: ; preds = %13
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = sub nsw i32 %28, %29
ret i32 %30
}

LLVM IR (-O2):
%struct.zpdec = type { i32 }
define i32 @bzz_decode_bin(%struct.zpdec* %0, i8* %1, i32 %2) {
%4 = shl nuw i32 1, %2
%5 = getelementptr inbounds i8, i8* %1, i64 -1
%6 = icmp sgt i32 %4, 1
br i1 %6, label %7, label %15
7: ; preds = %3, %7
%8 = phi i32 [ %13, %7 ], [ 1, %3 ]
%9 = shl i32 %8, 1
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %5, i64 %10
%12 = tail call i32 @zp_decode(%struct.zpdec* %0, i8* %11)
%13 = or i32 %12, %9
%14 = icmp slt i32 %13, %4
br i1 %14, label %7, label %15
15: ; preds = %7, %3
%16 = phi i32 [ 1, %3 ], [ %13, %7 ]
%17 = sub nsw i32 %16, %4
ret i32 %17
}