#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*/ OptimizeHuffmanForRle(int, size_t *);
int /*<<< orphan*/ PatchDistanceCodesForBuggyDecoders(unsigned int *);
int /*<<< orphan*/ ZopfliCalculateBitLengths(size_t *, int, int,
                                             unsigned int *);
int /*<<< orphan*/ ZopfliLZ77Counts(unsigned short const *,
                                    unsigned short const *, size_t, size_t,
                                    size_t *, size_t *);
void GetDynamicLengths(const unsigned short *litlens,
                       const unsigned short *dists, size_t lstart, size_t lend,
                       unsigned *ll_lengths, unsigned *d_lengths) {
  size_t ll_counts[288];
  size_t d_counts[32];
  ZopfliLZ77Counts(litlens, dists, lstart, lend, ll_counts, d_counts);
  OptimizeHuffmanForRle(288, ll_counts);
  OptimizeHuffmanForRle(32, d_counts);
  ZopfliCalculateBitLengths(ll_counts, 288, 15, ll_lengths);
  ZopfliCalculateBitLengths(d_counts, 32, 15, d_lengths);
  PatchDistanceCodesForBuggyDecoders(d_lengths);
}


x86 assembly (clang, -O0):
<GetDynamicLengths>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x930(%rbp),%r8
lea    -0xa30(%rbp),%r9
call   1030 <ZopfliLZ77Counts@plt>
lea    -0x930(%rbp),%rsi
mov    $0x120,%edi
call   1040 <OptimizeHuffmanForRle@plt>
lea    -0xa30(%rbp),%rsi
mov    $0x20,%edi
call   1040 <OptimizeHuffmanForRle@plt>
lea    -0x930(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x120,%esi
mov    $0xf,%edx
call   1050 <ZopfliCalculateBitLengths@plt>
lea    -0xa30(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x20,%esi
mov    $0xf,%edx
call   1050 <ZopfliCalculateBitLengths@plt>
mov    -0x30(%rbp),%rdi
call   1060 <PatchDistanceCodesForBuggyDecoders@plt>
add    $0xa30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetDynamicLengths>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa08,%rsp
mov    %r9,%rbx
mov    %r8,%r14
lea    0x100(%rsp),%r15
mov    %rsp,%r12
mov    %r15,%r8
mov    %r12,%r9
call   1030 <ZopfliLZ77Counts@plt>
mov    $0x120,%edi
mov    %r15,%rsi
call   1040 <OptimizeHuffmanForRle@plt>
mov    $0x20,%edi
mov    %r12,%rsi
call   1040 <OptimizeHuffmanForRle@plt>
mov    %r15,%rdi
mov    $0x120,%esi
mov    $0xf,%edx
mov    %r14,%rcx
call   1050 <ZopfliCalculateBitLengths@plt>
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0xf,%edx
mov    %rbx,%rcx
call   1050 <ZopfliCalculateBitLengths@plt>
mov    %rbx,%rdi
call   1060 <PatchDistanceCodesForBuggyDecoders@plt>
add    $0xa08,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @GetDynamicLengths(i16* %0, i16* %1, i64 %2, i64 %3, i32* %4, i32* %5) {
%7 = alloca i16*
%8 = alloca i16*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca [288 x i64]
%14 = alloca [32 x i64]
store i16* %0, i16** %7
store i16* %1, i16** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%15 = load i16*, i16** %7
%16 = load i16*, i16** %8
%17 = load i64, i64* %9
%18 = load i64, i64* %10
%19 = getelementptr inbounds [288 x i64], [288 x i64]* %13, i64 0, i64 0
%20 = getelementptr inbounds [32 x i64], [32 x i64]* %14, i64 0, i64 0
%21 = call i32 @ZopfliLZ77Counts(i16* %15, i16* %16, i64 %17, i64 %18, i64* %19, i64* %20)
%22 = getelementptr inbounds [288 x i64], [288 x i64]* %13, i64 0, i64 0
%23 = call i32 @OptimizeHuffmanForRle(i32 288, i64* %22)
%24 = getelementptr inbounds [32 x i64], [32 x i64]* %14, i64 0, i64 0
%25 = call i32 @OptimizeHuffmanForRle(i32 32, i64* %24)
%26 = getelementptr inbounds [288 x i64], [288 x i64]* %13, i64 0, i64 0
%27 = load i32*, i32** %11
%28 = call i32 @ZopfliCalculateBitLengths(i64* %26, i32 288, i32 15, i32* %27)
%29 = getelementptr inbounds [32 x i64], [32 x i64]* %14, i64 0, i64 0
%30 = load i32*, i32** %12
%31 = call i32 @ZopfliCalculateBitLengths(i64* %29, i32 32, i32 15, i32* %30)
%32 = load i32*, i32** %12
%33 = call i32 @PatchDistanceCodesForBuggyDecoders(i32* %32)
ret void
}

LLVM IR (-O2):
define void @GetDynamicLengths(i16* %0, i16* %1, i64 %2, i64 %3, i32* %4, i32* %5) {
%7 = alloca [288 x i64]
%8 = alloca [32 x i64]
%9 = bitcast [288 x i64]* %7 to i8*
%10 = bitcast [32 x i64]* %8 to i8*
%11 = getelementptr inbounds [288 x i64], [288 x i64]* %7, i64 0, i64 0
%12 = getelementptr inbounds [32 x i64], [32 x i64]* %8, i64 0, i64 0
%13 = call i32 @ZopfliLZ77Counts(i16* %0, i16* %1, i64 %2, i64 %3, i64* %11, i64* %12)
%14 = call i32 @OptimizeHuffmanForRle(i32 288, i64* %11)
%15 = call i32 @OptimizeHuffmanForRle(i32 32, i64* %12)
%16 = call i32 @ZopfliCalculateBitLengths(i64* %11, i32 288, i32 15, i32* %4)
%17 = call i32 @ZopfliCalculateBitLengths(i64* %12, i32 32, i32 15, i32* %5)
%18 = call i32 @PatchDistanceCodesForBuggyDecoders(i32* %5)
ret void
}