#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 BUFSIZ;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ out_word(unsigned short);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(unsigned char *, char *);
char *strdup_toupper(char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  FILE *fp;
  size_t len;
  char *prefix;
  unsigned short word = 0;
  int width, height, x = 0, i, b, w = 0;
  unsigned char buf[BUFSIZ];
  if (argc != 3) {
    fprintf(stderr, "Usage: convpbm [input.pbm] prefix > "
                    "output.h\n");
    return 1;
  }
  if (!(fp = fopen(argv[1], "r"))) {
    fprintf(stderr, "Couldn't open input file \"%s\"\n", argv[1]);
    return 1;
  }
  if (!(fgets(buf, BUFSIZ, fp)))
    goto readerr;
  if (strcmp(buf, "P4\n")) {
    fprintf(stderr, "Didn't find valid header. Perhaps this is "
                    "not a binary PBM file?\n");
    return 1;
  }
  if (fscanf(fp, "%d %d\n", &width, &height) != 2) {
    fprintf(stderr, "Failed to read image dimensions\n");
    return 1;
  }
  if (!(prefix = strdup_toupper(argv[2])))
    goto nomem;
  printf("/*\n * Microwindows bitmap converted by convbmp\n * Image "
         "dimensions: %d * %d\n * Prefix: %s\n * Original file name: %s"
         "\n */\n\n#define %s_WIDTH %d\n#define %s_HEIGHT %d\n\n"
         "static GR_BITMAP %s_bits[] = {\n\t",
         width, height, argv[2], argv[1], prefix, width, prefix, height,
         argv[2]);
  free(prefix);
  while (!feof(fp)) {
    len = fread(buf, 1, BUFSIZ, fp);
    for (i = 0; i < len; i++) {
      for (b = 0; b < 8; b++) {
        word <<= 1;
        word |= (buf[i] & 0x80) ? 0 : 1;
        buf[i] <<= 1;
        if (++x >= width) {
          x = 0;
          word <<= 8 - b - 1;
          if (w == 0) {
            word <<= 8;
            w = 1;
          }
          break;
        }
      }
      if (++w == 2) {
        w = 0;
        out_word(word);
        word = 0;
      }
    }
  }
  printf("};\n");
  fclose(fp);
  return 0;
readerr:
  fprintf(stderr, "Read error: %s\n", strerror(errno));
  return 1;
nomem:
  fprintf(stderr, "Out of memory\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x78,%rsp
movl   $0x0,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movw   $0x0,-0x32(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
cmpl   $0x3,-0x10(%rbp)
je     125b <main+0x8b>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    15b7 <main+0x3e7>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc4(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12af <main+0xdf>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    15b7 <main+0x3e7>
mov    -0x70(%rbp),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   10a0 <fgets@plt>
cmp    $0x0,%eax
jne    12d3 <main+0x103>
jmp    1551 <main+0x381>
mov    -0x70(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     1317 <main+0x147>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    15b7 <main+0x3e7>
mov    -0x20(%rbp),%rdi
lea    0xd73(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
call   1080 <fscanf@plt>
cmp    $0x2,%eax
je     1362 <main+0x192>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    15b7 <main+0x3e7>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strdup_toupper@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1382 <main+0x1b2>
jmp    1592 <main+0x3c2>
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%ebx
mov    -0x30(%rbp),%r11
mov    -0x3c(%rbp),%r10d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
lea    0xd07(%rip),%rdi
sub    $0x20,%rsp
mov    %ebx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1070 <printf@plt>
add    $0x20,%rsp
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   10d0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13fe <main+0x22e>
jmp    1527 <main+0x357>
mov    -0x70(%rbp),%rdi
mov    0x2bcf(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1522 <main+0x352>
movl   $0x0,-0x48(%rbp)
cmpl   $0x8,-0x48(%rbp)
jge    14e7 <main+0x317>
mov    -0x70(%rbp),%rax
movzwl -0x32(%rbp),%ecx
shl    $0x1,%ecx
mov    %cx,-0x32(%rbp)
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
and    $0x80,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
cmp    $0x0,%esi
cmovne %ecx,%edx
movzwl -0x32(%rbp),%ecx
or     %edx,%ecx
mov    %cx,-0x32(%rbp)
movslq -0x44(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
shl    $0x1,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
cmp    -0x38(%rbp),%eax
jl     14d4 <main+0x304>
movl   $0x0,-0x40(%rbp)
mov    $0x8,%ecx
sub    -0x48(%rbp),%ecx
sub    $0x1,%ecx
movzwl -0x32(%rbp),%eax
shl    %cl,%eax
mov    %ax,-0x32(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    14cf <main+0x2ff>
movzwl -0x32(%rbp),%eax
shl    $0x8,%eax
mov    %ax,-0x32(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14e7 <main+0x317>
jmp    14d9 <main+0x309>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1439 <main+0x269>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
cmp    $0x2,%eax
jne    150f <main+0x33f>
movl   $0x0,-0x4c(%rbp)
movzwl -0x32(%rbp),%edi
call   1090 <out_word@plt>
movw   $0x0,-0x32(%rbp)
jmp    1514 <main+0x344>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1424 <main+0x254>
jmp    13e0 <main+0x210>
lea    0xc53(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    15b7 <main+0x3e7>
mov    0x2a88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2a6c(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xc0d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    15b7 <main+0x3e7>
mov    0x2a47(%rip),%rax
mov    (%rax),%edi
lea    0xbf3(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0xc(%rbp),%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r14
mov    0x2ddd(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x3,%edi
jne    126d <main+0x8d>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe0b(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1286 <main+0xa6>
mov    %rax,%r13
mov    (%r12),%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   10b0 <fgets@plt>
test   %eax,%eax
je     129c <main+0xbc>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12dd <main+0xfd>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
jmp    127d <main+0x9d>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    12c6 <main+0xe6>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd96(%rip),%rsi
jmp    12bf <main+0xdf>
mov    0x2d3d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xec7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%eax
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb1(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
mov    %r13,%rdi
call   1090 <fscanf@plt>
cmp    $0x2,%eax
jne    136c <main+0x18c>
mov    0x10(%r15),%rdi
call   1040 <strdup_toupper@plt>
test   %rax,%rax
je     1381 <main+0x1a1>
mov    %rax,%r12
mov    %r14,-0x38(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    0x8(%r15),%r8
mov    0x10(%r15),%rcx
lea    0xd9a(%rip),%rdi
mov    %rax,%r9
xor    %eax,%eax
push   %rcx
push   %rdx
push   %r12
push   %rsi
call   1080 <printf@plt>
add    $0x20,%rsp
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   10e0 <feof@plt>
test   %eax,%eax
mov    %r13,%r15
je     1396 <main+0x1b6>
lea    0xe4c(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    -0x38(%rbp),%r14
xor    %eax,%eax
jmp    12cb <main+0xeb>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
jmp    127d <main+0x9d>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
jmp    127d <main+0x9d>
xor    %r13d,%r13d
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    %r15,-0x40(%rbp)
jmp    13c0 <main+0x1e0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x40(%rbp),%r15
mov    %r15,%rdi
call   10e0 <feof@plt>
test   %eax,%eax
jne    134d <main+0x16d>
mov    0x2c11(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1060 <fread@plt>
mov    %rax,-0x48(%rbp)
test   %rax,%rax
je     13b0 <main+0x1d0>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x2c(%rbp),%eax
movzbl (%rbx,%r15,1),%edx
mov    %edx,%ecx
shr    $0x7,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
lea    (%rdx,%rdx,1),%esi
lea    0x1(%r12),%edi
mov    $0x7,%cx
cmp    %eax,%edi
jge    1530 <main+0x350>
shr    $0x7,%sil
movzbl %sil,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
lea    0x0(,%rdx,4),%esi
lea    0x2(%r12),%edi
mov    $0x6,%cx
cmp    %eax,%edi
jge    1530 <main+0x350>
shr    $0x7,%sil
movzbl %sil,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
lea    0x0(,%rdx,8),%esi
lea    0x3(%r12),%edi
mov    $0x5,%cx
cmp    %eax,%edi
jge    1530 <main+0x350>
shr    $0x7,%sil
movzbl %sil,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
mov    %edx,%esi
shl    $0x4,%sil
lea    0x4(%r12),%edi
mov    $0x4,%cx
cmp    %eax,%edi
jge    1530 <main+0x350>
shr    $0x7,%sil
movzbl %sil,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
mov    %edx,%esi
shl    $0x5,%sil
lea    0x5(%r12),%edi
mov    $0x3,%cx
cmp    %eax,%edi
jge    1530 <main+0x350>
shr    $0x7,%sil
movzbl %sil,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
mov    %edx,%esi
shl    $0x6,%sil
lea    0x6(%r12),%edi
mov    $0x2,%cx
cmp    %eax,%edi
jge    1530 <main+0x350>
shr    $0x7,%sil
movzbl %sil,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
lea    0x7(%r12),%ecx
cmp    %eax,%ecx
jge    1519 <main+0x339>
movzwl %dx,%ecx
and    $0x1,%ecx
lea    (%rcx,%r13,2),%r13d
xor    $0x1,%r13d
add    $0x8,%r12d
cmp    %eax,%r12d
jge    1524 <main+0x344>
movb   $0x0,(%rbx,%r15,1)
cmp    $0x1,%r14d
mov    $0x1,%r14d
jne    1559 <main+0x379>
jmp    154a <main+0x36a>
shl    $0x7,%dl
mov    $0x1,%cx
mov    %edx,%esi
jmp    1530 <main+0x350>
xor    %ecx,%ecx
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
mov    %sil,(%rbx,%r15,1)
shl    %cl,%r13d
mov    %r13d,%eax
shl    $0x8,%eax
test   %r14d,%r14d
cmovne %r13d,%eax
xor    %r12d,%r12d
mov    %eax,%r13d
movzwl %r13w,%edi
call   10a0 <out_word@plt>
xor    %r14d,%r14d
xor    %r13d,%r13d
add    $0x1,%r15
cmp    %r15,-0x48(%rbp)
jne    13f0 <main+0x210>
jmp    13b0 <main+0x1d0>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"Usage: convpbm [input.pbm] prefix > output.h\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Couldn't open input file \22%s\22\0A\00"
@.str.3 = [4 x i8] c"P4\0A\00"
@.str.4 = [66 x i8] c"Didn't find valid header. Perhaps this is not a binary PBM file?\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [33 x i8] c"Failed to read image dimensions\0A\00"
@.str.7 = [196 x i8] c"/*\0A * Microwindows bitmap converted by convbmp\0A * Image dimensions: %d * %d\0A * Prefix: %s\0A * Original file name: %s\0A */\0A\0A#define %s_WIDTH %d\0A#define %s_HEIGHT %d\0A\0Astatic GR_BITMAP %s_bits[] = {\0A\09\00"
@.str.8 = [4 x i8] c"};\0A\00"
@.str.9 = [16 x i8] c"Read error: %s\0A\00"
@errno = global i32 0
@.str.10 = [15 x i8] c"Out of memory\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 0, i16* %9
store i32 0, i32* %12
store i32 0, i32* %15
%19 = load i32, i32* @BUFSIZ
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %16
%22 = alloca i8, i64 %20
store i64 %20, i64* %17
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 3
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %18
br label %176
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %6
%33 = icmp ne i32* %32, null
br i1 %33, label %40, label %34
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %38)
store i32 1, i32* %3
store i32 1, i32* %18
br label %176
40: ; preds = %28
%41 = load i32, i32* @BUFSIZ
%42 = load i32*, i32** %6
%43 = call i32 @fgets(i8* %22, i32 %41, i32* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %40
br label %168
46: ; preds = %40
%47 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %18
br label %176
52: ; preds = %46
%53 = load i32*, i32** %6
%54 = call i32 @fscanf(i32* %53, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %10, i32* %11)
%55 = icmp ne i32 %54, 2
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %18
br label %176
59: ; preds = %52
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = call i8* @strdup_toupper(i8* %62)
store i8* %63, i8** %8
%64 = icmp ne i8* %63, null
br i1 %64, label %66, label %65
65: ; preds = %59
br label %173
66: ; preds = %59
%67 = load i32, i32* %10
%68 = load i32, i32* %11
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 2
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = load i8*, i8** %8
%76 = load i32, i32* %10
%77 = load i8*, i8** %8
%78 = load i32, i32* %11
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 2
%81 = load i8*, i8** %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([196 x i8], [196 x i8]* @.str.7, i64 0, i64 0), i32 %67, i32 %68, i8* %71, i8* %74, i8* %75, i32 %76, i8* %77, i32 %78, i8* %81)
%83 = load i8*, i8** %8
%84 = call i32 @free(i8* %83)
br label %85
85: ; preds = %163, %66
%86 = load i32*, i32** %6
%87 = call i32 @feof(i32* %86)
%88 = icmp ne i32 %87, 0
%89 = xor i1 %88, true
br i1 %89, label %90, label %164
90: ; preds = %85
%91 = load i32, i32* @BUFSIZ
%92 = load i32*, i32** %6
%93 = call i64 @fread(i8* %22, i32 1, i32 %91, i32* %92)
store i64 %93, i64* %7
store i32 0, i32* %13
br label %94
94: ; preds = %160, %90
%95 = load i32, i32* %13
%96 = sext i32 %95 to i64
%97 = load i64, i64* %7
%98 = icmp ult i64 %96, %97
br i1 %98, label %99, label %163
99: ; preds = %94
store i32 0, i32* %14
br label %100
100: ; preds = %149, %99
%101 = load i32, i32* %14
%102 = icmp slt i32 %101, 8
br i1 %102, label %103, label %152
103: ; preds = %100
%104 = load i16, i16* %9
%105 = zext i16 %104 to i32
%106 = shl i32 %105, 1
%107 = trunc i32 %106 to i16
store i16 %107, i16* %9
%108 = load i32, i32* %13
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %22, i64 %109
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
%113 = and i32 %112, 128
%114 = icmp ne i32 %113, 0
%115 = zext i1 %114 to i64
%116 = select i1 %114, i32 0, i32 1
%117 = load i16, i16* %9
%118 = zext i16 %117 to i32
%119 = or i32 %118, %116
%120 = trunc i32 %119 to i16
store i16 %120, i16* %9
%121 = load i32, i32* %13
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8, i8* %22, i64 %122
%124 = load i8, i8* %123
%125 = zext i8 %124 to i32
%126 = shl i32 %125, 1
%127 = trunc i32 %126 to i8
store i8 %127, i8* %123
%128 = load i32, i32* %12
%129 = add nsw i32 %128, 1
store i32 %129, i32* %12
%130 = load i32, i32* %10
%131 = icmp sge i32 %129, %130
br i1 %131, label %132, label %148
132: ; preds = %103
store i32 0, i32* %12
%133 = load i32, i32* %14
%134 = sub nsw i32 8, %133
%135 = sub nsw i32 %134, 1
%136 = load i16, i16* %9
%137 = zext i16 %136 to i32
%138 = shl i32 %137, %135
%139 = trunc i32 %138 to i16
store i16 %139, i16* %9
%140 = load i32, i32* %15
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %147
142: ; preds = %132
%143 = load i16, i16* %9
%144 = zext i16 %143 to i32
%145 = shl i32 %144, 8
%146 = trunc i32 %145 to i16
store i16 %146, i16* %9
store i32 1, i32* %15
br label %147
147: ; preds = %142, %132
br label %152
148: ; preds = %103
br label %149
149: ; preds = %148
%150 = load i32, i32* %14
%151 = add nsw i32 %150, 1
store i32 %151, i32* %14
br label %100
152: ; preds = %147, %100
%153 = load i32, i32* %15
%154 = add nsw i32 %153, 1
store i32 %154, i32* %15
%155 = icmp eq i32 %154, 2
br i1 %155, label %156, label %159
156: ; preds = %152
store i32 0, i32* %15
%157 = load i16, i16* %9
%158 = call i32 @out_word(i16 zeroext %157)
store i16 0, i16* %9
br label %159
159: ; preds = %156, %152
br label %160
160: ; preds = %159
%161 = load i32, i32* %13
%162 = add nsw i32 %161, 1
store i32 %162, i32* %13
br label %94
163: ; preds = %94
br label %85
164: ; preds = %85
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%166 = load i32*, i32** %6
%167 = call i32 @fclose(i32* %166)
store i32 0, i32* %3
store i32 1, i32* %18
br label %176
168: ; preds = %45
%169 = load i32, i32* @stderr
%170 = load i32, i32* @errno
%171 = call i8* @strerror(i32 %170)
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %171)
store i32 1, i32* %3
store i32 1, i32* %18
br label %176
173: ; preds = %65
%174 = load i32, i32* @stderr
%175 = call i32 (i32, i8*, ...) @fprintf(i32 %174, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %18
br label %176
176: ; preds = %173, %168, %164, %56, %49, %34, %25
%177 = load i8*, i8** %16
%178 = load i32, i32* %3
ret i32 %178
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"Usage: convpbm [input.pbm] prefix > output.h\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Couldn't open input file \22%s\22\0A\00"
@.str.3 = [4 x i8] c"P4\0A\00"
@.str.4 = [66 x i8] c"Didn't find valid header. Perhaps this is not a binary PBM file?\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [33 x i8] c"Failed to read image dimensions\0A\00"
@.str.7 = [196 x i8] c"/*\0A * Microwindows bitmap converted by convbmp\0A * Image dimensions: %d * %d\0A * Prefix: %s\0A * Original file name: %s\0A */\0A\0A#define %s_WIDTH %d\0A#define %s_HEIGHT %d\0A\0Astatic GR_BITMAP %s_bits[] = {\0A\09\00"
@.str.9 = [16 x i8] c"Read error: %s\0A\00"
@errno = global i32 0
@.str.10 = [15 x i8] c"Out of memory\0A\00"
@str = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = icmp eq i32 %0, 3
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %176
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %16
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %176
24: ; preds = %15
%25 = load i32, i32* @BUFSIZ
%26 = call i32 @fgets(i8* %10, i32 %25, i32* %18)
%27 = icmp eq i32 %26, 0
br i1 %27, label %168, label %28
28: ; preds = %24
%29 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
br label %176
34: ; preds = %28
%35 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %3, i32* %4)
%36 = icmp eq i32 %35, 2
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %176
40: ; preds = %34
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = call i8* @strdup_toupper(i8* %42)
%44 = icmp eq i8* %43, null
br i1 %44, label %173, label %45
45: ; preds = %40
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = load i8*, i8** %41
%49 = load i8*, i8** %16
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([196 x i8], [196 x i8]* @.str.7, i64 0, i64 0), i32 %46, i32 %47, i8* %48, i8* %49, i8* %43, i32 %46, i8* %43, i32 %47, i8* %48)
%51 = call i32 @free(i8* %43)
%52 = call i32 @feof(i32* %18)
%53 = icmp eq i32 %52, 0
br i1 %53, label %60, label %165
54: ; preds = %159, %60
%55 = phi i32 [ %63, %60 ], [ %160, %159 ]
%56 = phi i32 [ %62, %60 ], [ %161, %159 ]
%57 = phi i16 [ %61, %60 ], [ %162, %159 ]
%58 = call i32 @feof(i32* %18)
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %165
60: ; preds = %45, %54
%61 = phi i16 [ %57, %54 ], [ 0, %45 ]
%62 = phi i32 [ %56, %54 ], [ 0, %45 ]
%63 = phi i32 [ %55, %54 ], [ 0, %45 ]
%64 = load i32, i32* @BUFSIZ
%65 = call i64 @fread(i8* %10, i32 1, i32 %64, i32* %18)
%66 = icmp eq i64 %65, 0
br i1 %66, label %54, label %67
67: ; preds = %60, %159
%68 = phi i64 [ %163, %159 ], [ 0, %60 ]
%69 = phi i16 [ %162, %159 ], [ %61, %60 ]
%70 = phi i32 [ %161, %159 ], [ %62, %60 ]
%71 = phi i32 [ %160, %159 ], [ %63, %60 ]
%72 = getelementptr inbounds i8, i8* %10, i64 %68
%73 = load i32, i32* %3
%74 = load i8, i8* %72
%75 = shl i16 %69, 1
%76 = lshr i8 %74, 7
%77 = zext i8 %76 to i16
%78 = or i16 %75, %77
%79 = xor i16 %78, 1
%80 = shl i8 %74, 1
%81 = add nsw i32 %71, 1
%82 = icmp slt i32 %81, %73
br i1 %82, label %91, label %83
83: ; preds = %145, %136, %127, %118, %109, %100, %91, %67
%84 = phi i16 [ 7, %67 ], [ 6, %91 ], [ 5, %100 ], [ 4, %109 ], [ 3, %118 ], [ 2, %127 ], [ 1, %136 ], [ 0, %145 ]
%85 = phi i16 [ %79, %67 ], [ %96, %91 ], [ %105, %100 ], [ %114, %109 ], [ %123, %118 ], [ %132, %127 ], [ %141, %136 ], [ %150, %145 ]
%86 = phi i8 [ %80, %67 ], [ %97, %91 ], [ %106, %100 ], [ %115, %109 ], [ %124, %118 ], [ %133, %127 ], [ %142, %136 ], [ 0, %145 ]
store i8 %86, i8* %72
%87 = shl i16 %85, %84
%88 = icmp eq i32 %70, 0
%89 = shl i16 %87, 8
%90 = select i1 %88, i16 %89, i16 %87
br label %155
91: ; preds = %67
%92 = shl i16 %79, 1
%93 = lshr i8 %80, 7
%94 = zext i8 %93 to i16
%95 = or i16 %92, %94
%96 = xor i16 %95, 1
%97 = shl i8 %74, 2
%98 = add nsw i32 %71, 2
%99 = icmp slt i32 %98, %73
br i1 %99, label %100, label %83
100: ; preds = %91
%101 = shl i16 %96, 1
%102 = lshr i8 %97, 7
%103 = zext i8 %102 to i16
%104 = or i16 %101, %103
%105 = xor i16 %104, 1
%106 = shl i8 %74, 3
%107 = add nsw i32 %71, 3
%108 = icmp slt i32 %107, %73
br i1 %108, label %109, label %83
109: ; preds = %100
%110 = shl i16 %105, 1
%111 = lshr i8 %106, 7
%112 = zext i8 %111 to i16
%113 = or i16 %110, %112
%114 = xor i16 %113, 1
%115 = shl i8 %74, 4
%116 = add nsw i32 %71, 4
%117 = icmp slt i32 %116, %73
br i1 %117, label %118, label %83
118: ; preds = %109
%119 = shl i16 %114, 1
%120 = lshr i8 %115, 7
%121 = zext i8 %120 to i16
%122 = or i16 %119, %121
%123 = xor i16 %122, 1
%124 = shl i8 %74, 5
%125 = add nsw i32 %71, 5
%126 = icmp slt i32 %125, %73
br i1 %126, label %127, label %83
127: ; preds = %118
%128 = shl i16 %123, 1
%129 = lshr i8 %124, 7
%130 = zext i8 %129 to i16
%131 = or i16 %128, %130
%132 = xor i16 %131, 1
%133 = shl i8 %74, 6
%134 = add nsw i32 %71, 6
%135 = icmp slt i32 %134, %73
br i1 %135, label %136, label %83
136: ; preds = %127
%137 = shl i16 %132, 1
%138 = lshr i8 %133, 7
%139 = zext i8 %138 to i16
%140 = or i16 %137, %139
%141 = xor i16 %140, 1
%142 = shl i8 %74, 7
%143 = add nsw i32 %71, 7
%144 = icmp slt i32 %143, %73
br i1 %144, label %145, label %83
145: ; preds = %136
%146 = shl i16 %141, 1
%147 = and i8 %74, 1
%148 = zext i8 %147 to i16
%149 = or i16 %146, %148
%150 = xor i16 %149, 1
%151 = add nsw i32 %71, 8
%152 = icmp slt i32 %151, %73
br i1 %152, label %153, label %83
153: ; preds = %145
store i8 0, i8* %72
%154 = icmp eq i32 %70, 1
br i1 %154, label %155, label %159
155: ; preds = %83, %153
%156 = phi i16 [ %150, %153 ], [ %90, %83 ]
%157 = phi i32 [ %151, %153 ], [ 0, %83 ]
%158 = call i32 @out_word(i16 zeroext %156)
br label %159
159: ; preds = %153, %155
%160 = phi i32 [ %157, %155 ], [ %151, %153 ]
%161 = phi i32 [ 0, %155 ], [ 1, %153 ]
%162 = phi i16 [ 0, %155 ], [ %150, %153 ]
%163 = add nuw i64 %68, 1
%164 = icmp eq i64 %163, %65
br i1 %164, label %54, label %67
165: ; preds = %54, %45
%166 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%167 = call i32 @fclose(i32* %18)
br label %176
168: ; preds = %24
%169 = load i32, i32* @stderr
%170 = load i32, i32* @errno
%171 = call i8* @strerror(i32 %170)
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %171)
br label %176
173: ; preds = %40
%174 = load i32, i32* @stderr
%175 = call i32 (i32, i8*, ...) @fprintf(i32 %174, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %176
176: ; preds = %173, %168, %165, %37, %31, %20, %12
%177 = phi i32 [ 1, %12 ], [ 1, %31 ], [ 1, %37 ], [ 0, %165 ], [ 1, %173 ], [ 1, %168 ], [ 1, %20 ]
ret i32 %177
}