#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,
                  int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
size_t CalculateTreeSize(const unsigned *ll_lengths,
                         const unsigned *d_lengths) {
  size_t result = 0;
  int i;
  for (i = 0; i < 8; i++) {
    size_t size =
        EncodeTree(ll_lengths, d_lengths, i & 1, i & 2, i & 4, 0, 0, 0);
    if (result == 0 || size < result)
      result = size;
  }
  return result;
}


x86 assembly (clang, -O0):
<CalculateTreeSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11a4 <CalculateTreeSize+0x94>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
and    $0x1,%edx
mov    -0x1c(%rbp),%ecx
and    $0x2,%ecx
mov    -0x1c(%rbp),%r8d
and    $0x4,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1030 <EncodeTree@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1189 <CalculateTreeSize+0x79>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1191 <CalculateTreeSize+0x81>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1196 <CalculateTreeSize+0x86>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <CalculateTreeSize+0x1f>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateTreeSize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %r12,%rax
mov    %r12,%r13
cmovb  %rax,%r13
test   %r12,%r12
cmove  %rax,%r13
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %r13,%rax
mov    %r13,%rbx
cmovb  %rax,%rbx
test   %r13,%r13
cmove  %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %rbx,%rax
mov    %rbx,%r12
cmovb  %rax,%r12
test   %rbx,%rbx
cmove  %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %r12,%rax
mov    %r12,%rbx
cmovb  %rax,%rbx
test   %r12,%r12
cmove  %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %rbx,%rax
mov    %rbx,%r12
cmovb  %rax,%r12
test   %rbx,%rbx
cmove  %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %r12,%rax
mov    %r12,%rbx
cmovb  %rax,%rbx
test   %r12,%r12
cmove  %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x4,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1030 <EncodeTree@plt>
add    $0x10,%rsp
cmp    %rbx,%rax
mov    %rbx,%rcx
cmovb  %rax,%rcx
test   %rbx,%rbx
cmovne %rcx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @CalculateTreeSize(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %8
8: ; preds = %30, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = load i32*, i32** %3
%13 = load i32*, i32** %4
%14 = load i32, i32* %6
%15 = and i32 %14, 1
%16 = load i32, i32* %6
%17 = and i32 %16, 2
%18 = load i32, i32* %6
%19 = and i32 %18, 4
%20 = call i64 @EncodeTree(i32* %12, i32* %13, i32 %15, i32 %17, i32 %19, i32 0, i32 0, i32 0)
store i64 %20, i64* %7
%21 = load i64, i64* %5
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %11
%24 = load i64, i64* %7
%25 = load i64, i64* %5
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23, %11
%28 = load i64, i64* %7
store i64 %28, i64* %5
br label %29
29: ; preds = %27, %23
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %8
33: ; preds = %8
%34 = load i64, i64* %5
ret i64 %34
}

LLVM IR (-O2):
define i64 @CalculateTreeSize(i32* %0, i32* %1) {
%3 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%4 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 0, i32 0, i32 0, i32 0, i32 0)
%5 = icmp eq i64 %3, 0
%6 = icmp ult i64 %4, %3
%7 = select i1 %5, i1 true, i1 %6
%8 = select i1 %7, i64 %4, i64 %3
%9 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 2, i32 0, i32 0, i32 0, i32 0)
%10 = icmp eq i64 %8, 0
%11 = icmp ult i64 %9, %8
%12 = select i1 %10, i1 true, i1 %11
%13 = select i1 %12, i64 %9, i64 %8
%14 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 2, i32 0, i32 0, i32 0, i32 0)
%15 = icmp eq i64 %13, 0
%16 = icmp ult i64 %14, %13
%17 = select i1 %15, i1 true, i1 %16
%18 = select i1 %17, i64 %14, i64 %13
%19 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 0, i32 4, i32 0, i32 0, i32 0)
%20 = icmp eq i64 %18, 0
%21 = icmp ult i64 %19, %18
%22 = select i1 %20, i1 true, i1 %21
%23 = select i1 %22, i64 %19, i64 %18
%24 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 0, i32 4, i32 0, i32 0, i32 0)
%25 = icmp eq i64 %23, 0
%26 = icmp ult i64 %24, %23
%27 = select i1 %25, i1 true, i1 %26
%28 = select i1 %27, i64 %24, i64 %23
%29 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 0, i32 2, i32 4, i32 0, i32 0, i32 0)
%30 = icmp eq i64 %28, 0
%31 = icmp ult i64 %29, %28
%32 = select i1 %30, i1 true, i1 %31
%33 = select i1 %32, i64 %29, i64 %28
%34 = tail call i64 @EncodeTree(i32* %0, i32* %1, i32 1, i32 2, i32 4, i32 0, i32 0, i32 0)
%35 = icmp eq i64 %33, 0
%36 = icmp ult i64 %34, %33
%37 = select i1 %35, i1 true, i1 %36
%38 = select i1 %37, i64 %34, i64 %33
ret i64 %38
}