#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 fprintf(int /*<<< orphan*/ *, char *, int);
void writeLetter(FILE *file, unsigned char letter, int *pos, int *byte) {
  int j;
  for (j = 0; j < 8; j++, letter <<= 1) {
    (*byte) <<= 1, (*pos)++;
    (*byte) |= (letter & 0x80) != 0;
    (*byte) = (*pos) == 8 ? (*pos) = fprintf(file, "%c", (*byte)) - 1 : (*byte);
  }
}


x86 assembly (clang, -O0):
<writeLetter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    11cb <writeLetter+0xbb>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movzbl -0x9(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x20(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x8,(%rax)
jne    11a1 <writeLetter+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe75(%rip),%rsi
call   1030 <fprintf@plt>
sub    $0x1,%eax
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x28(%rbp)
jmp    11aa <writeLetter+0x9a>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movzbl -0x9(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x9(%rbp)
jmp    1131 <writeLetter+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeLetter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    (%rcx),%eax
mov    $0x8,%ebx
lea    0xecc(%rip),%r12
jmp    114c <writeLetter+0x3c>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,0x0(%r13)
add    %bpl,%bpl
add    $0xffffffff,%ebx
je     1181 <writeLetter+0x71>
add    %eax,%eax
mov    %eax,0x0(%r13)
addl   $0x1,(%r14)
mov    %ebp,%eax
shr    $0x7,%al
movzbl %al,%eax
or     0x0(%r13),%eax
mov    %eax,0x0(%r13)
cmpl   $0x8,(%r14)
jne    1140 <writeLetter+0x30>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
add    $0xffffffff,%eax
mov    %eax,(%r14)
jmp    1140 <writeLetter+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @writeLetter(i32* %0, i8 zeroext %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i8 %1, i8* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
br label %10
10: ; preds = %44, %4
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %51
13: ; preds = %10
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = shl i32 %15, 1
store i32 %16, i32* %14
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = load i8, i8* %6
%21 = zext i8 %20 to i32
%22 = and i32 %21, 128
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
%25 = load i32*, i32** %8
%26 = load i32, i32* %25
%27 = or i32 %26, %24
store i32 %27, i32* %25
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 8
br i1 %30, label %31, label %38
31: ; preds = %13
%32 = load i32*, i32** %5
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = sub nsw i32 %35, 1
%37 = load i32*, i32** %7
store i32 %36, i32* %37
br label %41
38: ; preds = %13
%39 = load i32*, i32** %8
%40 = load i32, i32* %39
br label %41
41: ; preds = %38, %31
%42 = phi i32 [ %36, %31 ], [ %40, %38 ]
%43 = load i32*, i32** %8
store i32 %42, i32* %43
br label %44
44: ; preds = %41
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
%47 = load i8, i8* %6
%48 = zext i8 %47 to i32
%49 = shl i32 %48, 1
%50 = trunc i32 %49 to i8
store i8 %50, i8* %6
br label %10
51: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @writeLetter(i32* nocapture %0, i8 zeroext %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %3
br label %6
6: ; preds = %4, %22
%7 = phi i32 [ %5, %4 ], [ %23, %22 ]
%8 = phi i32 [ 0, %4 ], [ %24, %22 ]
%9 = phi i8 [ %1, %4 ], [ %25, %22 ]
%10 = shl i32 %7, 1
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
store i32 %12, i32* %2
%13 = lshr i8 %9, 7
%14 = zext i8 %13 to i32
%15 = load i32, i32* %3
%16 = or i32 %15, %14
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %22
19: ; preds = %6
%20 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%21 = add nsw i32 %20, -1
store i32 %21, i32* %2
br label %22
22: ; preds = %6, %19
%23 = phi i32 [ %21, %19 ], [ %16, %6 ]
store i32 %23, i32* %3
%24 = add nuw nsw i32 %8, 1
%25 = shl i8 %9, 1
%26 = icmp eq i32 %24, 8
br i1 %26, label %27, label %6
27: ; preds = %22
ret void
}