#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*/ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp = fopen("bin/DMG_ROM.bin", "rb");
  FILE *out = fopen("bin/DMG_ROM.mif", "w");
  unsigned char c = fgetc(fp);
  int i;
  while (!feof(fp)) {
    for (i = 7; i >= 0; i--) {
      fputc((c >> i) & 0x1 ? '1' : '0', out);
    }
    fputc('\n', out);
    c = fgetc(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe9f(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ae <main+0x6e>
jmp    1214 <main+0xd4>
movl   $0x7,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     11f5 <main+0xb5>
movzbl -0x21(%rbp),%edx
mov    -0x28(%rbp),%ecx
sar    %cl,%edx
and    $0x1,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11b5 <main+0x75>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0xed4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xec8(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    12c0 <main+0x180>
mov    %r14,0x10(%rsp)
nopl   0x0(%rax)
movzbl %bl,%eax
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,%xmm1
pand   0xe48(%rip),%xmm1
pand   0xe50(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebp
mov    %ebp,%eax
and    $0x2,%al
shr    %al
mov    %al,0xf(%rsp)
mov    %ebp,%eax
and    $0x4,%al
shr    $0x2,%al
mov    %al,0xe(%rsp)
mov    %ebp,%ebx
and    $0x8,%bl
shr    $0x3,%bl
mov    %ebp,%r14d
and    $0x10,%r14b
shr    $0x4,%r14b
mov    %ebp,%r15d
and    $0x20,%r15b
shr    $0x5,%r15b
mov    %ebp,%r12d
and    $0x40,%r12b
shr    $0x6,%r12b
mov    %ebp,%eax
shr    $0x7,%al
movzbl %al,%edi
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
movzbl %r12b,%edi
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
movzbl %r15b,%edi
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
movzbl %r14b,%edi
mov    0x10(%rsp),%r14
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
movzbl %bl,%edi
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
movzbl 0xe(%rsp),%edi
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
movzbl 0xf(%rsp),%edi
xor    $0x31,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
and    $0x1,%ebp
xor    $0x31,%ebp
mov    %ebp,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11a0 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"bin/DMG_ROM.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"bin/DMG_ROM.mif\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %6
%13 = call zeroext i8 @fgetc(i32* %12)
store i8 %13, i8* %8
br label %14
14: ; preds = %38, %2
%15 = load i32*, i32** %6
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %43
19: ; preds = %14
store i32 7, i32* %9
br label %20
20: ; preds = %35, %19
%21 = load i32, i32* %9
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i8, i8* %8
%25 = zext i8 %24 to i32
%26 = load i32, i32* %9
%27 = ashr i32 %25, %26
%28 = and i32 %27, 1
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 49, i32 48
%32 = trunc i32 %31 to i8
%33 = load i32*, i32** %7
%34 = call i32 @fputc(i8 signext %32, i32* %33)
br label %35
35: ; preds = %23
%36 = load i32, i32* %9
%37 = add nsw i32 %36, -1
store i32 %37, i32* %9
br label %20
38: ; preds = %20
%39 = load i32*, i32** %7
%40 = call i32 @fputc(i8 signext 10, i32* %39)
%41 = load i32*, i32** %6
%42 = call zeroext i8 @fgetc(i32* %41)
store i8 %42, i8* %8
br label %14
43: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"bin/DMG_ROM.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"bin/DMG_ROM.mif\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call zeroext i8 @fgetc(i32* %3)
%6 = tail call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %43
8: ; preds = %2, %8
%9 = phi i8 [ %40, %8 ], [ %5, %2 ]
%10 = zext i8 %9 to i32
%11 = insertelement <8 x i32> poison, i32 %10, i64 0
%12 = shufflevector <8 x i32> %11, <8 x i32> poison, <8 x i32> zeroinitializer
%13 = and <8 x i32> %12, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%14 = icmp eq <8 x i32> %13, zeroinitializer
%15 = extractelement <8 x i1> %14, i64 7
%16 = select i1 %15, i8 48, i8 49
%17 = tail call i32 @fputc(i8 signext %16, i32* %4)
%18 = extractelement <8 x i1> %14, i64 6
%19 = select i1 %18, i8 48, i8 49
%20 = tail call i32 @fputc(i8 signext %19, i32* %4)
%21 = extractelement <8 x i1> %14, i64 5
%22 = select i1 %21, i8 48, i8 49
%23 = tail call i32 @fputc(i8 signext %22, i32* %4)
%24 = extractelement <8 x i1> %14, i64 4
%25 = select i1 %24, i8 48, i8 49
%26 = tail call i32 @fputc(i8 signext %25, i32* %4)
%27 = extractelement <8 x i1> %14, i64 3
%28 = select i1 %27, i8 48, i8 49
%29 = tail call i32 @fputc(i8 signext %28, i32* %4)
%30 = extractelement <8 x i1> %14, i64 2
%31 = select i1 %30, i8 48, i8 49
%32 = tail call i32 @fputc(i8 signext %31, i32* %4)
%33 = extractelement <8 x i1> %14, i64 1
%34 = select i1 %33, i8 48, i8 49
%35 = tail call i32 @fputc(i8 signext %34, i32* %4)
%36 = extractelement <8 x i1> %14, i64 0
%37 = select i1 %36, i8 48, i8 49
%38 = tail call i32 @fputc(i8 signext %37, i32* %4)
%39 = tail call i32 @fputc(i8 signext 10, i32* %4)
%40 = tail call zeroext i8 @fgetc(i32* %3)
%41 = tail call i32 @feof(i32* %3)
%42 = icmp eq i32 %41, 0
br i1 %42, label %8, label %43
43: ; preds = %8, %2
ret i32 0
}