#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 */
typedef int /*<<< orphan*/ huffman;

/* Variables and functions */
int extract_bits_little(unsigned char const **, int *, int *, int);
int zlib_extract_huffman_code(const unsigned char **data, int *bit, int *size,
                              int *huffman, int *code) {
  int i, b, c;
  for (c = 0, i = 0;;) {
    b = extract_bits_little(data, bit, size, 1);
    c = (c << 1) | b;
    if (++i > 15)
      return 0;
    if (((huffman[c]) != -1) && ((unsigned int)(huffman[c]) >> 16) == i) {
      *code = ((unsigned int)(huffman[c]) & 0xFFFF);
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<zlib_extract_huffman_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x1,%ecx
call   1030 <extract_bits_little@plt>
mov    %eax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmp    $0xf,%eax
jle    117d <zlib_extract_huffman_code+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11ce <zlib_extract_huffman_code+0xbe>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     11c9 <zlib_extract_huffman_code+0xb9>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shr    $0x10,%eax
cmp    -0x34(%rbp),%eax
jne    11c9 <zlib_extract_huffman_code+0xb9>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
and    $0xffff,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11ce <zlib_extract_huffman_code+0xbe>
jmp    113a <zlib_extract_huffman_code+0x2a>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlib_extract_huffman_code>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0x1,%eax
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%r15d
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    $0x1,%ecx
call   1030 <extract_bits_little@plt>
cmp    $0x10,%r15d
je     118c <zlib_extract_huffman_code+0x7c>
add    %r14d,%r14d
or     %eax,%r14d
movslq %r14d,%rax
mov    (%r12,%rax,4),%ecx
lea    0x1(%r15),%eax
cmp    $0xffffffff,%ecx
je     1140 <zlib_extract_huffman_code+0x30>
mov    %ecx,%edx
shr    $0x10,%edx
cmp    %edx,%r15d
jne    1140 <zlib_extract_huffman_code+0x30>
movzwl %cx,%eax
mov    (%rsp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
jmp    118e <zlib_extract_huffman_code+0x7e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @zlib_extract_huffman_code(i8** %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8** %0, i8*** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 0, i32* %14
store i32 0, i32* %12
br label %15
15: ; preds = %52, %5
%16 = load i8**, i8*** %7
%17 = load i32*, i32** %8
%18 = load i32*, i32** %9
%19 = call i32 @extract_bits_little(i8** %16, i32* %17, i32* %18, i32 1)
store i32 %19, i32* %13
%20 = load i32, i32* %14
%21 = shl i32 %20, 1
%22 = load i32, i32* %13
%23 = or i32 %21, %22
store i32 %23, i32* %14
%24 = load i32, i32* %12
%25 = add nsw i32 %24, 1
store i32 %25, i32* %12
%26 = icmp sgt i32 %25, 15
br i1 %26, label %27, label %28
27: ; preds = %15
store i32 0, i32* %6
br label %53
28: ; preds = %15
%29 = load i32*, i32** %10
%30 = load i32, i32* %14
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %52
35: ; preds = %28
%36 = load i32*, i32** %10
%37 = load i32, i32* %14
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = lshr i32 %40, 16
%42 = load i32, i32* %12
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %52
44: ; preds = %35
%45 = load i32*, i32** %10
%46 = load i32, i32* %14
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = and i32 %49, 65535
%51 = load i32*, i32** %11
store i32 %50, i32* %51
store i32 1, i32* %6
br label %53
52: ; preds = %35, %28
br label %15
53: ; preds = %44, %27
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
define i32 @zlib_extract_huffman_code(i8** %0, i32* %1, i32* %2, i32* nocapture %3, i32* nocapture writeonly %4) {
br label %6
6: ; preds = %14, %5
%7 = phi i32 [ 0, %5 ], [ %12, %14 ]
%8 = phi i32 [ 0, %5 ], [ %11, %14 ]
%9 = tail call i32 @extract_bits_little(i8** %0, i32* %1, i32* %2, i32 1)
%10 = shl i32 %8, 1
%11 = or i32 %10, %9
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %7, 15
br i1 %13, label %24, label %14
14: ; preds = %6
%15 = sext i32 %11 to i64
%16 = getelementptr inbounds i32, i32* %3, i64 %15
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, -1
%19 = lshr i32 %17, 16
%20 = icmp eq i32 %19, %12
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %22, label %6
22: ; preds = %14
%23 = and i32 %17, 65535
store i32 %23, i32* %4
br label %24
24: ; preds = %6, %22
%25 = phi i32 [ 1, %22 ], [ 0, %6 ]
ret i32 %25
}