#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *, ...);
void dump_font(const char *filename, const char *name) {
  int c;
  FILE *f;
  int j;
  f = fopen(filename, "r");
  if (!f) {
    perror(filename);
    exit(1);
  }
  printf("static const unsigned char font_%s[] = {\n", name);
  j = 0;
  for (;;) {
    c = fgetc(f);
    if (c == EOF)
      break;
    j++;
    printf("0x%02x,", c);
    if ((j & 7) == 0)
      printf("\n");
    else
      printf(" ");
  }
  if ((j & 7) != 0)
    printf("\n");
  printf("};\n\n");
  fclose(f);
}


x86 assembly (clang, -O0):
<dump_font>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <dump_font+0x42>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%eax
jne    11de <dump_font+0x7e>
jmp    122d <dump_font+0xcd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    121a <dump_font+0xba>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1228 <dump_font+0xc8>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11bb <dump_font+0x5b>
mov    -0x24(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
je     124a <dump_font+0xea>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_font>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     123a <dump_font+0xba>
mov    %rax,%rbx
lea    0xe55(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    0x2e22(%rip),%r15
cmp    (%r15),%eax
je     121e <dump_font+0x9e>
lea    0xe5a(%rip),%r14
mov    $0xa,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x7,%bpl
mov    $0x20,%edi
cmove  %r12d,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r15),%eax
jne    11e0 <dump_font+0x60>
test   $0x7,%bpl
je     121e <dump_font+0x9e>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe0f(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
mov    %r15,%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [42 x i8] c"static const unsigned char font_%s[] = {\0A\00"
@EOF = global i32 0
@.str.2 = [8 x i8] c"0x%02x,\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [5 x i8] c"};\0A\0A\00"
define void @dump_font(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @perror(i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 0, i32* %7
br label %19
19: ; preds = %38, %16
%20 = load i32*, i32** %6
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %19
br label %39
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = and i32 %31, 7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
br label %19
39: ; preds = %25
%40 = load i32, i32* %7
%41 = and i32 %40, 7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [42 x i8] c"static const unsigned char font_%s[] = {\0A\00"
@EOF = global i32 0
@.str.2 = [8 x i8] c"0x%02x,\00"
@str = [4 x i8] c"};\0A\00"
define void @dump_font(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = tail call i32 @fgetc(i32* %3)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %30, label %13
13: ; preds = %8, %13
%14 = phi i32 [ %22, %13 ], [ %10, %8 ]
%15 = phi i32 [ %16, %13 ], [ 0, %8 ]
%16 = add nuw nsw i32 %15, 1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%18 = and i32 %16, 7
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i32 10, i32 32
%21 = tail call i32 @putchar(i32 %20)
%22 = tail call i32 @fgetc(i32* %3)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %13
25: ; preds = %13
%26 = and i32 %16, 7
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 @putchar(i32 10)
br label %30
30: ; preds = %8, %28, %25
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%32 = tail call i32 @fclose(i32* %3)
ret void
}