#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*/ putc(unsigned char, int /*<<< orphan*/ *);
void jo_writeBits(FILE *fp, int *bitBuf, int *bitCnt,
                  const unsigned short *bs) {
  *bitCnt += bs[1];
  *bitBuf |= bs[0] << (24 - *bitCnt);
  while (*bitCnt >= 8) {
    unsigned char c = (*bitBuf >> 16) & 255;
    putc(c, fp);
    if (c == 255) {
      putc(0, fp);
    }
    *bitBuf <<= 8;
    *bitCnt -= 8;
  }
}


x86 assembly (clang, -O0):
<jo_writeBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzwl 0x2(%rax),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movzwl (%rax),%eax
mov    -0x18(%rbp),%rdx
mov    $0x18,%ecx
sub    (%rdx),%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x8,(%rax)
jl     11b8 <jo_writeBits+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
movzbl -0x21(%rbp),%eax
cmp    $0xff,%eax
jne    119d <jo_writeBits+0x8d>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
shl    $0x8,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0x8,%ecx
mov    %ecx,(%rax)
jmp    1156 <jo_writeBits+0x46>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jo_writeBits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movzwl 0x2(%rcx),%eax
add    (%rdx),%eax
mov    %eax,(%rdx)
movzwl (%rcx),%ebp
mov    $0x18,%cl
sub    %al,%cl
shl    %cl,%ebp
or     (%rsi),%ebp
mov    %ebp,(%rsi)
cmpl   $0x8,(%rdx)
jl     1179 <jo_writeBits+0x69>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
shr    $0x10,%eax
movzbl %al,%edi
mov    %r15,%rsi
call   1030 <putc@plt>
not    %ebp
test   $0xff0000,%ebp
jne    1164 <jo_writeBits+0x54>
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <putc@plt>
shll   $0x8,(%rbx)
mov    (%r14),%eax
lea    -0x8(%rax),%ecx
mov    %ecx,(%r14)
cmp    $0x10,%eax
jl     1179 <jo_writeBits+0x69>
mov    (%rbx),%ebp
jmp    1140 <jo_writeBits+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @jo_writeBits(i32* %0, i32* %1, i32* %2, i16* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i16*
%9 = alloca i8
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i16* %3, i16** %8
%10 = load i16*, i16** %8
%11 = getelementptr inbounds i16, i16* %10, i64 1
%12 = load i16, i16* %11
%13 = zext i16 %12 to i32
%14 = load i32*, i32** %7
%15 = load i32, i32* %14
%16 = add nsw i32 %15, %13
store i32 %16, i32* %14
%17 = load i16*, i16** %8
%18 = getelementptr inbounds i16, i16* %17, i64 0
%19 = load i16, i16* %18
%20 = zext i16 %19 to i32
%21 = load i32*, i32** %7
%22 = load i32, i32* %21
%23 = sub nsw i32 24, %22
%24 = shl i32 %20, %23
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = or i32 %26, %24
store i32 %27, i32* %25
br label %28
28: ; preds = %47, %4
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = icmp sge i32 %30, 8
br i1 %31, label %32, label %54
32: ; preds = %28
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = ashr i32 %34, 16
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i8
store i8 %37, i8* %9
%38 = load i8, i8* %9
%39 = load i32*, i32** %5
%40 = call i32 @putc(i8 zeroext %38, i32* %39)
%41 = load i8, i8* %9
%42 = zext i8 %41 to i32
%43 = icmp eq i32 %42, 255
br i1 %43, label %44, label %47
44: ; preds = %32
%45 = load i32*, i32** %5
%46 = call i32 @putc(i8 zeroext 0, i32* %45)
br label %47
47: ; preds = %44, %32
%48 = load i32*, i32** %6
%49 = load i32, i32* %48
%50 = shl i32 %49, 8
store i32 %50, i32* %48
%51 = load i32*, i32** %7
%52 = load i32, i32* %51
%53 = sub nsw i32 %52, 8
store i32 %53, i32* %51
br label %28
54: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @jo_writeBits(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i16* nocapture %3) {
%5 = getelementptr inbounds i16, i16* %3, i64 1
%6 = load i16, i16* %5
%7 = zext i16 %6 to i32
%8 = load i32, i32* %2
%9 = add nsw i32 %8, %7
store i32 %9, i32* %2
%10 = load i16, i16* %3
%11 = zext i16 %10 to i32
%12 = sub nsw i32 24, %9
%13 = shl i32 %11, %12
%14 = load i32, i32* %1
%15 = or i32 %13, %14
store i32 %15, i32* %1
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 7
br i1 %17, label %18, label %35
18: ; preds = %4, %33
%19 = phi i32 [ %34, %33 ], [ %15, %4 ]
%20 = lshr i32 %19, 16
%21 = trunc i32 %20 to i8
%22 = tail call i32 @putc(i8 zeroext %21, i32* %0)
%23 = and i32 %19, 16711680
%24 = icmp eq i32 %23, 16711680
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = tail call i32 @putc(i8 zeroext 0, i32* %0)
br label %27
27: ; preds = %25, %18
%28 = load i32, i32* %1
%29 = shl i32 %28, 8
store i32 %29, i32* %1
%30 = load i32, i32* %2
%31 = add nsw i32 %30, -8
store i32 %31, i32* %2
%32 = icmp sgt i32 %30, 15
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i32, i32* %1
br label %18
35: ; preds = %27, %4
ret void
}