#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 lzx {
  int dummy;
};
struct huffman_symbols {
  int dummy;
};
struct huffman_alphabet {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ huffman_len(struct huffman_symbols *);
int huffman_raw(struct huffman_symbols *, int);
struct huffman_symbols *huffman_sym(struct huffman_alphabet *, int);
int lzx_accumulate(struct lzx *, int);
int lzx_consume(struct lzx *, int /*<<< orphan*/);
int lzx_decode(struct lzx *lzx, struct huffman_alphabet *alphabet) {
  struct huffman_symbols *sym;
  int huf;
  int rc;
  huf = lzx_accumulate(lzx, 16);
  if (huf < 0)
    return huf;
  sym = huffman_sym(alphabet, huf);
  if ((rc = lzx_consume(lzx, huffman_len(sym))) != 0)
    return rc;
  return huffman_raw(sym, huf);
}


x86 assembly (clang, -O0):
<lzx_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
call   1060 <lzx_accumulate@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1186 <lzx_decode+0x36>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <lzx_decode+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <huffman_sym@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <huffman_len@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1030 <lzx_consume@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     11c9 <lzx_decode+0x79>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <lzx_decode+0x88>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <huffman_raw@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lzx_decode>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x10,%esi
call   1060 <lzx_accumulate@plt>
mov    %eax,%ebx
test   %eax,%eax
js     119d <lzx_decode+0x4d>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <huffman_sym@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <huffman_len@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <lzx_consume@plt>
test   %eax,%eax
jne    119f <lzx_decode+0x4f>
mov    %r15,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <huffman_raw@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lzx = type { i32 }
%struct.huffman_alphabet = type { i32 }
%struct.huffman_symbols = type { i32 }
define i32 @lzx_decode(%struct.lzx* %0, %struct.huffman_alphabet* %1) {
%3 = alloca i32
%4 = alloca %struct.lzx*
%5 = alloca %struct.huffman_alphabet*
%6 = alloca %struct.huffman_symbols*
%7 = alloca i32
%8 = alloca i32
store %struct.lzx* %0, %struct.lzx** %4
store %struct.huffman_alphabet* %1, %struct.huffman_alphabet** %5
%9 = load %struct.lzx*, %struct.lzx** %4
%10 = call i32 @lzx_accumulate(%struct.lzx* %9, i32 16)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %7
store i32 %14, i32* %3
br label %30
15: ; preds = %2
%16 = load %struct.huffman_alphabet*, %struct.huffman_alphabet** %5
%17 = load i32, i32* %7
%18 = call %struct.huffman_symbols* @huffman_sym(%struct.huffman_alphabet* %16, i32 %17)
store %struct.huffman_symbols* %18, %struct.huffman_symbols** %6
%19 = load %struct.lzx*, %struct.lzx** %4
%20 = load %struct.huffman_symbols*, %struct.huffman_symbols** %6
%21 = call i32 @huffman_len(%struct.huffman_symbols* %20)
%22 = call i32 @lzx_consume(%struct.lzx* %19, i32 %21)
store i32 %22, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = load i32, i32* %8
store i32 %25, i32* %3
br label %30
26: ; preds = %15
%27 = load %struct.huffman_symbols*, %struct.huffman_symbols** %6
%28 = load i32, i32* %7
%29 = call i32 @huffman_raw(%struct.huffman_symbols* %27, i32 %28)
store i32 %29, i32* %3
br label %30
30: ; preds = %26, %24, %13
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.lzx = type { i32 }
%struct.huffman_alphabet = type { i32 }
%struct.huffman_symbols = type { i32 }
define i32 @lzx_decode(%struct.lzx* %0, %struct.huffman_alphabet* %1) {
%3 = tail call i32 @lzx_accumulate(%struct.lzx* %0, i32 16)
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call %struct.huffman_symbols* @huffman_sym(%struct.huffman_alphabet* %1, i32 %3)
%7 = tail call i32 @huffman_len(%struct.huffman_symbols* %6)
%8 = tail call i32 @lzx_consume(%struct.lzx* %0, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @huffman_raw(%struct.huffman_symbols* %6, i32 %3)
br label %12
12: ; preds = %5, %2, %10
%13 = phi i32 [ %11, %10 ], [ %3, %2 ], [ %8, %5 ]
ret i32 %13
}