#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*/ buildrevtab(unsigned char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *f;
  unsigned char pair[2];
  int got;
  unsigned char revtab[256];
  int col = 0;
  if (argc != 2) {
    fprintf(stderr,
            "USAGE: %s IMAGE.mono\n"
            "IMAGE.mono may be created via ImageMagick convert.\n"
            "Image must be of the appropriate size.",
            argv[0]);
    exit(1);
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    perror("Couldn't open file");
    exit(1);
  }
  printf("unsigned char fb[H_PIXELS*V_DISPLINES/8] = {\n");
  buildrevtab(revtab);
  while (1) {
    got = fread(pair, 1, 2, f);
    if (got != 2)
      break;
    printf("0x%02x,0x%02x,", revtab[pair[1]], revtab[pair[0]]);
    if (col == 5) {
      col = 0;
      printf("\n");
    } else {
      col++;
    }
  }
  if (col != 0)
    printf("\n");
  printf("};\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x124(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c3 <main+0x53>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fc <main+0x8c>
lea    0xe85(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
call   1080 <buildrevtab@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
je     123f <main+0xcf>
jmp    12a3 <main+0x133>
movzbl -0x19(%rbp),%eax
movzbl -0x120(%rbp,%rax,1),%esi
ff
movzbl -0x1a(%rbp),%eax
movzbl -0x120(%rbp,%rax,1),%edx
ff
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x5,-0x124(%rbp)
jne    128f <main+0x11f>
movl   $0x0,-0x124(%rbp)
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129e <main+0x12e>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1216 <main+0xa6>
cmpl   $0x0,-0x124(%rbp)
je     12be <main+0x14e>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
cmp    $0x2,%edi
jne    1288 <main+0xf8>
mov    0x8(%rsi),%rdi
lea    0xebe(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12aa <main+0x11a>
mov    %rax,%rbx
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   10a0 <buildrevtab@plt>
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x2,%eax
jne    126c <main+0xdc>
lea    0xe8a(%rip),%r14
lea    0xe(%rsp),%r15
xor    %ebp,%ebp
jmp    122d <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x2,%eax
jne    125e <main+0xce>
movzbl 0xf(%rsp),%eax
movzbl 0x10(%rsp,%rax,1),%esi
movzbl 0xe(%rsp),%eax
movzbl 0x10(%rsp,%rax,1),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x5,%ebp
jne    1210 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1213 <main+0x83>
test   %ebp,%ebp
je     126c <main+0xdc>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd65(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdc1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [111 x i8] c"USAGE: %s IMAGE.mono\0AIMAGE.mono may be created via ImageMagick convert.\0AImage must be of the appropriate size.\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"Couldn't open file\00"
@.str.3 = [46 x i8] c"unsigned char fb[H_PIXELS*V_DISPLINES/8] = {\0A\00"
@.str.4 = [15 x i8] c"0x%02x,0x%02x,\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [2 x i8]
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%33 = call i32 @buildrevtab(i8* %32)
br label %34
34: ; preds = %30, %62
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%36 = load i32*, i32** %6
%37 = call i32 @fread(i8* %35, i32 1, i32 2, i32* %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 2
br i1 %39, label %40, label %41
40: ; preds = %34
br label %63
41: ; preds = %34
%42 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%43 = load i8, i8* %42
%44 = zext i8 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%49 = load i8, i8* %48
%50 = zext i8 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %53)
%55 = load i32, i32* %10
%56 = icmp eq i32 %55, 5
br i1 %56, label %57, label %59
57: ; preds = %41
store i32 0, i32* %10
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %62
59: ; preds = %41
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %62
62: ; preds = %59, %57
br label %34
63: ; preds = %40
%64 = load i32, i32* %10
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [111 x i8] c"USAGE: %s IMAGE.mono\0AIMAGE.mono may be created via ImageMagick convert.\0AImage must be of the appropriate size.\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"Couldn't open file\00"
@.str.4 = [15 x i8] c"0x%02x,0x%02x,\00"
@str = [45 x i8] c"unsigned char fb[H_PIXELS*V_DISPLINES/8] = {\00"
@str.7 = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%23 = call i32 @buildrevtab(i8* %6)
%24 = call i32 @fread(i8* %5, i32 1, i32 2, i32* %16)
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %54
26: ; preds = %21
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %28
28: ; preds = %26, %46
%29 = phi i32 [ 0, %26 ], [ %47, %46 ]
%30 = load i8, i8* %27
%31 = zext i8 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = load i8, i8* %5
%36 = zext i8 %35 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %39)
%41 = icmp eq i32 %29, 5
br i1 %41, label %42, label %44
42: ; preds = %28
%43 = call i32 @putchar(i32 10)
br label %46
44: ; preds = %28
%45 = add nsw i32 %29, 1
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ 0, %42 ], [ %45, %44 ]
%48 = call i32 @fread(i8* %5, i32 1, i32 2, i32* %16)
%49 = icmp eq i32 %48, 2
br i1 %49, label %28, label %50
50: ; preds = %46
%51 = icmp eq i32 %47, 0
br i1 %51, label %54, label %52
52: ; preds = %50
%53 = call i32 @putchar(i32 10)
br label %54
54: ; preds = %21, %52, %50
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}