#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*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
void write4bits(FILE *outfile, int byte) {
  static unsigned char buf;
  static int inbuf;
  byte &= 0xf;
  if (inbuf) {
    buf = (((unsigned char)byte) | buf << 4);
    fwrite(&buf, sizeof(unsigned char), 1, outfile);
    inbuf = 0;
  } else {
    buf = (unsigned char)byte;
    inbuf = 1;
  }
}


x86 assembly (clang, -O0):
<write4bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,0x2f01(%rip)
je     1173 <write4bits+0x63>
mov    -0xc(%rbp),%eax
movzbl %al,%eax
movzbl 0x2eea(%rip),%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    %al,0x2edf(%rip)
mov    -0x8(%rbp),%rcx
lea    0x2ed4(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fwrite@plt>
movl   $0x0,0x2ec2(%rip)
jmp    1186 <write4bits+0x76>
mov    -0xc(%rbp),%eax
mov    %al,0x2eb0(%rip)
movl   $0x1,0x2eaa(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write4bits>:
push   %rbx
and    $0xf,%esi
mov    0x2f16(%rip),%bl
cmp    $0x1,%bl
jne    1141 <write4bits+0x31>
mov    %rdi,%rax
movzbl 0x2f03(%rip),%ecx
shl    $0x4,%ecx
or     %esi,%ecx
mov    %cl,0x2ef8(%rip)
movsbl %cl,%edi
mov    %rax,%rsi
call   1030 <fputc@plt>
jmp    1148 <write4bits+0x38>
mov    %sil,0x2ee4(%rip)
xor    $0x1,%bl
mov    %bl,0x2edf(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@write4bits.buf = internal global i8 0
@write4bits.inbuf = internal global i32 0
define void @write4bits(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = and i32 %5, 15
store i32 %6, i32* %4
%7 = load i32, i32* @write4bits.inbuf
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = load i32, i32* %4
%11 = trunc i32 %10 to i8
%12 = zext i8 %11 to i32
%13 = load i8, i8* @write4bits.buf
%14 = zext i8 %13 to i32
%15 = shl i32 %14, 4
%16 = or i32 %12, %15
%17 = trunc i32 %16 to i8
store i8 %17, i8* @write4bits.buf
%18 = load i32*, i32** %3
%19 = call i32 @fwrite(i8* @write4bits.buf, i32 1, i32 1, i32* %18)
store i32 0, i32* @write4bits.inbuf
br label %23
20: ; preds = %2
%21 = load i32, i32* %4
%22 = trunc i32 %21 to i8
store i8 %22, i8* @write4bits.buf
store i32 1, i32* @write4bits.inbuf
br label %23
23: ; preds = %20, %9
ret void
}

LLVM IR (-O2):
@write4bits.buf = internal unnamed_addr global i8 0
@write4bits.inbuf = internal unnamed_addr global i1 false
define void @write4bits(i32* nocapture %0, i32 %1) {
%3 = and i32 %1, 15
%4 = load i1, i1* @write4bits.inbuf
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = load i8, i8* @write4bits.buf
%7 = zext i8 %6 to i32
%8 = shl nuw nsw i32 %7, 4
%9 = or i32 %8, %3
%10 = trunc i32 %9 to i8
store i8 %10, i8* @write4bits.buf
%11 = shl i32 %9, 24
%12 = ashr exact i32 %11, 24
%13 = tail call i32 @fputc(i32 %12, i32* %0)
br label %16
14: ; preds = %2
%15 = trunc i32 %3 to i8
store i8 %15, i8* @write4bits.buf
br label %16
16: ; preds = %14, %5
%17 = xor i1 %4, true
store i1 %17, i1* @write4bits.inbuf
ret void
}