#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 */
scalar_t__ CalculateBlockSymbolSize(unsigned int *, unsigned int *,
                                    unsigned short const *,
                                    unsigned short const *, size_t, size_t);
scalar_t__ CalculateTreeSize(unsigned int *, unsigned int *);
int /*<<< orphan*/ GetDynamicLengths(unsigned short const *,
                                     unsigned short const *, size_t, size_t,
                                     unsigned int *, unsigned int *);
int /*<<< orphan*/ GetFixedTree(unsigned int *, unsigned int *);
int /*<<< orphan*/ assert(int);
double ZopfliCalculateBlockSize(const unsigned short *litlens,
                                const unsigned short *dists, size_t lstart,
                                size_t lend, int btype) {
  unsigned ll_lengths[288];
  unsigned d_lengths[32];
  double result = 3;
  assert(btype == 1 || btype == 2);
  if (btype == 1) {
    GetFixedTree(ll_lengths, d_lengths);
  } else {
    GetDynamicLengths(litlens, dists, lstart, lend, ll_lengths, d_lengths);
    result += CalculateTreeSize(ll_lengths, d_lengths);
  }
  result += CalculateBlockSymbolSize(ll_lengths, d_lengths, litlens, dists,
                                     lstart, lend);
  return result;
}


x86 assembly (clang, -O0):
<ZopfliCalculateBlockSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movsd  0xe89(%rip),%xmm0
movsd  %xmm0,-0x538(%rbp)
ff
mov    $0x1,%al
cmpl   $0x1,-0x24(%rbp)
mov    %al,-0x539(%rbp)
je     119e <ZopfliCalculateBlockSize+0x4e>
cmpl   $0x2,-0x24(%rbp)
sete   %al
mov    %al,-0x539(%rbp)
mov    -0x539(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0x1,-0x24(%rbp)
jne    11d0 <ZopfliCalculateBlockSize+0x80>
lea    -0x4b0(%rbp),%rdi
lea    -0x530(%rbp),%rsi
call   1040 <GetFixedTree@plt>
jmp    121b <ZopfliCalculateBlockSize+0xcb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x4b0(%rbp),%r8
lea    -0x530(%rbp),%r9
call   1030 <GetDynamicLengths@plt>
lea    -0x4b0(%rbp),%rdi
lea    -0x530(%rbp),%rsi
call   1050 <CalculateTreeSize@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x538(%rbp),%xmm0
ff
movsd  %xmm0,-0x538(%rbp)
ff
lea    -0x4b0(%rbp),%rdi
lea    -0x530(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
call   1070 <CalculateBlockSymbolSize@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x538(%rbp),%xmm0
ff
movsd  %xmm0,-0x538(%rbp)
ff
movsd  -0x538(%rbp),%xmm0
ff
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ZopfliCalculateBlockSize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    -0x1(%rbx),%eax
xor    %edi,%edi
cmp    $0x2,%eax
setb   %dil
call   1060 <assert@plt>
cmp    $0x1,%ebx
jne    11a2 <ZopfliCalculateBlockSize+0x52>
lea    0x90(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <GetFixedTree@plt>
movsd  0xe60(%rip),%xmm0
jmp    11de <ZopfliCalculateBlockSize+0x8e>
lea    0x90(%rsp),%rbx
lea    0x10(%rsp),%rbp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
mov    %rbp,%r9
call   1030 <GetDynamicLengths@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <CalculateTreeSize@plt>
cvtsi2sd %rax,%xmm0
addsd  0xe22(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x90(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1070 <CalculateBlockSymbolSize@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @ZopfliCalculateBlockSize(i16* %0, i16* %1, i64 %2, i64 %3, i32 %4) {
%6 = alloca i16*
%7 = alloca i16*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca [288 x i32]
%12 = alloca [32 x i32]
%13 = alloca double
store i16* %0, i16** %6
store i16* %1, i16** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i32 %4, i32* %10
store double 3.000000e+00, double* %13
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %5
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 2
br label %19
19: ; preds = %16, %5
%20 = phi i1 [ true, %5 ], [ %18, %16 ]
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = getelementptr inbounds [288 x i32], [288 x i32]* %11, i64 0, i64 0
%27 = getelementptr inbounds [32 x i32], [32 x i32]* %12, i64 0, i64 0
%28 = call i32 @GetFixedTree(i32* %26, i32* %27)
br label %43
29: ; preds = %19
%30 = load i16*, i16** %6
%31 = load i16*, i16** %7
%32 = load i64, i64* %8
%33 = load i64, i64* %9
%34 = getelementptr inbounds [288 x i32], [288 x i32]* %11, i64 0, i64 0
%35 = getelementptr inbounds [32 x i32], [32 x i32]* %12, i64 0, i64 0
%36 = call i32 @GetDynamicLengths(i16* %30, i16* %31, i64 %32, i64 %33, i32* %34, i32* %35)
%37 = getelementptr inbounds [288 x i32], [288 x i32]* %11, i64 0, i64 0
%38 = getelementptr inbounds [32 x i32], [32 x i32]* %12, i64 0, i64 0
%39 = call i64 @CalculateTreeSize(i32* %37, i32* %38)
%40 = sitofp i64 %39 to double
%41 = load double, double* %13
%42 = fadd double %41, %40
store double %42, double* %13
br label %43
43: ; preds = %29, %25
%44 = getelementptr inbounds [288 x i32], [288 x i32]* %11, i64 0, i64 0
%45 = getelementptr inbounds [32 x i32], [32 x i32]* %12, i64 0, i64 0
%46 = load i16*, i16** %6
%47 = load i16*, i16** %7
%48 = load i64, i64* %8
%49 = load i64, i64* %9
%50 = call i64 @CalculateBlockSymbolSize(i32* %44, i32* %45, i16* %46, i16* %47, i64 %48, i64 %49)
%51 = sitofp i64 %50 to double
%52 = load double, double* %13
%53 = fadd double %52, %51
store double %53, double* %13
%54 = load double, double* %13
ret double %54
}

LLVM IR (-O2):
define double @ZopfliCalculateBlockSize(i16* %0, i16* %1, i64 %2, i64 %3, i32 %4) {
%6 = alloca [288 x i32]
%7 = alloca [32 x i32]
%8 = bitcast [288 x i32]* %6 to i8*
%9 = bitcast [32 x i32]* %7 to i8*
%10 = icmp eq i32 %4, 1
%11 = add i32 %4, -1
%12 = icmp ult i32 %11, 2
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = getelementptr inbounds [288 x i32], [288 x i32]* %6, i64 0, i64 0
%16 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
br i1 %10, label %17, label %19
17: ; preds = %5
%18 = call i32 @GetFixedTree(i32* %15, i32* %16)
br label %24
19: ; preds = %5
%20 = call i32 @GetDynamicLengths(i16* %0, i16* %1, i64 %2, i64 %3, i32* %15, i32* %16)
%21 = call i64 @CalculateTreeSize(i32* %15, i32* %16)
%22 = sitofp i64 %21 to double
%23 = fadd double %22, 3.000000e+00
br label %24
24: ; preds = %19, %17
%25 = phi double [ 3.000000e+00, %17 ], [ %23, %19 ]
%26 = getelementptr inbounds [288 x i32], [288 x i32]* %6, i64 0, i64 0
%27 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
%28 = call i64 @CalculateBlockSymbolSize(i32* %26, i32* %27, i16* %0, i16* %1, i64 %2, i64 %3)
%29 = sitofp i64 %28 to double
%30 = fadd double %25, %29
ret double %30
}