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

/* Variables and functions */
int huffman_alphabet(struct huffman_alphabet *, int *, unsigned int);
int lzx_getbits(struct lzx *, unsigned int);
int lzx_raw_alphabet(struct lzx *lzx, unsigned int count, unsigned int bits,
                     uint8_t *lengths, struct huffman_alphabet *alphabet) {
  unsigned int i;
  int len;
  int rc;
  for (i = 0; i < count; i++) {
    len = lzx_getbits(lzx, bits);
    if (len < 0)
      return len;
    lengths[i] = len;
  }
  if ((rc = huffman_alphabet(alphabet, lengths, count)) != 0)
    return rc;
  return 0;
}


x86 assembly (clang, -O0):
<lzx_raw_alphabet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    118c <lzx_raw_alphabet+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <lzx_getbits@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1171 <lzx_raw_alphabet+0x51>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <lzx_raw_alphabet+0x9a>
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1141 <lzx_raw_alphabet+0x21>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <huffman_alphabet@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     11b3 <lzx_raw_alphabet+0x93>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <lzx_raw_alphabet+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lzx_raw_alphabet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rcx,%r12
mov    %esi,%r15d
test   %esi,%esi
je     116c <lzx_raw_alphabet+0x4c>
mov    %edx,%r13d
mov    %rdi,%rbx
mov    %r15d,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r13d,%esi
call   1030 <lzx_getbits@plt>
test   %eax,%eax
js     1189 <lzx_raw_alphabet+0x69>
mov    %eax,(%r12,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbp
jne    1150 <lzx_raw_alphabet+0x30>
mov    (%rsp),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <huffman_alphabet@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.lzx = type { i32 }
%struct.huffman_alphabet = type { i32 }
define i32 @lzx_raw_alphabet(%struct.lzx* %0, i32 %1, i32 %2, i32* %3, %struct.huffman_alphabet* %4) {
%6 = alloca i32
%7 = alloca %struct.lzx*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.huffman_alphabet*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store %struct.lzx* %0, %struct.lzx** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store %struct.huffman_alphabet* %4, %struct.huffman_alphabet** %11
store i32 0, i32* %12
br label %15
15: ; preds = %33, %5
%16 = load i32, i32* %12
%17 = load i32, i32* %8
%18 = icmp ult i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load %struct.lzx*, %struct.lzx** %7
%21 = load i32, i32* %9
%22 = call i32 @lzx_getbits(%struct.lzx* %20, i32 %21)
store i32 %22, i32* %13
%23 = load i32, i32* %13
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32, i32* %13
store i32 %26, i32* %6
br label %45
27: ; preds = %19
%28 = load i32, i32* %13
%29 = load i32*, i32** %10
%30 = load i32, i32* %12
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
br label %33
33: ; preds = %27
%34 = load i32, i32* %12
%35 = add i32 %34, 1
store i32 %35, i32* %12
br label %15
36: ; preds = %15
%37 = load %struct.huffman_alphabet*, %struct.huffman_alphabet** %11
%38 = load i32*, i32** %10
%39 = load i32, i32* %8
%40 = call i32 @huffman_alphabet(%struct.huffman_alphabet* %37, i32* %38, i32 %39)
store i32 %40, i32* %14
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = load i32, i32* %14
store i32 %43, i32* %6
br label %45
44: ; preds = %36
store i32 0, i32* %6
br label %45
45: ; preds = %44, %42, %25
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
%struct.lzx = type { i32 }
%struct.huffman_alphabet = type { i32 }
define i32 @lzx_raw_alphabet(%struct.lzx* %0, i32 %1, i32 %2, i32* %3, %struct.huffman_alphabet* %4) {
%6 = icmp eq i32 %1, 0
br i1 %6, label %17, label %7
7: ; preds = %5
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %13
%10 = phi i64 [ 0, %7 ], [ %15, %13 ]
%11 = tail call i32 @lzx_getbits(%struct.lzx* %0, i32 %2)
%12 = icmp slt i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = getelementptr inbounds i32, i32* %3, i64 %10
store i32 %11, i32* %14
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %17, label %9
17: ; preds = %13, %5
%18 = tail call i32 @huffman_alphabet(%struct.huffman_alphabet* %4, i32* %3, i32 %1)
br label %19
19: ; preds = %9, %17
%20 = phi i32 [ %18, %17 ], [ %11, %9 ]
ret i32 %20
}