#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 */
int /*<<< orphan*/ AddDynamicTree(unsigned int const *, unsigned int const *,
                                  unsigned char *, unsigned char **, size_t *);
int /*<<< orphan*/ free(unsigned char *);
size_t CalculateTreeSize(const unsigned *ll_lengths, const unsigned *d_lengths,
                         size_t *ll_counts, size_t *d_counts) {
  unsigned char *dummy = 0;
  size_t dummysize = 0;
  unsigned char bp = 0;
  (void)ll_counts;
  (void)d_counts;
  AddDynamicTree(ll_lengths, d_lengths, &bp, &dummy, &dummysize);
  free(dummy);
  return dummysize * 8 + (bp & 7);
}


x86 assembly (clang, -O0):
<CalculateTreeSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x31(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1040 <AddDynamicTree@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
movzbl -0x31(%rbp),%ecx
and    $0x7,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateTreeSize>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x7(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1040 <AddDynamicTree@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
movzbl 0x7(%rsp),%ecx
and    $0x7,%ecx
lea    (%rcx,%rax,8),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i64 @CalculateTreeSize(i32* %0, i32* %1, i64* %2, i64* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
store i8* null, i8** %9
store i64 0, i64* %10
store i8 0, i8* %11
%12 = load i64*, i64** %7
%13 = load i64*, i64** %8
%14 = load i32*, i32** %5
%15 = load i32*, i32** %6
%16 = call i32 @AddDynamicTree(i32* %14, i32* %15, i8* %11, i8** %9, i64* %10)
%17 = load i8*, i8** %9
%18 = call i32 @free(i8* %17)
%19 = load i64, i64* %10
%20 = mul i64 %19, 8
%21 = load i8, i8* %11
%22 = zext i8 %21 to i32
%23 = and i32 %22, 7
%24 = sext i32 %23 to i64
%25 = add i64 %20, %24
ret i64 %25
}

LLVM IR (-O2):
define i64 @CalculateTreeSize(i32* %0, i32* %1, i64* nocapture readnone %2, i64* nocapture readnone %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = bitcast i64* %6 to i8*
store i64 0, i64* %6
store i8 0, i8* %7
%10 = call i32 @AddDynamicTree(i32* %0, i32* %1, i8* %7, i8** %5, i64* %6)
%11 = load i8*, i8** %5
%12 = call i32 @free(i8* %11)
%13 = load i64, i64* %6
%14 = shl i64 %13, 3
%15 = load i8, i8* %7
%16 = and i8 %15, 7
%17 = zext i8 %16 to i64
%18 = or i64 %14, %17
ret i64 %18
}