#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*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int pack_output(unsigned code, int bits) {
  static unsigned int out_buffer = 0;
  static int out_bits = 0;
  unsigned char out_byte;
  out_buffer |= (code << out_bits);
  out_bits += bits;
  if (out_bits >= 8) {
    out_byte = out_buffer & 0xff;
    out_bits -= 8;
    out_buffer >>= 8;
    fwrite(&out_byte, sizeof(char), 1, stdout);
  }
  return (out_bits > 0);
}


x86 assembly (clang, -O0):
<pack_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2f09(%rip),%ecx
shl    %cl,%eax
or     0x2efd(%rip),%eax
mov    %eax,0x2ef7(%rip)
mov    -0x8(%rbp),%eax
add    0x2ef2(%rip),%eax
mov    %eax,0x2eec(%rip)
cmpl   $0x8,0x2ee5(%rip)
jl     1196 <pack_output+0x86>
mov    0x2ed5(%rip),%eax
and    $0xff,%eax
mov    %al,-0x9(%rbp)
mov    0x2ecb(%rip),%eax
sub    $0x8,%eax
mov    %eax,0x2ec2(%rip)
mov    0x2eb8(%rip),%eax
shr    $0x8,%eax
mov    %eax,0x2eaf(%rip)
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
lea    -0x9(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fwrite@plt>
cmpl   $0x0,0x2e93(%rip)
setg   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_output>:
push   %rax
mov    0x2f19(%rip),%ecx
shl    %cl,%edi
or     0x2f0d(%rip),%edi
mov    %edi,0x2f07(%rip)
add    %ecx,%esi
mov    %esi,0x2f03(%rip)
cmp    $0x8,%esi
jl     116c <pack_output+0x5c>
mov    %dil,0x7(%rsp)
add    $0xfffffff8,%esi
mov    %esi,0x2ef0(%rip)
shr    $0x8,%edi
mov    %edi,0x2ee3(%rip)
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    0x2ec4(%rip),%esi
xor    %eax,%eax
test   %esi,%esi
setg   %al
pop    %rcx
ret

LLVM IR (-O0):
@pack_output.out_buffer = internal global i32 0
@pack_output.out_bits = internal global i32 0
@stdout = global i32 0
define i32 @pack_output(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @pack_output.out_bits
%8 = shl i32 %6, %7
%9 = load i32, i32* @pack_output.out_buffer
%10 = or i32 %9, %8
store i32 %10, i32* @pack_output.out_buffer
%11 = load i32, i32* %4
%12 = load i32, i32* @pack_output.out_bits
%13 = add nsw i32 %12, %11
store i32 %13, i32* @pack_output.out_bits
%14 = load i32, i32* @pack_output.out_bits
%15 = icmp sge i32 %14, 8
br i1 %15, label %16, label %26
16: ; preds = %2
%17 = load i32, i32* @pack_output.out_buffer
%18 = and i32 %17, 255
%19 = trunc i32 %18 to i8
store i8 %19, i8* %5
%20 = load i32, i32* @pack_output.out_bits
%21 = sub nsw i32 %20, 8
store i32 %21, i32* @pack_output.out_bits
%22 = load i32, i32* @pack_output.out_buffer
%23 = lshr i32 %22, 8
store i32 %23, i32* @pack_output.out_buffer
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %5, i32 1, i32 1, i32 %24)
br label %26
26: ; preds = %16, %2
%27 = load i32, i32* @pack_output.out_bits
%28 = icmp sgt i32 %27, 0
%29 = zext i1 %28 to i32
ret i32 %29
}

LLVM IR (-O2):
@pack_output.out_buffer = internal unnamed_addr global i32 0
@pack_output.out_bits = internal unnamed_addr global i32 0
@stdout = global i32 0
define i32 @pack_output(i32 %0, i32 %1) {
%3 = alloca i8
%4 = load i32, i32* @pack_output.out_bits
%5 = shl i32 %0, %4
%6 = load i32, i32* @pack_output.out_buffer
%7 = or i32 %6, %5
store i32 %7, i32* @pack_output.out_buffer
%8 = add nsw i32 %4, %1
store i32 %8, i32* @pack_output.out_bits
%9 = icmp sgt i32 %8, 7
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = trunc i32 %7 to i8
store i8 %11, i8* %3
%12 = add nsw i32 %8, -8
store i32 %12, i32* @pack_output.out_bits
%13 = lshr i32 %7, 8
store i32 %13, i32* @pack_output.out_buffer
%14 = load i32, i32* @stdout
%15 = call i32 @fwrite(i8* %3, i32 1, i32 1, i32 %14)
%16 = load i32, i32* @pack_output.out_bits
br label %17
17: ; preds = %10, %2
%18 = phi i32 [ %16, %10 ], [ %8, %2 ]
%19 = icmp sgt i32 %18, 0
%20 = zext i1 %19 to i32
ret i32 %20
}