#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 */
struct bitwriter {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ bwrite_nbits(struct bitwriter *, int, int);
void bwrite_huffman_codes(struct bitwriter *bw, int *l, int N) {
  int i;
  for (i = 0; i < N; i++) {
    assert(l[i] >= 0 && l[i] <= 15);
    bwrite_nbits(bw, l[i], 4);
  }
}


x86 assembly (clang, -O0):
<bwrite_huffman_codes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <bwrite_huffman_codes+0x83>
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
xor    %eax,%eax
cmpl   $0x0,(%rcx,%rdx,4)
mov    %al,-0x19(%rbp)
jl     116f <bwrite_huffman_codes+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0xf,(%rax,%rcx,4)
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    $0x4,%edx
call   1030 <bwrite_nbits@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <bwrite_huffman_codes+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bwrite_huffman_codes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    116a <bwrite_huffman_codes+0x4a>
mov    %rsi,%r12
mov    %rdi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
cmpl   $0x10,(%r12,%rbx,4)
setb   %dil
call   1040 <assert@plt>
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <bwrite_nbits@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <bwrite_huffman_codes+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.bitwriter = type { i32 }
define void @bwrite_huffman_codes(%struct.bitwriter* %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %16, %7 ]
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = load i32, i32* %9
%11 = icmp ult i32 %10, 16
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* %9
%15 = tail call i32 @bwrite_nbits(%struct.bitwriter* %0, i32 %14, i32 4)
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %7
18: ; preds = %7, %3
ret void
}