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

/* Variables and functions */
int /*<<< orphan*/ bit_writer(int /*<<< orphan*/ *, int, int);
void encoding_writer(FILE *f, uint8_t *data, uint16_t length) {
  int i;
  if (data == NULL)
    bit_writer(f, 0, 1);
  for (i = length - 1; i >= 0; --i) {
    bit_writer(f, data[i / 8] & (1 << (i % 8)), 0);
  }
}


x86 assembly (clang, -O0):
<encoding_writer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113e <encoding_writer+0x2e>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <bit_writer@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     119f <encoding_writer+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%esi
xor    %edx,%edx
call   1030 <bit_writer@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1147 <encoding_writer+0x37>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encoding_writer>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
test   %rsi,%rsi
je     1128 <encoding_writer+0x18>
test   %ebx,%ebx
jg     113b <encoding_writer+0x2b>
jmp    1168 <encoding_writer+0x58>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <bit_writer@plt>
test   %ebx,%ebx
jle    1168 <encoding_writer+0x58>
add    $0x1,%ebx
xchg   %ax,%ax
lea    -0x2(%rbx),%ecx
mov    %ecx,%eax
and    $0x7,%cl
mov    $0x1,%esi
shl    %cl,%esi
shr    $0x3,%eax
and    (%r14,%rax,4),%esi
mov    %r15,%rdi
xor    %edx,%edx
call   1030 <bit_writer@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1140 <encoding_writer+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @encoding_writer(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32*, i32** %4
%12 = call i32 @bit_writer(i32* %11, i32 0, i32 1)
br label %13
13: ; preds = %10, %3
%14 = load i32, i32* %6
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %7
br label %16
16: ; preds = %32, %13
%17 = load i32, i32* %7
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load i32*, i32** %4
%21 = load i32*, i32** %5
%22 = load i32, i32* %7
%23 = sdiv i32 %22, 8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %21, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %7
%28 = srem i32 %27, 8
%29 = shl i32 1, %28
%30 = and i32 %26, %29
%31 = call i32 @bit_writer(i32* %20, i32 %30, i32 0)
br label %32
32: ; preds = %19
%33 = load i32, i32* %7
%34 = add nsw i32 %33, -1
store i32 %34, i32* %7
br label %16
35: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @encoding_writer(i32* %0, i32* %1, i32 %2) {
%4 = icmp eq i32* %1, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @bit_writer(i32* %0, i32 0, i32 1)
br label %7
7: ; preds = %5, %3
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %21
9: ; preds = %7, %9
%10 = phi i32 [ %11, %9 ], [ %2, %7 ]
%11 = add nsw i32 %10, -1
%12 = lshr i32 %11, 3
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = load i32, i32* %14
%16 = and i32 %11, 7
%17 = shl nuw nsw i32 1, %16
%18 = and i32 %15, %17
%19 = tail call i32 @bit_writer(i32* %0, i32 %18, i32 0)
%20 = icmp ugt i32 %10, 1
br i1 %20, label %9, label %21
21: ; preds = %9, %7
ret void
}