#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 */

/* Variables and functions */
size_t EncodeTree(unsigned int const *, unsigned int const *, int, int, int,
                  unsigned char *, unsigned char **, size_t *);
void AddDynamicTree(const unsigned *ll_lengths, const unsigned *d_lengths,
                    unsigned char *bp, unsigned char **out, size_t *outsize) {
  int i;
  int best = 0;
  size_t bestsize = 0;
  for (i = 0; i < 8; i++) {
    size_t size =
        EncodeTree(ll_lengths, d_lengths, i & 1, i & 2, i & 4, 0, 0, 0);
    if (bestsize == 0 || size < bestsize) {
      bestsize = size;
      best = i;
    }
  }
  EncodeTree(ll_lengths, d_lengths, best & 1, best & 2, best & 4, bp, out,
             outsize);
}


x86 assembly (clang, -O0):
<AddDynamicTree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jge    11c1 <AddDynamicTree+0xb1>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
and    $0x1,%edx
mov    -0x2c(%rbp),%ecx
and    $0x2,%ecx
mov    -0x2c(%rbp),%r8d
and    $0x4,%r8d
xor    %eax,%eax
mov    %eax,%r9d
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
call   1030 <EncodeTree@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11a0 <AddDynamicTree+0x90>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11ae <AddDynamicTree+0x9e>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11b3 <AddDynamicTree+0xa3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1142 <AddDynamicTree+0x32>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%edx
and    $0x1,%edx
mov    -0x30(%rbp),%ecx
and    $0x2,%ecx
mov    -0x30(%rbp),%r8d
and    $0x4,%r8d
mov    -0x18(%rbp),%r9
mov    -0x20(%rbp),%r10
mov    -0x28(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <EncodeTree@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AddDynamicTree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rsi,%r13
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
mov    %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
test   %rbp,%rbp
sete   %cl
cmp    %rbp,%rax
setb   %dl
or     %cl,%dl
movzbl %dl,%r14d
test   %r14b,%r14b
cmovne %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    $0x2,%ebx
mov    %r15,%rdi
mov    %r13,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
test   %rbp,%rbp
sete   %cl
cmp    %rbp,%rax
setb   %dl
or     %cl,%dl
cmovne %ebx,%r14d
cmovne %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
test   %rbp,%rbp
sete   %cl
cmp    %rbp,%rax
setb   %dl
or     %cl,%dl
mov    $0x3,%ebx
cmove  %r14d,%ebx
cmovne %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    $0x4,%r14d
mov    %r15,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
test   %rbp,%rbp
sete   %cl
cmp    %rbp,%rax
setb   %dl
or     %cl,%dl
cmovne %r14d,%ebx
cmovne %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
test   %rbp,%rbp
sete   %cl
cmp    %rbp,%rax
setb   %dl
or     %cl,%dl
mov    $0x5,%r12d
cmove  %ebx,%r12d
cmovne %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
test   %rbp,%rbp
sete   %cl
cmp    %rbp,%rax
setb   %dl
or     %cl,%dl
mov    $0x6,%r14d
cmove  %r12d,%r14d
cmovne %rax,%rbp
xorps  %xmm0,%xmm0
movups %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
call   1030 <EncodeTree@plt>
cmp    %rbp,%rax
mov    $0x7,%eax
cmovb  %eax,%r14d
test   %rbp,%rbp
cmove  %eax,%r14d
mov    %r14d,%edx
and    $0x1,%edx
mov    %r14d,%ecx
and    $0x2,%ecx
and    $0x4,%r14d
mov    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x18(%rsp),%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14d,%r8d
mov    0x20(%rsp),%r9
call   1030 <EncodeTree@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @AddDynamicTree(i32* %0, i32* %1, i8* %2, i8** %3, i64* %4) {
%6 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 0, i32 0, i8* null, i8** null, i64* null)
%7 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 0, i32 0, i8* null, i8** null, i64* null)
%8 = icmp eq i64 %6, 0
%9 = icmp ult i64 %7, %6
%10 = select i1 %8, i1 true, i1 %9
%11 = zext i1 %10 to i32
%12 = select i1 %10, i64 %7, i64 %6
%13 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 2, i32 0, i8* null, i8** null, i64* null)
%14 = icmp eq i64 %12, 0
%15 = icmp ult i64 %13, %12
%16 = select i1 %14, i1 true, i1 %15
%17 = select i1 %16, i32 2, i32 %11
%18 = select i1 %16, i64 %13, i64 %12
%19 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 2, i32 0, i8* null, i8** null, i64* null)
%20 = icmp eq i64 %18, 0
%21 = icmp ult i64 %19, %18
%22 = select i1 %20, i1 true, i1 %21
%23 = select i1 %22, i32 3, i32 %17
%24 = select i1 %22, i64 %19, i64 %18
%25 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 0, i32 4, i8* null, i8** null, i64* null)
%26 = icmp eq i64 %24, 0
%27 = icmp ult i64 %25, %24
%28 = select i1 %26, i1 true, i1 %27
%29 = select i1 %28, i32 4, i32 %23
%30 = select i1 %28, i64 %25, i64 %24
%31 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 0, i32 4, i8* null, i8** null, i64* null)
%32 = icmp eq i64 %30, 0
%33 = icmp ult i64 %31, %30
%34 = select i1 %32, i1 true, i1 %33
%35 = select i1 %34, i32 5, i32 %29
%36 = select i1 %34, i64 %31, i64 %30
%37 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 2, i32 4, i8* null, i8** null, i64* null)
%38 = icmp eq i64 %36, 0
%39 = icmp ult i64 %37, %36
%40 = select i1 %38, i1 true, i1 %39
%41 = select i1 %40, i32 6, i32 %35
%42 = select i1 %40, i64 %37, i64 %36
%43 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 2, i32 4, i8* null, i8** null, i64* null)
%44 = icmp eq i64 %42, 0
%45 = icmp ult i64 %43, %42
%46 = select i1 %44, i1 true, i1 %45
%47 = select i1 %46, i32 7, i32 %41
%48 = and i32 %47, 1
%49 = and i32 %47, 2
%50 = and i32 %47, 4
%51 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 %48, i32 %49, i32 %50, i8* %2, i8** %3, i64* %4)
ret void
}