#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 huff_symbol {
  int dummy;
};
struct bit_stream {
  int dummy;
};

/* Variables and functions */
int bit_stream_get(struct bit_stream *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
struct huff_symbol *huff_tbl_search(struct huff_symbol const *, unsigned int,
                                    int, unsigned int);
int /*<<< orphan*/ stderr;
struct huff_symbol const *
bit_stream_read_huff(struct bit_stream *bits,
                     struct huff_symbol const *huff_tbl, unsigned tbl_len) {
  int key = 0;
  unsigned key_len = 0;
  struct huff_symbol const *ret;
  int tmp;
  do {
    if (key >= (1 << 20)) {
      fprintf(stderr,
              "CRITICAL: unlimited loop at line "
              "%d of %s\n",
              325,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/jayelliott/simple_fps/refs/heads/"
              "master/common/deflate.c");
      return NULL;
    }
    if ((tmp = bit_stream_get(bits)) < 0)
      return NULL;
    key = (key << 1) | tmp;
    ret = huff_tbl_search(huff_tbl, tbl_len, key, ++key_len);
  } while (!ret);
  return ret;
}


x86 assembly (clang, -O0):
<bit_stream_read_huff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100000,-0x20(%rbp)
jl     118c <bit_stream_read_huff+0x5c>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    $0x145,%edx
lea    0xeb1(%rip),%rcx
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f0 <bit_stream_read_huff+0xc0>
mov    -0x10(%rbp),%rdi
call   1050 <bit_stream_get@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11ae <bit_stream_read_huff+0x7e>
movq   $0x0,-0x8(%rbp)
jmp    11f0 <bit_stream_read_huff+0xc0>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
or     -0x34(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
call   1030 <huff_tbl_search@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1151 <bit_stream_read_huff+0x21>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_stream_read_huff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
xor    %r14d,%r14d
mov    $0x1,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
cmp    $0x100000,%ebp
jge    1184 <bit_stream_read_huff+0x54>
mov    %r13,%rdi
call   1050 <bit_stream_get@plt>
test   %eax,%eax
js     11a8 <bit_stream_read_huff+0x78>
add    %ebp,%ebp
or     %eax,%ebp
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <huff_tbl_search@plt>
add    $0x1,%ebx
test   %rax,%rax
je     1150 <bit_stream_read_huff+0x20>
mov    %rax,%r14
jmp    11a8 <bit_stream_read_huff+0x78>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
lea    0xe90(%rip),%rcx
mov    $0x145,%edx
call   1040 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bit_stream = type { i32 }
%struct.huff_symbol = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"CRITICAL: unlimited loop at line %d of %s\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jayelliott/simple_fps/refs/heads/master/common/deflate.c\00"
define %struct.huff_symbol* @bit_stream_read_huff(%struct.bit_stream* %0, %struct.huff_symbol* %1, i32 %2) {
%4 = alloca %struct.huff_symbol*
%5 = alloca %struct.bit_stream*
%6 = alloca %struct.huff_symbol*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.huff_symbol*
%11 = alloca i32
store %struct.bit_stream* %0, %struct.bit_stream** %5
store %struct.huff_symbol* %1, %struct.huff_symbol** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %12
12: ; preds = %34, %3
%13 = load i32, i32* %8
%14 = icmp sge i32 %13, 1048576
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 325, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0))
store %struct.huff_symbol* null, %struct.huff_symbol** %4
br label %40
18: ; preds = %12
%19 = load %struct.bit_stream*, %struct.bit_stream** %5
%20 = call i32 @bit_stream_get(%struct.bit_stream* %19)
store i32 %20, i32* %11
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store %struct.huff_symbol* null, %struct.huff_symbol** %4
br label %40
23: ; preds = %18
%24 = load i32, i32* %8
%25 = shl i32 %24, 1
%26 = load i32, i32* %11
%27 = or i32 %25, %26
store i32 %27, i32* %8
%28 = load %struct.huff_symbol*, %struct.huff_symbol** %6
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = add i32 %31, 1
store i32 %32, i32* %9
%33 = call %struct.huff_symbol* @huff_tbl_search(%struct.huff_symbol* %28, i32 %29, i32 %30, i32 %32)
store %struct.huff_symbol* %33, %struct.huff_symbol** %10
br label %34
34: ; preds = %23
%35 = load %struct.huff_symbol*, %struct.huff_symbol** %10
%36 = icmp ne %struct.huff_symbol* %35, null
%37 = xor i1 %36, true
br i1 %37, label %12, label %38
38: ; preds = %34
%39 = load %struct.huff_symbol*, %struct.huff_symbol** %10
store %struct.huff_symbol* %39, %struct.huff_symbol** %4
br label %40
40: ; preds = %38, %22, %15
%41 = load %struct.huff_symbol*, %struct.huff_symbol** %4
ret %struct.huff_symbol* %41
}

LLVM IR (-O2):
%struct.bit_stream = type { i32 }
%struct.huff_symbol = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"CRITICAL: unlimited loop at line %d of %s\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jayelliott/simple_fps/refs/heads/master/common/deflate.c\00"
define %struct.huff_symbol* @bit_stream_read_huff(%struct.bit_stream* %0, %struct.huff_symbol* %1, i32 %2) {
br label %4
4: ; preds = %14, %3
%5 = phi i32 [ 0, %3 ], [ %17, %14 ]
%6 = phi i32 [ 0, %3 ], [ %16, %14 ]
%7 = icmp sgt i32 %6, 1048575
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 325, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0))
br label %20
11: ; preds = %4
%12 = tail call i32 @bit_stream_get(%struct.bit_stream* %0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = shl i32 %6, 1
%16 = or i32 %12, %15
%17 = add i32 %5, 1
%18 = tail call %struct.huff_symbol* @huff_tbl_search(%struct.huff_symbol* %1, i32 %2, i32 %16, i32 %17)
%19 = icmp eq %struct.huff_symbol* %18, null
br i1 %19, label %4, label %20
20: ; preds = %14, %11, %8
%21 = phi %struct.huff_symbol* [ null, %8 ], [ %18, %14 ], [ null, %11 ]
ret %struct.huff_symbol* %21
}