#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
long atol(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fonttable(size_t, size_t, size_t, size_t, size_t, size_t,
                             unsigned char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
size_t getcharheight(size_t, size_t, size_t, unsigned char *);
size_t getyoff(size_t, size_t, unsigned char *);
unsigned char *malloc(size_t);
int nrcolor(size_t, unsigned char *);
int /*<<< orphan*/ stderr;
int main(const int argc, const char *argv[]) {
  FILE *file;
  unsigned char *data;
  if (argc < 8) {
    fprintf(
        stderr,
        "Usage: %s <file.gray> width height xoff yoff charwidth charheight\n",
        argv[0]);
    return 1;
  }
  long width = atol(argv[2]);
  long height = atol(argv[3]);
  long xoff = atol(argv[4]);
  long yoff = atol(argv[5]);
  long charwidth = atol(argv[6]);
  long charheight = atol(argv[7]);
  if (width <= 0 || height <= 0 || xoff < 0 || yoff < 0 || charwidth <= 0 ||
      charheight <= 0) {
    fprintf(stderr, "%s: Error: Parameter <= 0\n", argv[0]);
    return 1;
  }
  if (charwidth > 32) {
    fprintf(stderr, "%s: Error: charwidth > 32\n", argv[0]);
    return 1;
  }
  file = fopen(argv[1], "r+");
  if (!file)
    goto ONERR;
  if (fseek(file, 0, SEEK_END) != 0)
    goto ONERR;
  size_t file_size = (size_t)ftell(file);
  if (file_size != width * height) {
    fprintf(stderr, "%s: Error: file_size != %ld\n", argv[0], width * height);
    return 1;
  }
  if (fseek(file, 0, SEEK_SET) != 0)
    goto ONERR;
  data = malloc((size_t)file_size);
  if (!data) {
    fprintf(stderr, "%s: Error: Out of memory\n", argv[0]);
    return 1;
  }
  if (fread(data, 1, file_size, file) != file_size)
    goto ONERR;
  if (nrcolor(file_size, data) != 2) {
    fprintf(stderr, "%s: Error: Picture not black and white\n", argv[0]);
    return 1;
  }
  size_t yoff2 = getyoff((size_t)width, (size_t)height, data);
  size_t charheight2 =
      getcharheight((size_t)width, (size_t)height, yoff2, data) + yoff2 -
      (size_t)yoff;
  if (charheight2 != (size_t)charheight) {
    fprintf(stderr, "%s: Error: charheight != %ld (yoff2:%ld)\n", argv[0],
            (long)charheight2, (long)yoff2);
    return 1;
  }
  fonttable((size_t)width, (size_t)height, (size_t)xoff, (size_t)yoff,
            (size_t)charwidth, (size_t)charheight, data);
  fclose(file);
  return 0;
ONERR:
  if (file) {
    fprintf(stderr, "Read error in file '%s'\n", argv[1]);
    fclose(file);
  } else {
    fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    120a <main+0x4a>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rdi
call   10d0 <atol@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    12b2 <main+0xf2>
cmpq   $0x0,-0x30(%rbp)
jle    12b2 <main+0xf2>
cmpq   $0x0,-0x38(%rbp)
jl     12b2 <main+0xf2>
cmpq   $0x0,-0x40(%rbp)
jl     12b2 <main+0xf2>
cmpq   $0x0,-0x48(%rbp)
jle    12b2 <main+0xf2>
cmpq   $0x0,-0x50(%rbp)
jg     12dc <main+0x11c>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
cmpq   $0x20,-0x48(%rbp)
jle    1311 <main+0x151>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd59(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1339 <main+0x179>
jmp    152c <main+0x36c>
mov    -0x18(%rbp),%rdi
mov    0x2ca4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     135c <main+0x19c>
jmp    152c <main+0x36c>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
imul   -0x30(%rbp),%rcx
cmp    %rcx,%rax
je     13b2 <main+0x1f2>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
imul   -0x30(%rbp),%rcx
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
mov    -0x18(%rbp),%rdi
mov    0x2c13(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     13d5 <main+0x215>
jmp    152c <main+0x36c>
mov    -0x58(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1417 <main+0x257>
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc95(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
mov    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x58(%rbp),%rax
je     143c <main+0x27c>
jmp    152c <main+0x36c>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <nrcolor@plt>
cmp    $0x2,%eax
je     147c <main+0x2bc>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc4a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   10b0 <getyoff@plt>
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <getcharheight@plt>
add    -0x60(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
cmp    -0x50(%rbp),%rax
je     14f2 <main+0x332>
mov    0x2b11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x68(%rbp),%rcx
mov    -0x60(%rbp),%r8
lea    0xbfc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    158a <main+0x3ca>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%r9
mov    -0x20(%rbp),%rax
mov    %rax,(%rsp)
call   10c0 <fonttable@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    158a <main+0x3ca>
cmpq   $0x0,-0x18(%rbp)
je     1564 <main+0x3a4>
mov    0x2a9a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xbb6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1583 <main+0x3c3>
mov    0x2a6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xba2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x7,%edi
jg     11ee <main+0x2e>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe17(%rip),%rsi
jmp    127f <main+0xbf>
mov    0x10(%rbx),%rdi
call   10d0 <atol@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   10d0 <atol@plt>
mov    %rax,%r15
mov    0x20(%rbx),%rdi
call   10d0 <atol@plt>
mov    %rax,%r12
mov    0x28(%rbx),%rdi
call   10d0 <atol@plt>
mov    %rax,%r13
mov    0x30(%rbx),%rdi
call   10d0 <atol@plt>
mov    %rax,%rbp
mov    0x38(%rbx),%rdi
call   10d0 <atol@plt>
test   %r14,%r14
jle    126c <main+0xac>
test   %r15,%r15
jle    126c <main+0xac>
test   %r12,%r12
js     126c <main+0xac>
test   %r13,%r13
js     126c <main+0xac>
test   %rbp,%rbp
jle    126c <main+0xac>
test   %rax,%rax
jle    126c <main+0xac>
cmp    $0x21,%rbp
jb     129a <main+0xda>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf4(%rip),%rsi
jmp    127f <main+0xbf>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,0x20(%rsp)
mov    0x8(%rbx),%rdi
lea    0xdcf(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     12f8 <main+0x138>
mov    0x2d2d(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
mov    %rax,0x10(%rsp)
xor    %esi,%esi
call   10a0 <fseek@plt>
test   %rax,%rax
je     1311 <main+0x151>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe20(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
jmp    1286 <main+0xc6>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe12(%rip),%rsi
jmp    127f <main+0xbf>
mov    0x10(%rsp),%rdi
call   1080 <ftell@plt>
mov    %r15,%rcx
imul   %r14,%rcx
cmp    %rcx,%rax
jne    140a <main+0x24a>
mov    %rax,0x8(%rsp)
mov    0x2c99(%rip),%rax
mov    (%rax),%edx
mov    0x10(%rsp),%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
test   %rax,%rax
jne    12d1 <main+0x111>
mov    0x8(%rsp),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     1429 <main+0x269>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
call   1040 <fread@plt>
cmp    0x8(%rsp),%rax
jne    12d1 <main+0x111>
mov    0x8(%rsp),%rdi
mov    0x18(%rsp),%rsi
call   1030 <nrcolor@plt>
cmp    $0x2,%eax
jne    1441 <main+0x281>
mov    %r14,%rdi
mov    %r15,%rsi
mov    0x18(%rsp),%rdx
call   10b0 <getyoff@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    0x18(%rsp),%rcx
call   1060 <getcharheight@plt>
mov    0x8(%rsp),%r8
mov    %r8,%rcx
sub    %r13,%rcx
add    %rax,%rcx
mov    0x20(%rsp),%r9
cmp    %r9,%rcx
jne    1459 <main+0x299>
mov    0x18(%rsp),%rax
mov    %rax,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   10c0 <fonttable@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    128b <main+0xcb>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc5f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1286 <main+0xc6>
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc5d(%rip),%rsi
jmp    127f <main+0xbf>
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc5f(%rip),%rsi
jmp    127f <main+0xbf>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc6f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1286 <main+0xc6>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [67 x i8] c"Usage: %s <file.gray> width height xoff yoff charwidth charheight\0A\00"
@.str.1 = [27 x i8] c"%s: Error: Parameter <= 0\0A\00"
@.str.2 = [27 x i8] c"%s: Error: charwidth > 32\0A\00"
@.str.3 = [3 x i8] c"r+\00"
@SEEK_END = global i32 0
@.str.4 = [29 x i8] c"%s: Error: file_size != %ld\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [26 x i8] c"%s: Error: Out of memory\0A\00"
@.str.6 = [40 x i8] c"%s: Error: Picture not black and white\0A\00"
@.str.7 = [42 x i8] c"%s: Error: charheight != %ld (yoff2:%ld)\0A\00"
@.str.8 = [25 x i8] c"Read error in file '%s'\0A\00"
@.str.9 = [23 x i8] c"Cannot open file '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
br label %203
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @atol(i8* %28)
store i64 %29, i64* %8
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i64 @atol(i8* %32)
store i64 %33, i64* %9
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = call i64 @atol(i8* %36)
store i64 %37, i64* %10
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 5
%40 = load i8*, i8** %39
%41 = call i64 @atol(i8* %40)
store i64 %41, i64* %11
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 6
%44 = load i8*, i8** %43
%45 = call i64 @atol(i8* %44)
store i64 %45, i64* %12
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 7
%48 = load i8*, i8** %47
%49 = call i64 @atol(i8* %48)
store i64 %49, i64* %13
%50 = load i64, i64* %8
%51 = icmp sle i64 %50, 0
br i1 %51, label %67, label %52
52: ; preds = %25
%53 = load i64, i64* %9
%54 = icmp sle i64 %53, 0
br i1 %54, label %67, label %55
55: ; preds = %52
%56 = load i64, i64* %10
%57 = icmp slt i64 %56, 0
br i1 %57, label %67, label %58
58: ; preds = %55
%59 = load i64, i64* %11
%60 = icmp slt i64 %59, 0
br i1 %60, label %67, label %61
61: ; preds = %58
%62 = load i64, i64* %12
%63 = icmp sle i64 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = load i64, i64* %13
%66 = icmp sle i64 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %64, %61, %58, %55, %52, %25
%68 = load i32, i32* @stderr
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %71)
store i32 1, i32* %3
br label %203
73: ; preds = %64
%74 = load i64, i64* %12
%75 = icmp sgt i64 %74, 32
br i1 %75, label %76, label %82
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 0
%80 = load i8*, i8** %79
%81 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %80)
store i32 1, i32* %3
br label %203
82: ; preds = %73
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = call i32* @fopen(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %86, i32** %6
%87 = load i32*, i32** %6
%88 = icmp ne i32* %87, null
br i1 %88, label %90, label %89
89: ; preds = %82
br label %185
90: ; preds = %82
%91 = load i32*, i32** %6
%92 = load i32, i32* @SEEK_END
%93 = call i64 @fseek(i32* %91, i32 0, i32 %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %96
95: ; preds = %90
br label %185
96: ; preds = %90
%97 = load i32*, i32** %6
%98 = call i64 @ftell(i32* %97)
store i64 %98, i64* %14
%99 = load i64, i64* %14
%100 = load i64, i64* %8
%101 = load i64, i64* %9
%102 = mul nsw i64 %100, %101
%103 = icmp ne i64 %99, %102
br i1 %103, label %104, label %113
104: ; preds = %96
%105 = load i32, i32* @stderr
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 0
%108 = load i8*, i8** %107
%109 = load i64, i64* %8
%110 = load i64, i64* %9
%111 = mul nsw i64 %109, %110
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %108, i64 %111)
store i32 1, i32* %3
br label %203
113: ; preds = %96
%114 = load i32*, i32** %6
%115 = load i32, i32* @SEEK_SET
%116 = call i64 @fseek(i32* %114, i32 0, i32 %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %113
br label %185
119: ; preds = %113
%120 = load i64, i64* %14
%121 = call i8* @malloc(i64 %120)
store i8* %121, i8** %7
%122 = load i8*, i8** %7
%123 = icmp ne i8* %122, null
br i1 %123, label %130, label %124
124: ; preds = %119
%125 = load i32, i32* @stderr
%126 = load i8**, i8*** %5
%127 = getelementptr inbounds i8*, i8** %126, i64 0
%128 = load i8*, i8** %127
%129 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %128)
store i32 1, i32* %3
br label %203
130: ; preds = %119
%131 = load i8*, i8** %7
%132 = load i64, i64* %14
%133 = load i32*, i32** %6
%134 = call i64 @fread(i8* %131, i32 1, i64 %132, i32* %133)
%135 = load i64, i64* %14
%136 = icmp ne i64 %134, %135
br i1 %136, label %137, label %138
137: ; preds = %130
br label %185
138: ; preds = %130
%139 = load i64, i64* %14
%140 = load i8*, i8** %7
%141 = call i32 @nrcolor(i64 %139, i8* %140)
%142 = icmp ne i32 %141, 2
br i1 %142, label %143, label %149
143: ; preds = %138
%144 = load i32, i32* @stderr
%145 = load i8**, i8*** %5
%146 = getelementptr inbounds i8*, i8** %145, i64 0
%147 = load i8*, i8** %146
%148 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %147)
store i32 1, i32* %3
br label %203
149: ; preds = %138
%150 = load i64, i64* %8
%151 = load i64, i64* %9
%152 = load i8*, i8** %7
%153 = call i64 @getyoff(i64 %150, i64 %151, i8* %152)
store i64 %153, i64* %15
%154 = load i64, i64* %8
%155 = load i64, i64* %9
%156 = load i64, i64* %15
%157 = load i8*, i8** %7
%158 = call i64 @getcharheight(i64 %154, i64 %155, i64 %156, i8* %157)
%159 = load i64, i64* %15
%160 = add i64 %158, %159
%161 = load i64, i64* %11
%162 = sub i64 %160, %161
store i64 %162, i64* %16
%163 = load i64, i64* %16
%164 = load i64, i64* %13
%165 = icmp ne i64 %163, %164
br i1 %165, label %166, label %174
166: ; preds = %149
%167 = load i32, i32* @stderr
%168 = load i8**, i8*** %5
%169 = getelementptr inbounds i8*, i8** %168, i64 0
%170 = load i8*, i8** %169
%171 = load i64, i64* %16
%172 = load i64, i64* %15
%173 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %170, i64 %171, i64 %172)
store i32 1, i32* %3
br label %203
174: ; preds = %149
%175 = load i64, i64* %8
%176 = load i64, i64* %9
%177 = load i64, i64* %10
%178 = load i64, i64* %11
%179 = load i64, i64* %12
%180 = load i64, i64* %13
%181 = load i8*, i8** %7
%182 = call i32 @fonttable(i64 %175, i64 %176, i64 %177, i64 %178, i64 %179, i64 %180, i8* %181)
%183 = load i32*, i32** %6
%184 = call i32 @fclose(i32* %183)
store i32 0, i32* %3
br label %203
185: ; preds = %137, %118, %95, %89
%186 = load i32*, i32** %6
%187 = icmp ne i32* %186, null
br i1 %187, label %188, label %196
188: ; preds = %185
%189 = load i32, i32* @stderr
%190 = load i8**, i8*** %5
%191 = getelementptr inbounds i8*, i8** %190, i64 1
%192 = load i8*, i8** %191
%193 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %189, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %192)
%194 = load i32*, i32** %6
%195 = call i32 @fclose(i32* %194)
br label %202
196: ; preds = %185
%197 = load i32, i32* @stderr
%198 = load i8**, i8*** %5
%199 = getelementptr inbounds i8*, i8** %198, i64 1
%200 = load i8*, i8** %199
%201 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %197, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %200)
br label %202
202: ; preds = %196, %188
store i32 1, i32* %3
br label %203
203: ; preds = %202, %174, %166, %143, %124, %104, %76, %67, %19
%204 = load i32, i32* %3
ret i32 %204
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [67 x i8] c"Usage: %s <file.gray> width height xoff yoff charwidth charheight\0A\00"
@.str.1 = [27 x i8] c"%s: Error: Parameter <= 0\0A\00"
@.str.2 = [27 x i8] c"%s: Error: charwidth > 32\0A\00"
@.str.3 = [3 x i8] c"r+\00"
@SEEK_END = global i32 0
@.str.4 = [29 x i8] c"%s: Error: file_size != %ld\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [26 x i8] c"%s: Error: Out of memory\0A\00"
@.str.6 = [40 x i8] c"%s: Error: Picture not black and white\0A\00"
@.str.7 = [42 x i8] c"%s: Error: charheight != %ld (yoff2:%ld)\0A\00"
@.str.8 = [25 x i8] c"Read error in file '%s'\0A\00"
@.str.9 = [23 x i8] c"Cannot open file '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 8
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %108
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i64 @atol(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i64 @atol(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 4
%16 = load i8*, i8** %15
%17 = tail call i64 @atol(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 5
%19 = load i8*, i8** %18
%20 = tail call i64 @atol(i8* %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 6
%22 = load i8*, i8** %21
%23 = tail call i64 @atol(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 7
%25 = load i8*, i8** %24
%26 = tail call i64 @atol(i8* %25)
%27 = icmp slt i64 %11, 1
%28 = icmp slt i64 %14, 1
%29 = select i1 %27, i1 true, i1 %28
%30 = icmp slt i64 %17, 0
%31 = select i1 %29, i1 true, i1 %30
%32 = icmp slt i64 %20, 0
%33 = select i1 %31, i1 true, i1 %32
%34 = icmp slt i64 %23, 1
%35 = select i1 %33, i1 true, i1 %34
%36 = icmp slt i64 %26, 1
%37 = select i1 %35, i1 true, i1 %36
br i1 %37, label %38, label %42
38: ; preds = %8
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %1
%41 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %108
42: ; preds = %8
%43 = icmp ugt i64 %23, 32
br i1 %43, label %44, label %48
44: ; preds = %42
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %1
%47 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %108
48: ; preds = %42
%49 = getelementptr inbounds i8*, i8** %1, i64 1
%50 = load i8*, i8** %49
%51 = tail call i32* @fopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i32* %51, null
br i1 %52, label %104, label %53
53: ; preds = %48
%54 = load i32, i32* @SEEK_END
%55 = tail call i64 @fseek(i32* %51, i32 0, i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %99
57: ; preds = %53
%58 = tail call i64 @ftell(i32* %51)
%59 = mul nsw i64 %14, %11
%60 = icmp eq i64 %58, %59
br i1 %60, label %65, label %61
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %1
%64 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %63, i64 %59)
br label %108
65: ; preds = %57
%66 = load i32, i32* @SEEK_SET
%67 = tail call i64 @fseek(i32* %51, i32 0, i32 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %99
69: ; preds = %65
%70 = tail call i8* @malloc(i64 %58)
%71 = icmp eq i8* %70, null
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %1
%75 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %74)
br label %108
76: ; preds = %69
%77 = tail call i64 @fread(i8* %70, i32 1, i64 %58, i32* %51)
%78 = icmp eq i64 %77, %58
br i1 %78, label %79, label %99
79: ; preds = %76
%80 = tail call i32 @nrcolor(i64 %58, i8* %70)
%81 = icmp eq i32 %80, 2
br i1 %81, label %86, label %82
82: ; preds = %79
%83 = load i32, i32* @stderr
%84 = load i8*, i8** %1
%85 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %84)
br label %108
86: ; preds = %79
%87 = tail call i64 @getyoff(i64 %11, i64 %14, i8* %70)
%88 = tail call i64 @getcharheight(i64 %11, i64 %14, i64 %87, i8* %70)
%89 = sub i64 %87, %20
%90 = add i64 %89, %88
%91 = icmp eq i64 %90, %26
br i1 %91, label %96, label %92
92: ; preds = %86
%93 = load i32, i32* @stderr
%94 = load i8*, i8** %1
%95 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %94, i64 %90, i64 %87)
br label %108
96: ; preds = %86
%97 = tail call i32 @fonttable(i64 %11, i64 %14, i64 %17, i64 %20, i64 %23, i64 %26, i8* %70)
%98 = tail call i32 @fclose(i32* %51)
br label %108
99: ; preds = %53, %65, %76
%100 = load i32, i32* @stderr
%101 = load i8*, i8** %49
%102 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %101)
%103 = tail call i32 @fclose(i32* %51)
br label %108
104: ; preds = %48
%105 = load i32, i32* @stderr
%106 = load i8*, i8** %49
%107 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %106)
br label %108
108: ; preds = %38, %44, %61, %72, %82, %92, %96, %104, %99, %4
%109 = phi i32 [ 1, %4 ], [ 1, %38 ], [ 1, %44 ], [ 1, %61 ], [ 1, %82 ], [ 1, %92 ], [ 0, %96 ], [ 1, %72 ], [ 1, %104 ], [ 1, %99 ]
ret i32 %109
}