#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
void write_dht_header(FILE *f, int code_len_freq[], int sym_sorted[],
                      int tc_th) {
  int length = 19;
  int i;
  for (i = 1; i <= 16; i++)
    length += code_len_freq[i];
  fputc(0xFF, f);
  fputc(0xC4, f);
  fputc((length >> 8) & 0xFF, f);
  fputc(length & 0xFF, f);
  fputc(tc_th, f);
  for (i = 1; i <= 16; i++)
    fputc(code_len_freq[i], f);
  for (i = 0; length > 19; i++, length--)
    fputc(sym_sorted[i], f);
}


x86 assembly (clang, -O0):
<write_dht_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x13,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jg     115e <write_dht_header+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1135 <write_dht_header+0x25>
mov    -0x8(%rbp),%rsi
mov    $0xff,%edi
call   1030 <fputc@plt>
mov    -0x8(%rbp),%rsi
mov    $0xc4,%edi
call   1030 <fputc@plt>
mov    -0x20(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x20(%rbp),%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jg     11e0 <write_dht_header+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <write_dht_header+0xa4>
movl   $0x0,-0x24(%rbp)
cmpl   $0x13,-0x20(%rbp)
jle    121c <write_dht_header+0x10c>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11e7 <write_dht_header+0xd7>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_dht_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
movdqu 0x4(%rsi),%xmm0
movdqu 0x14(%rsi),%xmm1
movdqu 0x24(%rsi),%xmm2
paddd  %xmm0,%xmm2
movdqu 0x34(%rsi),%xmm0
paddd  %xmm1,%xmm0
paddd  %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebp
lea    0x13(%rbp),%r13d
mov    $0xff,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    $0xc4,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %r13d,%eax
movzbl %ah,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
movzbl %r13b,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x4(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x8(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0xc(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x10(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x14(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x18(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x1c(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x20(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x24(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x28(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x2c(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x30(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x34(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x38(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x3c(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    0x40(%r15),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
test   %ebp,%ebp
jle    1286 <write_dht_header+0x176>
add    $0x14,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x4,%rbx
add    $0xffffffff,%ebp
cmp    $0x14,%ebp
ja     1270 <write_dht_header+0x160>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @write_dht_header(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 19, i32* %9
store i32 1, i32* %10
br label %11
11: ; preds = %22, %4
%12 = load i32, i32* %10
%13 = icmp sle i32 %12, 16
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32*, i32** %6
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %9
%21 = add nsw i32 %20, %19
store i32 %21, i32* %9
br label %22
22: ; preds = %14
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
store i32 %24, i32* %10
br label %11
25: ; preds = %11
%26 = load i32*, i32** %5
%27 = call i32 @fputc(i32 255, i32* %26)
%28 = load i32*, i32** %5
%29 = call i32 @fputc(i32 196, i32* %28)
%30 = load i32, i32* %9
%31 = ashr i32 %30, 8
%32 = and i32 %31, 255
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i32 %32, i32* %33)
%35 = load i32, i32* %9
%36 = and i32 %35, 255
%37 = load i32*, i32** %5
%38 = call i32 @fputc(i32 %36, i32* %37)
%39 = load i32, i32* %8
%40 = load i32*, i32** %5
%41 = call i32 @fputc(i32 %39, i32* %40)
store i32 1, i32* %10
br label %42
42: ; preds = %53, %25
%43 = load i32, i32* %10
%44 = icmp sle i32 %43, 16
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32*, i32** %6
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = load i32, i32* %49
%51 = load i32*, i32** %5
%52 = call i32 @fputc(i32 %50, i32* %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %42
56: ; preds = %42
store i32 0, i32* %10
br label %57
57: ; preds = %68, %56
%58 = load i32, i32* %9
%59 = icmp sgt i32 %58, 19
br i1 %59, label %60, label %73
60: ; preds = %57
%61 = load i32*, i32** %7
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = load i32*, i32** %5
%67 = call i32 @fputc(i32 %65, i32* %66)
br label %68
68: ; preds = %60
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
%71 = load i32, i32* %9
%72 = add nsw i32 %71, -1
store i32 %72, i32* %9
br label %57
73: ; preds = %57
ret void
}

LLVM IR (-O2):
define void @write_dht_header(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = getelementptr inbounds i32, i32* %1, i64 1
%6 = getelementptr inbounds i32, i32* %1, i64 2
%7 = getelementptr inbounds i32, i32* %1, i64 3
%8 = getelementptr inbounds i32, i32* %1, i64 4
%9 = getelementptr inbounds i32, i32* %1, i64 5
%10 = getelementptr inbounds i32, i32* %1, i64 6
%11 = getelementptr inbounds i32, i32* %1, i64 7
%12 = getelementptr inbounds i32, i32* %1, i64 8
%13 = getelementptr inbounds i32, i32* %1, i64 9
%14 = getelementptr inbounds i32, i32* %1, i64 10
%15 = getelementptr inbounds i32, i32* %1, i64 11
%16 = getelementptr inbounds i32, i32* %1, i64 12
%17 = getelementptr inbounds i32, i32* %1, i64 13
%18 = getelementptr inbounds i32, i32* %1, i64 14
%19 = getelementptr inbounds i32, i32* %1, i64 15
%20 = getelementptr inbounds i32, i32* %1, i64 16
%21 = bitcast i32* %5 to <16 x i32>*
%22 = load <16 x i32>, <16 x i32>* %21
%23 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %22)
%24 = add nsw i32 %23, 19
%25 = tail call i32 @fputc(i32 255, i32* %0)
%26 = tail call i32 @fputc(i32 196, i32* %0)
%27 = lshr i32 %24, 8
%28 = and i32 %27, 255
%29 = tail call i32 @fputc(i32 %28, i32* %0)
%30 = and i32 %24, 255
%31 = tail call i32 @fputc(i32 %30, i32* %0)
%32 = tail call i32 @fputc(i32 %3, i32* %0)
%33 = load i32, i32* %5
%34 = tail call i32 @fputc(i32 %33, i32* %0)
%35 = load i32, i32* %6
%36 = tail call i32 @fputc(i32 %35, i32* %0)
%37 = load i32, i32* %7
%38 = tail call i32 @fputc(i32 %37, i32* %0)
%39 = load i32, i32* %8
%40 = tail call i32 @fputc(i32 %39, i32* %0)
%41 = load i32, i32* %9
%42 = tail call i32 @fputc(i32 %41, i32* %0)
%43 = load i32, i32* %10
%44 = tail call i32 @fputc(i32 %43, i32* %0)
%45 = load i32, i32* %11
%46 = tail call i32 @fputc(i32 %45, i32* %0)
%47 = load i32, i32* %12
%48 = tail call i32 @fputc(i32 %47, i32* %0)
%49 = load i32, i32* %13
%50 = tail call i32 @fputc(i32 %49, i32* %0)
%51 = load i32, i32* %14
%52 = tail call i32 @fputc(i32 %51, i32* %0)
%53 = load i32, i32* %15
%54 = tail call i32 @fputc(i32 %53, i32* %0)
%55 = load i32, i32* %16
%56 = tail call i32 @fputc(i32 %55, i32* %0)
%57 = load i32, i32* %17
%58 = tail call i32 @fputc(i32 %57, i32* %0)
%59 = load i32, i32* %18
%60 = tail call i32 @fputc(i32 %59, i32* %0)
%61 = load i32, i32* %19
%62 = tail call i32 @fputc(i32 %61, i32* %0)
%63 = load i32, i32* %20
%64 = tail call i32 @fputc(i32 %63, i32* %0)
%65 = icmp sgt i32 %23, 0
br i1 %65, label %66, label %75
66: ; preds = %4, %66
%67 = phi i64 [ %72, %66 ], [ 0, %4 ]
%68 = phi i32 [ %73, %66 ], [ %24, %4 ]
%69 = getelementptr inbounds i32, i32* %2, i64 %67
%70 = load i32, i32* %69
%71 = tail call i32 @fputc(i32 %70, i32* %0)
%72 = add nuw nsw i64 %67, 1
%73 = add nsw i32 %68, -1
%74 = icmp ugt i32 %68, 20
br i1 %74, label %66, label %75
75: ; preds = %66, %4
ret void
}