#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 */
long EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
char *malloc(long);
char *pack_table(char *, char const *, char const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ replace(char *, char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int strlen(char const *);
char *strstr(char *, char const *);
int main() {
  char *buf, *offset, *ptr;
  long sz;
  FILE *fp;
  const char *next_opcode = "    .next_opcode:\n\tmov\tah,al\n";
  const char *opcode_table_header = "  ; opcode table obviously";
  const char *opcode_table = "opcode_table:\n";
  const char *opcode_table_0F_header = "  ; escaped opcode table";
  const char *opcode_table_0F = "opcode_table_0F:\n";
  fp = fopen("decode.asm", "rb");
  if (!fp)
    return 1;
  if (fseek(fp, 0, SEEK_END))
    return 1;
  sz = ftell(fp);
  if (sz == EOF)
    return 1;
  rewind(fp);
  buf = malloc(sz + 1);
  if (!buf)
    return 1;
  if (fread(buf, 1, sz, fp) != (size_t)sz)
    return 1;
  buf[sz] = '\0';
  replace(buf, "\r\n", "\n");
  ptr = strstr(buf, next_opcode);
  if (!ptr)
    return 1;
  offset = ptr + strlen(next_opcode);
  fwrite(buf, 1, offset - buf, stdout);
  printf("      .loop:\n"
         "\tmov\tcl,[rbx]\n"
         "\tmov\tch,[rbx]\n"
         "\tshr\tcl,5\n"
         "\tand\tch,1Fh\n"
         "\tinc\tcl\n"
         "\tinc\trbx\n"
         "\tsub\tal,cl\n"
         "\tjnc\t.loop\n"
         "\tmov\tal,ch\n"
         "\tlea\trbx,[flags_table]\n");
  ptr = strstr(offset, opcode_table_header);
  if (!ptr)
    return 1;
  fwrite(offset, 1, ptr - offset, stdout);
  printf("  ; flags table indices\n\n"
         "  T_NONE\t      = 0\n"
         "  T_MODRM\t      = 1\n"
         "  T_MODRM_IMM8\t      = 2\n"
         "  T_MODRM_IMM32\t      = 3\n"
         "  T_IMM8\t      = 4\n"
         "  T_IMM16\t      = 5\n"
         "  T_IMM16_IMM8\t      = 6\n"
         "  T_IMM32\t      = 7\n"
         "  T_REL_IMM8\t      = 8\n"
         "  T_REL_IMM32\t      = 9\n"
         "  T_GROUP_MODRM\t      = 10\n"
         "  T_GROUP_MODRM_IMM8  = 11\n"
         "  T_GROUP_MODRM_IMM32 = 12\n"
         "  T_ERROR_NONE\t      = 13\n"
         "  T_ERROR_MODRM\t      = 14\n"
         "  T_ERROR_IMM8\t      = 15\n"
         "  T_ERROR_IMM32_IMM16 = 16\n"
         "  T_MOFFS\t      = 17\n"
         "  T_PREFIX\t      = 18\n"
         "  T_0F\t\t      = 19\n"
         "  T_3BYTE\t      = 20\n"
         "  T_UNDEFINED\t      = 21\n\n"
         "  ; flags table for grouping\n\n"
         "flags_table:\n\n"
         "\tdb\tC_NONE\n"
         "\tdb\tC_MODRM\n"
         "\tdb\tC_MODRM+C_IMM8\n"
         "\tdb\tC_MODRM+C_IMM32\n"
         "\tdb\tC_IMM8\n"
         "\tdb\tC_IMM16\n"
         "\tdb\tC_IMM16+C_IMM8\n"
         "\tdb\tC_IMM32\n"
         "\tdb\tC_REL+C_IMM8\n"
         "\tdb\tC_REL+C_IMM32\n"
         "\tdb\tC_GROUP+C_MODRM\n"
         "\tdb\tC_GROUP+C_MODRM+C_IMM8\n"
         "\tdb\tC_GROUP+C_MODRM+C_IMM32\n"
         "\tdb\tC_ERROR+C_NONE\n"
         "\tdb\tC_ERROR+C_MODRM\n"
         "\tdb\tC_ERROR+C_IMM8\n"
         "\tdb\tC_ERROR+C_IMM32+C_IMM16\n"
         "\tdb\tC_MOFFS\n"
         "\tdb\tC_PREFIX\n"
         "\tdb\tC_0F\n"
         "\tdb\tC_3BYTE\n"
         "\tdb\tC_UNDEFINED\n\n");
  ptr = strstr(ptr, opcode_table);
  if (!ptr)
    return 1;
  ptr =
      pack_table(ptr + strlen(opcode_table), opcode_table_header, opcode_table);
  printf("\n");
  ptr = strstr(offset, opcode_table_0F_header);
  if (!ptr)
    return 1;
  ptr = strstr(ptr, opcode_table_0F);
  if (!ptr)
    return 1;
  ptr = pack_table(ptr + strlen(opcode_table_0F), opcode_table_0F_header,
                   opcode_table_0F);
  printf("%s", ptr);
  free(buf);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe0a(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe1d(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe2d(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe31(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe46(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1254 <main+0x74>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x30(%rbp),%rdi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
cmp    $0x0,%rax
je     127e <main+0x9e>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x30(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d4a(%rip),%rcx
cmp    (%rcx),%rax
jne    12ab <main+0xcb>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x30(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12dc <main+0xfc>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x28(%rbp),%rax
je     1308 <main+0x128>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xd62(%rip),%rsi
lea    0x11a7(%rip),%rdx
call   10d0 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1353 <main+0x173>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    0x2c44(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
lea    0xce5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13ce <main+0x1ee>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    0x2bea(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1428 <main+0x248>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x68(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1090 <pack_table@plt>
mov    %rax,-0x20(%rbp)
lea    0x1073(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1489 <main+0x2a9>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    14b1 <main+0x2d1>
movl   $0x1,-0x4(%rbp)
jmp    1507 <main+0x327>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x70(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1090 <pack_table@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xfe8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-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
push   %rax
lea    0xe61(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1100 <fopen@plt>
mov    $0x1,%r12d
test   %rax,%rax
je     1420 <main+0x220>
mov    %rax,%rbx
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
test   %rax,%rax
jne    1420 <main+0x220>
mov    %rbx,%rdi
call   10c0 <ftell@plt>
mov    %rax,%rbp
mov    0x2d82(%rip),%rax
cmp    (%rax),%rbp
je     1420 <main+0x220>
mov    %rbx,%rdi
call   10a0 <rewind@plt>
lea    0x1(%rbp),%rdi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1420 <main+0x220>
mov    %rax,%r14
mov    $0x1,%r12d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1060 <fread@plt>
cmp    %rbp,%rax
jne    1420 <main+0x220>
movb   $0x0,(%r14,%rbp,1)
lea    0xdcf(%rip),%rsi
lea    0xdc9(%rip),%rdx
mov    %r14,%rdi
call   10f0 <replace@plt>
lea    0xd38(%rip),%rsi
mov    %r14,%rdi
call   1120 <strstr@plt>
test   %rax,%rax
je     1420 <main+0x220>
mov    %rax,%r15
lea    0xd1d(%rip),%rdi
call   1080 <strlen@plt>
cltq
add    %rax,%r15
mov    %r15d,%edx
sub    %r14d,%edx
mov    0x2cd6(%rip),%r13
mov    0x0(%r13),%ecx
mov    $0x1,%r12d
mov    %r14,%rdi
mov    $0x1,%esi
call   1110 <fwrite@plt>
lea    0xd6f(%rip),%rdi
call   1050 <puts@plt>
lea    0xcfa(%rip),%rsi
mov    %r15,%rdi
call   1120 <strstr@plt>
test   %rax,%rax
je     1420 <main+0x220>
mov    %rax,%rbp
mov    %ebp,%edx
sub    %r15d,%edx
mov    0x0(%r13),%ecx
mov    $0x1,%r12d
mov    %r15,%rdi
mov    $0x1,%esi
call   1110 <fwrite@plt>
lea    0xdb4(%rip),%rdi
call   1050 <puts@plt>
lea    0xcd2(%rip),%rsi
mov    %rbp,%rdi
call   1120 <strstr@plt>
test   %rax,%rax
je     1420 <main+0x220>
mov    %rax,%rbp
lea    0xcb7(%rip),%r13
mov    %r13,%rdi
call   1080 <strlen@plt>
cltq
add    %rax,%rbp
lea    0xc88(%rip),%rsi
mov    %rbp,%rdi
mov    %r13,%rdx
call   10b0 <pack_table@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xc96(%rip),%rsi
mov    %r15,%rdi
call   1120 <strstr@plt>
test   %rax,%rax
je     1420 <main+0x220>
lea    0xc9b(%rip),%rsi
mov    %rax,%rdi
call   1120 <strstr@plt>
test   %rax,%rax
je     1420 <main+0x220>
mov    %rax,%rbp
lea    0xc84(%rip),%r15
mov    %r15,%rdi
call   1080 <strlen@plt>
cltq
add    %rax,%rbp
lea    0xc57(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
call   10b0 <pack_table@plt>
lea    0xc81(%rip),%rdi
xor    %r12d,%r12d
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c" .next_opcode:\0A\09mov\09ah,al\0A\00"
@.str.1 = [27 x i8] c" ; opcode table obviously\00"
@.str.2 = [15 x i8] c"opcode_table:\0A\00"
@.str.3 = [25 x i8] c" ; escaped opcode table\00"
@.str.4 = [18 x i8] c"opcode_table_0F:\0A\00"
@.str.5 = [11 x i8] c"decode.asm\00"
@.str.6 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@stdout = global i32 0
@.str.9 = [137 x i8] c" .loop:\0A\09mov\09cl,[rbx]\0A\09mov\09ch,[rbx]\0A\09shr\09cl,5\0A\09and\09ch,1Fh\0A\09inc\09cl\0A\09inc\09rbx\0A\09sub\09al,cl\0A\09jnc\09.loop\0A\09mov\09al,ch\0A\09lea\09rbx,[flags_table]\0A\00"
@.str.10 = [962 x i8] c" ; flags table indices\0A\0A T_NONE\09 = 0\0A T_MODRM\09 = 1\0A T_MODRM_IMM8\09 = 2\0A T_MODRM_IMM32\09 = 3\0A T_IMM8\09 = 4\0A T_IMM16\09 = 5\0A T_IMM16_IMM8\09 = 6\0A T_IMM32\09 = 7\0A T_REL_IMM8\09 = 8\0A T_REL_IMM32\09 = 9\0A T_GROUP_MODRM\09 = 10\0A T_GROUP_MODRM_IMM8 = 11\0A T_GROUP_MODRM_IMM32 = 12\0A T_ERROR_NONE\09 = 13\0A T_ERROR_MODRM\09 = 14\0A T_ERROR_IMM8\09 = 15\0A T_ERROR_IMM32_IMM16 = 16\0A T_MOFFS\09 = 17\0A T_PREFIX\09 = 18\0A T_0F\09\09 = 19\0A T_3BYTE\09 = 20\0A T_UNDEFINED\09 = 21\0A\0A ; flags table for grouping\0A\0Aflags_table:\0A\0A\09db\09C_NONE\0A\09db\09C_MODRM\0A\09db\09C_MODRM+C_IMM8\0A\09db\09C_MODRM+C_IMM32\0A\09db\09C_IMM8\0A\09db\09C_IMM16\0A\09db\09C_IMM16+C_IMM8\0A\09db\09C_IMM32\0A\09db\09C_REL+C_IMM8\0A\09db\09C_REL+C_IMM32\0A\09db\09C_GROUP+C_MODRM\0A\09db\09C_GROUP+C_MODRM+C_IMM8\0A\09db\09C_GROUP+C_MODRM+C_IMM32\0A\09db\09C_ERROR+C_NONE\0A\09db\09C_ERROR+C_MODRM\0A\09db\09C_ERROR+C_IMM8\0A\09db\09C_ERROR+C_IMM32+C_IMM16\0A\09db\09C_MOFFS\0A\09db\09C_PREFIX\0A\09db\09C_0F\0A\09db\09C_3BYTE\0A\09db\09C_UNDEFINED\0A\0A\00"
@.str.11 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8** %11
%12 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %0
store i32 1, i32* %1
br label %135
16: ; preds = %0
%17 = load i32*, i32** %6
%18 = load i32, i32* @SEEK_END
%19 = call i64 @fseek(i32* %17, i32 0, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %1
br label %135
22: ; preds = %16
%23 = load i32*, i32** %6
%24 = call i64 @ftell(i32* %23)
store i64 %24, i64* %5
%25 = load i64, i64* %5
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 1, i32* %1
br label %135
29: ; preds = %22
%30 = load i32*, i32** %6
%31 = call i32 @rewind(i32* %30)
%32 = load i64, i64* %5
%33 = add nsw i64 %32, 1
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %2
%35 = load i8*, i8** %2
%36 = icmp ne i8* %35, null
br i1 %36, label %38, label %37
37: ; preds = %29
store i32 1, i32* %1
br label %135
38: ; preds = %29
%39 = load i8*, i8** %2
%40 = load i64, i64* %5
%41 = load i32*, i32** %6
%42 = call i64 @fread(i8* %39, i32 1, i64 %40, i32* %41)
%43 = load i64, i64* %5
%44 = icmp ne i64 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %38
store i32 1, i32* %1
br label %135
46: ; preds = %38
%47 = load i8*, i8** %2
%48 = load i64, i64* %5
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %2
%51 = call i32 @replace(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%52 = load i8*, i8** %2
%53 = load i8*, i8** %7
%54 = call i8* @strstr(i8* %52, i8* %53)
store i8* %54, i8** %4
%55 = load i8*, i8** %4
%56 = icmp ne i8* %55, null
br i1 %56, label %58, label %57
57: ; preds = %46
store i32 1, i32* %1
br label %135
58: ; preds = %46
%59 = load i8*, i8** %4
%60 = load i8*, i8** %7
%61 = call i32 @strlen(i8* %60)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8* %63, i8** %3
%64 = load i8*, i8** %2
%65 = load i8*, i8** %3
%66 = load i8*, i8** %2
%67 = ptrtoint i8* %65 to i64
%68 = ptrtoint i8* %66 to i64
%69 = sub i64 %67, %68
%70 = trunc i64 %69 to i32
%71 = load i32, i32* @stdout
%72 = call i32 @fwrite(i8* %64, i32 1, i32 %70, i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.9, i64 0, i64 0))
%74 = load i8*, i8** %3
%75 = load i8*, i8** %8
%76 = call i8* @strstr(i8* %74, i8* %75)
store i8* %76, i8** %4
%77 = load i8*, i8** %4
%78 = icmp ne i8* %77, null
br i1 %78, label %80, label %79
79: ; preds = %58
store i32 1, i32* %1
br label %135
80: ; preds = %58
%81 = load i8*, i8** %3
%82 = load i8*, i8** %4
%83 = load i8*, i8** %3
%84 = ptrtoint i8* %82 to i64
%85 = ptrtoint i8* %83 to i64
%86 = sub i64 %84, %85
%87 = trunc i64 %86 to i32
%88 = load i32, i32* @stdout
%89 = call i32 @fwrite(i8* %81, i32 1, i32 %87, i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([962 x i8], [962 x i8]* @.str.10, i64 0, i64 0))
%91 = load i8*, i8** %4
%92 = load i8*, i8** %9
%93 = call i8* @strstr(i8* %91, i8* %92)
store i8* %93, i8** %4
%94 = load i8*, i8** %4
%95 = icmp ne i8* %94, null
br i1 %95, label %97, label %96
96: ; preds = %80
store i32 1, i32* %1
br label %135
97: ; preds = %80
%98 = load i8*, i8** %4
%99 = load i8*, i8** %9
%100 = call i32 @strlen(i8* %99)
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %98, i64 %101
%103 = load i8*, i8** %8
%104 = load i8*, i8** %9
%105 = call i8* @pack_table(i8* %102, i8* %103, i8* %104)
store i8* %105, i8** %4
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%107 = load i8*, i8** %3
%108 = load i8*, i8** %10
%109 = call i8* @strstr(i8* %107, i8* %108)
store i8* %109, i8** %4
%110 = load i8*, i8** %4
%111 = icmp ne i8* %110, null
br i1 %111, label %113, label %112
112: ; preds = %97
store i32 1, i32* %1
br label %135
113: ; preds = %97
%114 = load i8*, i8** %4
%115 = load i8*, i8** %11
%116 = call i8* @strstr(i8* %114, i8* %115)
store i8* %116, i8** %4
%117 = load i8*, i8** %4
%118 = icmp ne i8* %117, null
br i1 %118, label %120, label %119
119: ; preds = %113
store i32 1, i32* %1
br label %135
120: ; preds = %113
%121 = load i8*, i8** %4
%122 = load i8*, i8** %11
%123 = call i32 @strlen(i8* %122)
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %121, i64 %124
%126 = load i8*, i8** %10
%127 = load i8*, i8** %11
%128 = call i8* @pack_table(i8* %125, i8* %126, i8* %127)
store i8* %128, i8** %4
%129 = load i8*, i8** %4
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %129)
%131 = load i8*, i8** %2
%132 = call i32 @free(i8* %131)
%133 = load i32*, i32** %6
%134 = call i32 @fclose(i32* %133)
store i32 0, i32* %1
br label %135
135: ; preds = %120, %119, %112, %96, %79, %57, %45, %37, %28, %21, %15
%136 = load i32, i32* %1
ret i32 %136
}

LLVM IR (-O2):
@.str = [30 x i8] c" .next_opcode:\0A\09mov\09ah,al\0A\00"
@.str.1 = [27 x i8] c" ; opcode table obviously\00"
@.str.2 = [15 x i8] c"opcode_table:\0A\00"
@.str.3 = [25 x i8] c" ; escaped opcode table\00"
@.str.4 = [18 x i8] c"opcode_table_0F:\0A\00"
@.str.5 = [11 x i8] c"decode.asm\00"
@.str.6 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@stdout = global i32 0
@.str.11 = [3 x i8] c"%s\00"
@str = [136 x i8] c" .loop:\0A\09mov\09cl,[rbx]\0A\09mov\09ch,[rbx]\0A\09shr\09cl,5\0A\09and\09ch,1Fh\0A\09inc\09cl\0A\09inc\09rbx\0A\09sub\09al,cl\0A\09jnc\09.loop\0A\09mov\09al,ch\0A\09lea\09rbx,[flags_table]\00"
@str.12 = [961 x i8] c" ; flags table indices\0A\0A T_NONE\09 = 0\0A T_MODRM\09 = 1\0A T_MODRM_IMM8\09 = 2\0A T_MODRM_IMM32\09 = 3\0A T_IMM8\09 = 4\0A T_IMM16\09 = 5\0A T_IMM16_IMM8\09 = 6\0A T_IMM32\09 = 7\0A T_REL_IMM8\09 = 8\0A T_REL_IMM32\09 = 9\0A T_GROUP_MODRM\09 = 10\0A T_GROUP_MODRM_IMM8 = 11\0A T_GROUP_MODRM_IMM32 = 12\0A T_ERROR_NONE\09 = 13\0A T_ERROR_MODRM\09 = 14\0A T_ERROR_IMM8\09 = 15\0A T_ERROR_IMM32_IMM16 = 16\0A T_MOFFS\09 = 17\0A T_PREFIX\09 = 18\0A T_0F\09\09 = 19\0A T_3BYTE\09 = 20\0A T_UNDEFINED\09 = 21\0A\0A ; flags table for grouping\0A\0Aflags_table:\0A\0A\09db\09C_NONE\0A\09db\09C_MODRM\0A\09db\09C_MODRM+C_IMM8\0A\09db\09C_MODRM+C_IMM32\0A\09db\09C_IMM8\0A\09db\09C_IMM16\0A\09db\09C_IMM16+C_IMM8\0A\09db\09C_IMM32\0A\09db\09C_REL+C_IMM8\0A\09db\09C_REL+C_IMM32\0A\09db\09C_GROUP+C_MODRM\0A\09db\09C_GROUP+C_MODRM+C_IMM8\0A\09db\09C_GROUP+C_MODRM+C_IMM32\0A\09db\09C_ERROR+C_NONE\0A\09db\09C_ERROR+C_MODRM\0A\09db\09C_ERROR+C_IMM8\0A\09db\09C_ERROR+C_IMM32+C_IMM16\0A\09db\09C_MOFFS\0A\09db\09C_PREFIX\0A\09db\09C_0F\0A\09db\09C_3BYTE\0A\09db\09C_UNDEFINED\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %65, label %3
3: ; preds = %0
%4 = load i32, i32* @SEEK_END
%5 = tail call i64 @fseek(i32* %1, i32 0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %65
7: ; preds = %3
%8 = tail call i64 @ftell(i32* %1)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %65, label %11
11: ; preds = %7
%12 = tail call i32 @rewind(i32* %1)
%13 = add nsw i64 %8, 1
%14 = tail call i8* @malloc(i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %65, label %16
16: ; preds = %11
%17 = tail call i64 @fread(i8* %14, i32 1, i64 %8, i32* %1)
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %65
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %14, i64 %8
store i8 0, i8* %20
%21 = tail call i32 @replace(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%22 = tail call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %65, label %24
24: ; preds = %19
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = ptrtoint i8* %27 to i64
%29 = ptrtoint i8* %14 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = load i32, i32* @stdout
%33 = tail call i32 @fwrite(i8* %14, i32 1, i32 %31, i32 %32)
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([136 x i8], [136 x i8]* @str, i64 0, i64 0))
%35 = tail call i8* @strstr(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %65, label %37
37: ; preds = %24
%38 = ptrtoint i8* %35 to i64
%39 = sub i64 %38, %28
%40 = trunc i64 %39 to i32
%41 = load i32, i32* @stdout
%42 = tail call i32 @fwrite(i8* %27, i32 1, i32 %40, i32 %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([961 x i8], [961 x i8]* @str.12, i64 0, i64 0))
%44 = tail call i8* @strstr(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i8* %44, null
br i1 %45, label %65, label %46
46: ; preds = %37
%47 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %44, i64 %48
%50 = tail call i8* @pack_table(i8* %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%51 = tail call i32 @putchar(i32 10)
%52 = tail call i8* @strstr(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %65, label %54
54: ; preds = %46
%55 = tail call i8* @strstr(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp eq i8* %55, null
br i1 %56, label %65, label %57
57: ; preds = %54
%58 = tail call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
%61 = tail call i8* @pack_table(i8* %60, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %61)
%63 = tail call i32 @free(i8* %14)
%64 = tail call i32 @fclose(i32* %1)
br label %65
65: ; preds = %54, %46, %37, %24, %19, %16, %11, %7, %3, %0, %57
%66 = phi i32 [ 0, %57 ], [ 1, %0 ], [ 1, %3 ], [ 1, %7 ], [ 1, %11 ], [ 1, %16 ], [ 1, %19 ], [ 1, %24 ], [ 1, %37 ], [ 1, %46 ], [ 1, %54 ]
ret i32 %66
}