#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 uint8_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  FILE *f;
  char buf[512];
  uint16_t tile, mask;
  enum { ST_START, ST_SOLID, ST_BOUNDRY } state = ST_START;
  uint8_t rands[0xf];
  unsigned int k = 0, i;
  uint16_t kase;
  if (argc != 2) {
    fprintf(stderr, "*** Usage: %s <list>\n", argv[0]);
    fprintf(stderr, "*** Generate the list with something like:\n"
                    "***   1) ./tools/extract_sprites path/to/maindat.war\n"
                    "***   2) ls -1 ./tiles/png/winter > winter.list\n");
    return 1;
  }
  f = fopen(argv[1], "r");
  if (!f) {
    fprintf(stderr, "*** Failed to open \"%s\"\n", argv[1]);
    return 2;
  }
  while (fgets(buf, sizeof(buf), f)) {
    buf[6] = 0;
    tile = strtol(buf, NULL, 16);
    switch (state) {
    case ST_START:
      printf("if ((tile & 0xff00) == 0x0000) /* Solid */\n");
      printf("  {\n");
      printf("     switch (tile & 0x00f0)\n");
      printf("       {\n");
      state = ST_SOLID;
      mask = 0x00f0;
      kase = tile & mask;
      break;
    case ST_SOLID:
      if ((0x0f00 & tile) != 0x0000) {
        printf("    default:\n");
        printf(
            "       fprintf(stderr, \"*** Invalid tile 0x%%04x\\n\", tile);\n");
        printf("       return 0x0000;\n");
        printf("      }\n");
        printf("  }\n");
        printf("else /* Boundry */\n");
        printf("  {\n");
        printf("     switch (tile & 0x0ff0)\n");
        printf("        {\n");
        mask = 0x0ff0;
        kase = tile & mask;
        state = ST_BOUNDRY;
        k = 0;
      }
      break;
    case ST_BOUNDRY:
      break;
    }
    if ((tile & mask) != kase) {
      printf(" case 0x%04x:\n", kase);
      printf("    GEN(%u", k);
      for (i = 0; i < k; ++i)
        printf(", 0x%1x", rands[i]);
      printf("); break;\n");
      k = 0;
      kase = (tile & mask);
    }
    rands[k++] = (tile & 0x000f);
  }
  printf("    default:\n");
  printf("       fprintf(stderr, \"*** Invalid tile 0x%%04x\\n\", tile);\n");
  printf("       return 0x0000;\n");
  printf("      }\n");
  printf("  }\n");
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x22c(%rbp)
movl   $0x0,-0x274(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d8 <main+0x78>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    150f <main+0x3af>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xec0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1226 <main+0xc6>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    150f <main+0x3af>
jmp    122b <main+0xcb>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     14b9 <main+0x359>
movb   $0x0,-0x21a(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x220(%rbp),%rdi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,-0x224(%rbp)
mov    -0x22c(%rbp),%eax
mov    %eax,-0x280(%rbp)
test   %eax,%eax
je     12ad <main+0x14d>
jmp    1285 <main+0x125>
mov    -0x280(%rbp),%eax
sub    $0x1,%eax
je     1310 <main+0x1b0>
jmp    1299 <main+0x139>
mov    -0x280(%rbp),%eax
sub    $0x2,%eax
je     13d7 <main+0x277>
jmp    13dc <main+0x27c>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x22c(%rbp)
movl   $0xf0,-0x228(%rbp)
mov    -0x224(%rbp),%eax
and    -0x228(%rbp),%eax
mov    %eax,-0x27c(%rbp)
jmp    13dc <main+0x27c>
mov    -0x224(%rbp),%eax
and    $0xf00,%eax
cmp    $0x0,%eax
je     13d2 <main+0x272>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xff0,-0x228(%rbp)
mov    -0x224(%rbp),%eax
and    -0x228(%rbp),%eax
mov    %eax,-0x27c(%rbp)
movl   $0x2,-0x22c(%rbp)
movl   $0x0,-0x274(%rbp)
jmp    13dc <main+0x27c>
jmp    13dc <main+0x27c>
mov    -0x224(%rbp),%eax
and    -0x228(%rbp),%eax
cmp    -0x27c(%rbp),%eax
je     1491 <main+0x331>
mov    -0x27c(%rbp),%esi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x274(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x278(%rbp)
mov    -0x278(%rbp),%eax
cmp    -0x274(%rbp),%eax
jae    1467 <main+0x307>
mov    -0x278(%rbp),%eax
mov    -0x270(%rbp,%rax,4),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x278(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x278(%rbp)
jmp    1426 <main+0x2c6>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x274(%rbp)
mov    -0x224(%rbp),%eax
and    -0x228(%rbp),%eax
mov    %eax,-0x27c(%rbp)
mov    -0x224(%rbp),%ecx
and    $0xf,%ecx
mov    -0x274(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x274(%rbp)
mov    %eax,%eax
mov    %ecx,-0x270(%rbp,%rax,4)
jmp    122b <main+0xcb>
lea    0xc4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x258,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    139c <main+0x22c>
mov    0x8(%rbx),%rdi
lea    0xf0f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1419 <main+0x2a9>
mov    %rax,%r14
lea    0x50(%rsp),%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     13cf <main+0x25f>
lea    0x50(%rsp),%rbx
xor    %r13d,%r13d
xor    %ebp,%ebp
mov    %r14,0x8(%rsp)
jmp    1228 <main+0xb8>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xf3a(%rip),%rdi
call   1030 <puts@plt>
xor    %r13d,%r13d
mov    %r14d,%r15d
and    $0xf,%r12d
mov    %r13d,%eax
add    $0x1,%r13d
mov    %r12d,0x10(%rsp,%rax,4)
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    0x8(%rsp),%r14
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
mov    (%rsp),%ebp
je     13cf <main+0x25f>
movb   $0x0,0x56(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,%r12d
test   %ebp,%ebp
je     12d0 <main+0x160>
cmp    $0x1,%ebp
jne    1320 <main+0x1b0>
test   $0xf00,%r12d
je     1325 <main+0x1b5>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
xor    %r13d,%r13d
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
movl   $0x2,(%rsp)
mov    $0xff0,%ebx
lea    0xea5(%rip),%rdi
lea    0xeb1(%rip),%r14
lea    0xec6(%rip),%rbp
jmp    12f1 <main+0x181>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x1,(%rsp)
mov    $0xf0,%ebx
lea    0xeac(%rip),%rdi
lea    0xed0(%rip),%r14
lea    0xe95(%rip),%rbp
call   1030 <puts@plt>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r12d,%r15d
and    %ebx,%r15d
jmp    1330 <main+0x1c0>
nopw   0x0(%rax,%rax,1)
mov    %ebp,(%rsp)
jmp    132c <main+0x1bc>
movl   $0x1,(%rsp)
mov    0x4(%rsp),%ebx
mov    %ebx,0x4(%rsp)
mov    %ebx,%r14d
and    %r12d,%r14d
cmp    %r15d,%r14d
je     11f2 <main+0x82>
lea    0xdb5(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdb3(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
lea    0xdaa(%rip),%r15
je     11e0 <main+0x70>
mov    %r13d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbp,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1380 <main+0x210>
jmp    11e0 <main+0x70>
mov    0x2c3d(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xc50(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xc55(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebx
jmp    1439 <main+0x2c9>
lea    0xd55(%rip),%rdi
call   1030 <puts@plt>
lea    0xce0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd46(%rip),%rdi
call   1030 <puts@plt>
lea    0xd50(%rip),%rdi
call   1030 <puts@plt>
lea    0xd48(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1439 <main+0x2c9>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xc7c(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"*** Usage: %s <list>\0A\00"
@.str.1 = [145 x i8] c"*** Generate the list with something like:\0A*** 1) ./tools/extract_sprites path/to/maindat.war\0A*** 2) ls -1 ./tiles/png/winter > winter.list\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"*** Failed to open \22%s\22\0A\00"
@.str.4 = [44 x i8] c"if ((tile & 0xff00) == 0x0000) /* Solid */\0A\00"
@.str.5 = [5 x i8] c" {\0A\00"
@.str.6 = [29 x i8] c" switch (tile & 0x00f0)\0A\00"
@.str.7 = [10 x i8] c" {\0A\00"
@.str.8 = [14 x i8] c" default:\0A\00"
@.str.9 = [61 x i8] c" fprintf(stderr, \22*** Invalid tile 0x%%04x\\n\22, tile);\0A\00"
@.str.10 = [23 x i8] c" return 0x0000;\0A\00"
@.str.11 = [9 x i8] c" }\0A\00"
@.str.12 = [5 x i8] c" }\0A\00"
@.str.13 = [20 x i8] c"else /* Boundry */\0A\00"
@.str.14 = [29 x i8] c" switch (tile & 0x0ff0)\0A\00"
@.str.15 = [11 x i8] c" {\0A\00"
@.str.16 = [15 x i8] c" case 0x%04x:\0A\00"
@.str.17 = [11 x i8] c" GEN(%u\00"
@.str.18 = [8 x i8] c", 0x%1x\00"
@.str.19 = [11 x i8] c"); break;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [15 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %12
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %120
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %38, label %32
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 2, i32* %3
br label %120
38: ; preds = %25
br label %39
39: ; preds = %105, %38
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%41 = load i32*, i32** %6
%42 = call i64 @fgets(i8* %40, i32 512, i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %112
44: ; preds = %39
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 6
store i8 0, i8* %45
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%47 = call i32 @strtol(i8* %46, i32* null, i32 16)
store i32 %47, i32* %8
%48 = load i32, i32* %10
switch i32 %48, label %76 [
i32 0, label %49
i32 1, label %57
i32 2, label %75
]
49: ; preds = %44
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %10
store i32 240, i32* %9
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = and i32 %54, %55
store i32 %56, i32* %14
br label %76
57: ; preds = %44
%58 = load i32, i32* %8
%59 = and i32 3840, %58
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %74
61: ; preds = %57
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0))
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.14, i64 0, i64 0))
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.15, i64 0, i64 0))
store i32 4080, i32* %9
%71 = load i32, i32* %8
%72 = load i32, i32* %9
%73 = and i32 %71, %72
store i32 %73, i32* %14
store i32 2, i32* %10
store i32 0, i32* %12
br label %74
74: ; preds = %61, %57
br label %76
75: ; preds = %44
br label %76
76: ; preds = %44, %75, %74, %49
%77 = load i32, i32* %8
%78 = load i32, i32* %9
%79 = and i32 %77, %78
%80 = load i32, i32* %14
%81 = icmp ne i32 %79, %80
br i1 %81, label %82, label %105
82: ; preds = %76
%83 = load i32, i32* %14
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0), i32 %83)
%85 = load i32, i32* %12
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.17, i64 0, i64 0), i32 %85)
store i32 0, i32* %13
br label %87
87: ; preds = %97, %82
%88 = load i32, i32* %13
%89 = load i32, i32* %12
%90 = icmp ult i32 %88, %89
br i1 %90, label %91, label %100
91: ; preds = %87
%92 = load i32, i32* %13
%93 = zext i32 %92 to i64
%94 = getelementptr inbounds [15 x i32], [15 x i32]* %11, i64 0, i64 %93
%95 = load i32, i32* %94
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %91
%98 = load i32, i32* %13
%99 = add i32 %98, 1
store i32 %99, i32* %13
br label %87
100: ; preds = %87
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0))
store i32 0, i32* %12
%102 = load i32, i32* %8
%103 = load i32, i32* %9
%104 = and i32 %102, %103
store i32 %104, i32* %14
br label %105
105: ; preds = %100, %76
%106 = load i32, i32* %8
%107 = and i32 %106, 15
%108 = load i32, i32* %12
%109 = add i32 %108, 1
store i32 %109, i32* %12
%110 = zext i32 %108 to i64
%111 = getelementptr inbounds [15 x i32], [15 x i32]* %11, i64 0, i64 %110
store i32 %107, i32* %111
br label %39
112: ; preds = %39
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0))
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%118 = load i32*, i32** %6
%119 = call i32 @fclose(i32* %118)
store i32 0, i32* %3
br label %120
120: ; preds = %112, %32, %17
%121 = load i32, i32* %3
ret i32 %121
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"*** Usage: %s <list>\0A\00"
@.str.1 = [145 x i8] c"*** Generate the list with something like:\0A*** 1) ./tools/extract_sprites path/to/maindat.war\0A*** 2) ls -1 ./tiles/png/winter > winter.list\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"*** Failed to open \22%s\22\0A\00"
@.str.9 = [61 x i8] c" fprintf(stderr, \22*** Invalid tile 0x%%04x\\n\22, tile);\0A\00"
@.str.16 = [15 x i8] c" case 0x%04x:\0A\00"
@.str.17 = [11 x i8] c" GEN(%u\00"
@.str.18 = [8 x i8] c", 0x%1x\00"
@str.23 = [10 x i8] c"); break;\00"
@str.24 = [13 x i8] c" default:\00"
@str.25 = [22 x i8] c" return 0x0000;\00"
@str.26 = [8 x i8] c" }\00"
@str.27 = [4 x i8] c" }\00"
@str.28 = [19 x i8] c"else /* Boundry */\00"
@str.30 = [28 x i8] c" switch (tile & 0x0ff0)\00"
@str.31 = [10 x i8] c" {\00"
@str.32 = [43 x i8] c"if ((tile & 0xff00) == 0x0000) /* Solid */\00"
@str.33 = [4 x i8] c" {\00"
@str.34 = [28 x i8] c" switch (tile & 0x00f0)\00"
@str.35 = [9 x i8] c" {\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca [15 x i32]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast [15 x i32]* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0))
br label %94
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = call i64 @fgets(i8* %5, i32 512, i32* %17)
%21 = icmp eq i64 %20, 0
br i1 %21, label %87, label %22
22: ; preds = %19
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 6
br label %28
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %15
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %94
28: ; preds = %22, %78
%29 = phi i32 [ undef, %22 ], [ %80, %78 ]
%30 = phi i32 [ 0, %22 ], [ %82, %78 ]
%31 = phi i32 [ 0, %22 ], [ %58, %78 ]
%32 = phi i32 [ undef, %22 ], [ %57, %78 ]
store i8 0, i8* %23
%33 = call i32 @strtol(i8* nocapture %5, i32* null, i32 16)
switch i32 %31, label %56 [
i32 0, label %43
i32 1, label %34
]
34: ; preds = %28
%35 = and i32 %33, 3840
%36 = icmp eq i32 %35, 0
br i1 %36, label %56, label %37
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.24, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.25, i64 0, i64 0))
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.26, i64 0, i64 0))
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.27, i64 0, i64 0))
br label %43
43: ; preds = %28, %37
%44 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.28, i64 0, i64 0), %37 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @str.32, i64 0, i64 0), %28 ]
%45 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.33, i64 0, i64 0), %37 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.33, i64 0, i64 0), %28 ]
%46 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.30, i64 0, i64 0), %37 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.34, i64 0, i64 0), %28 ]
%47 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.31, i64 0, i64 0), %37 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.35, i64 0, i64 0), %28 ]
%48 = phi i32 [ 4080, %37 ], [ 240, %28 ]
%49 = phi i32 [ 2, %37 ], [ 1, %28 ]
%50 = phi i32 [ 0, %37 ], [ %30, %28 ]
%51 = call i32 @puts(i8* dereferenceable(1) %44)
%52 = call i32 @puts(i8* dereferenceable(1) %45)
%53 = call i32 @puts(i8* dereferenceable(1) %46)
%54 = call i32 @puts(i8* dereferenceable(1) %47)
%55 = and i32 %33, %48
br label %56
56: ; preds = %43, %34, %28
%57 = phi i32 [ %32, %28 ], [ %32, %34 ], [ %48, %43 ]
%58 = phi i32 [ %31, %28 ], [ 1, %34 ], [ %49, %43 ]
%59 = phi i32 [ %30, %28 ], [ %30, %34 ], [ %50, %43 ]
%60 = phi i32 [ %29, %28 ], [ %29, %34 ], [ %55, %43 ]
%61 = and i32 %57, %33
%62 = icmp eq i32 %61, %60
br i1 %62, label %78, label %63
63: ; preds = %56
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0), i32 %60)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.17, i64 0, i64 0), i32 %59)
%66 = icmp eq i32 %59, 0
br i1 %66, label %76, label %67
67: ; preds = %63
%68 = zext i32 %59 to i64
br label %69
69: ; preds = %67, %69
%70 = phi i64 [ 0, %67 ], [ %74, %69 ]
%71 = getelementptr inbounds [15 x i32], [15 x i32]* %4, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i64 0, i64 0), i32 %72)
%74 = add nuw nsw i64 %70, 1
%75 = icmp eq i64 %74, %68
br i1 %75, label %76, label %69
76: ; preds = %69, %63
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.23, i64 0, i64 0))
br label %78
78: ; preds = %76, %56
%79 = phi i32 [ 0, %76 ], [ %59, %56 ]
%80 = phi i32 [ %61, %76 ], [ %60, %56 ]
%81 = and i32 %33, 15
%82 = add i32 %79, 1
%83 = zext i32 %79 to i64
%84 = getelementptr inbounds [15 x i32], [15 x i32]* %4, i64 0, i64 %83
store i32 %81, i32* %84
%85 = call i64 @fgets(i8* %5, i32 512, i32* %17)
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %28
87: ; preds = %78, %19
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.24, i64 0, i64 0))
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0))
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.25, i64 0, i64 0))
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.26, i64 0, i64 0))
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.27, i64 0, i64 0))
%93 = call i32 @fclose(i32* %17)
br label %94
94: ; preds = %87, %24, %8
%95 = phi i32 [ 1, %8 ], [ 0, %87 ], [ 2, %24 ]
ret i32 %95
}