#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*/ bputc(int);
void WriteHuffman(int *bits, int *huffval) {
  int i, accum;
  for (accum = 0, i = 0; i < 16; i++) {
    bputc(bits[i]);
    accum += bits[i];
  }
  for (i = 0; i < accum; i++) {
    bputc(huffval[i]);
  }
}


x86 assembly (clang, -O0):
<WriteHuffman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    1167 <WriteHuffman+0x57>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <bputc@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112e <WriteHuffman+0x1e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1198 <WriteHuffman+0x88>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <bputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <WriteHuffman+0x5e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteHuffman>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1030 <bputc@plt>
mov    0x4(%rbx),%edi
movss  (%rbx),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <bputc@plt>
mov    0x8(%rbx),%edi
movss  0x4(%rbx),%xmm0
unpcklps 0x10(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <bputc@plt>
mov    0xc(%rbx),%edi
movss  0x8(%rbx),%xmm0
movaps %xmm0,0x20(%rsp)
call   1030 <bputc@plt>
mov    0x10(%rbx),%edi
movss  0xc(%rbx),%xmm0
unpcklps 0x20(%rsp),%xmm0
unpcklpd 0x10(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
call   1030 <bputc@plt>
mov    0x14(%rbx),%edi
movss  0x10(%rbx),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <bputc@plt>
mov    0x18(%rbx),%edi
movss  0x14(%rbx),%xmm0
unpcklps 0x10(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <bputc@plt>
mov    0x1c(%rbx),%edi
movss  0x18(%rbx),%xmm0
movaps %xmm0,(%rsp)
call   1030 <bputc@plt>
mov    0x20(%rbx),%edi
movss  0x1c(%rbx),%xmm0
unpcklps (%rsp),%xmm0
unpcklpd 0x10(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <bputc@plt>
mov    0x24(%rbx),%edi
movss  0x20(%rbx),%xmm0
movaps %xmm0,(%rsp)
call   1030 <bputc@plt>
mov    0x28(%rbx),%edi
movss  0x24(%rbx),%xmm0
unpcklps (%rsp),%xmm0
movaps %xmm0,(%rsp)
call   1030 <bputc@plt>
mov    0x2c(%rbx),%edi
movss  0x28(%rbx),%xmm0
movaps %xmm0,0x30(%rsp)
call   1030 <bputc@plt>
mov    0x30(%rbx),%edi
movd   0x2c(%rbx),%xmm0
punpckldq 0x30(%rsp),%xmm0
punpcklqdq (%rsp),%xmm0
paddd  0x20(%rsp),%xmm0
movdqa %xmm0,0x20(%rsp)
call   1030 <bputc@plt>
mov    0x34(%rbx),%edi
movss  0x30(%rbx),%xmm0
movaps %xmm0,(%rsp)
call   1030 <bputc@plt>
mov    0x38(%rbx),%edi
movss  0x34(%rbx),%xmm0
unpcklps (%rsp),%xmm0
movaps %xmm0,(%rsp)
call   1030 <bputc@plt>
mov    0x3c(%rbx),%edi
movss  0x38(%rbx),%xmm0
movaps %xmm0,0x30(%rsp)
call   1030 <bputc@plt>
movd   0x3c(%rbx),%xmm0
punpckldq 0x30(%rsp),%xmm0
punpcklqdq (%rsp),%xmm0
paddd  0x10(%rsp),%xmm0
paddd  0x20(%rsp),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
test   %eax,%eax
jle    12c2 <WriteHuffman+0x1b2>
mov    %eax,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,4),%edi
call   1030 <bputc@plt>
add    $0x1,%rbx
cmp    %r15,%rbx
jb     12b0 <WriteHuffman+0x1a0>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @WriteHuffman(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 16
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i32*, i32** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = call i32 @bputc(i32 %15)
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = load i32, i32* %6
%23 = add nsw i32 %22, %21
store i32 %23, i32* %6
br label %24
24: ; preds = %10
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %7
27: ; preds = %7
store i32 0, i32* %5
br label %28
28: ; preds = %39, %27
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @bputc(i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %28
42: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @WriteHuffman(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = tail call i32 @bputc(i32 %3)
%5 = load i32, i32* %0
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @bputc(i32 %7)
%9 = load i32, i32* %6
%10 = getelementptr inbounds i32, i32* %0, i64 2
%11 = load i32, i32* %10
%12 = tail call i32 @bputc(i32 %11)
%13 = load i32, i32* %10
%14 = getelementptr inbounds i32, i32* %0, i64 3
%15 = load i32, i32* %14
%16 = tail call i32 @bputc(i32 %15)
%17 = load i32, i32* %14
%18 = getelementptr inbounds i32, i32* %0, i64 4
%19 = load i32, i32* %18
%20 = tail call i32 @bputc(i32 %19)
%21 = load i32, i32* %18
%22 = getelementptr inbounds i32, i32* %0, i64 5
%23 = load i32, i32* %22
%24 = tail call i32 @bputc(i32 %23)
%25 = load i32, i32* %22
%26 = getelementptr inbounds i32, i32* %0, i64 6
%27 = load i32, i32* %26
%28 = tail call i32 @bputc(i32 %27)
%29 = load i32, i32* %26
%30 = getelementptr inbounds i32, i32* %0, i64 7
%31 = load i32, i32* %30
%32 = tail call i32 @bputc(i32 %31)
%33 = load i32, i32* %30
%34 = getelementptr inbounds i32, i32* %0, i64 8
%35 = load i32, i32* %34
%36 = tail call i32 @bputc(i32 %35)
%37 = load i32, i32* %34
%38 = getelementptr inbounds i32, i32* %0, i64 9
%39 = load i32, i32* %38
%40 = tail call i32 @bputc(i32 %39)
%41 = load i32, i32* %38
%42 = getelementptr inbounds i32, i32* %0, i64 10
%43 = load i32, i32* %42
%44 = tail call i32 @bputc(i32 %43)
%45 = load i32, i32* %42
%46 = getelementptr inbounds i32, i32* %0, i64 11
%47 = load i32, i32* %46
%48 = tail call i32 @bputc(i32 %47)
%49 = load i32, i32* %46
%50 = getelementptr inbounds i32, i32* %0, i64 12
%51 = load i32, i32* %50
%52 = tail call i32 @bputc(i32 %51)
%53 = load i32, i32* %50
%54 = getelementptr inbounds i32, i32* %0, i64 13
%55 = load i32, i32* %54
%56 = tail call i32 @bputc(i32 %55)
%57 = load i32, i32* %54
%58 = getelementptr inbounds i32, i32* %0, i64 14
%59 = load i32, i32* %58
%60 = tail call i32 @bputc(i32 %59)
%61 = load i32, i32* %58
%62 = getelementptr inbounds i32, i32* %0, i64 15
%63 = load i32, i32* %62
%64 = tail call i32 @bputc(i32 %63)
%65 = load i32, i32* %62
%66 = insertelement <16 x i32> poison, i32 %65, i64 0
%67 = insertelement <16 x i32> %66, i32 %61, i64 1
%68 = insertelement <16 x i32> %67, i32 %57, i64 2
%69 = insertelement <16 x i32> %68, i32 %53, i64 3
%70 = insertelement <16 x i32> %69, i32 %49, i64 4
%71 = insertelement <16 x i32> %70, i32 %45, i64 5
%72 = insertelement <16 x i32> %71, i32 %41, i64 6
%73 = insertelement <16 x i32> %72, i32 %37, i64 7
%74 = insertelement <16 x i32> %73, i32 %33, i64 8
%75 = insertelement <16 x i32> %74, i32 %29, i64 9
%76 = insertelement <16 x i32> %75, i32 %25, i64 10
%77 = insertelement <16 x i32> %76, i32 %21, i64 11
%78 = insertelement <16 x i32> %77, i32 %17, i64 12
%79 = insertelement <16 x i32> %78, i32 %13, i64 13
%80 = insertelement <16 x i32> %79, i32 %9, i64 14
%81 = insertelement <16 x i32> %80, i32 %5, i64 15
%82 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %81)
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %93
84: ; preds = %2
%85 = zext i32 %82 to i64
br label %86
86: ; preds = %84, %86
%87 = phi i64 [ 0, %84 ], [ %91, %86 ]
%88 = getelementptr inbounds i32, i32* %1, i64 %87
%89 = load i32, i32* %88
%90 = tail call i32 @bputc(i32 %89)
%91 = add nuw nsw i64 %87, 1
%92 = icmp ult i64 %91, %85
br i1 %92, label %86, label %93
93: ; preds = %86, %2
ret void
}