#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
char *calloc(int, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int run(char *fileName, int argc, char **argv) {
  char nameCopy[(80)];
  char *fileBuffer = NULL, *curPos = NULL, *bufEnd = NULL;
  FILE *inFile = NULL, *outFile = NULL;
  size_t fileSize = 0;
  if (strcmp(".vgz", &(fileName[strlen(fileName) - 4])) == 0) {
    perror(".vgz not supported\n");
    return EXIT_FAILURE;
  }
  strncpy(nameCopy, fileName, (80));
  strncpy(&(nameCopy[strlen(fileName) - 4]), "-ay.vgm", (80));
  inFile = fopen(fileName, "rb"), outFile = fopen(nameCopy, "wb");
  if (inFile == NULL || outFile == NULL) {
    perror("File cannot be opened.\n");
    return EXIT_FAILURE;
  }
  fseek(inFile, 0, SEEK_END);
  fileSize = ftell(inFile);
  fseek(inFile, 0, SEEK_SET);
  fileBuffer = calloc(sizeof(char), fileSize);
  if (fileBuffer == NULL) {
    perror("Cannot initialize file buffer.\n");
    return EXIT_FAILURE;
  }
  fread(fileBuffer, 1, fileSize, inFile);
  fclose(inFile);
  curPos = &(fileBuffer[0xE0]);
  bufEnd = &(fileBuffer[fileSize - 1]);
  while (curPos <= bufEnd) {
    size_t ptrInc;
    switch (curPos[0]) {
    case 0x55:
    case 0x56:
      ptrInc = 3;
      if (curPos[1] >= (char)0x00 && curPos[1] <= (char)0x0F) {
        char filterMe = 0;
        if (argc > 2)
          switch (argv[2][0]) {
          case '0':
            if (curPos[1] == 0x00 || curPos[1] == 0x01 || curPos[1] == 0x08)
              filterMe++;
            break;
          case '1':
            if (curPos[1] == 0x02 || curPos[1] == 0x03 || curPos[1] == 0x09)
              filterMe++;
            break;
          case '2':
            if (curPos[1] == 0x04 || curPos[1] == 0x05 || curPos[1] == 0x0A)
              filterMe++;
            break;
          default:
            filterMe++;
          }
        else
          filterMe++;
        if (!filterMe)
          break;
        curPos[0] = 0x61;
        curPos[1] = 0x00;
        curPos[2] = 0x00;
      }
      break;
    case 0x62:
    case 0x63:
      ptrInc = 1;
      break;
    case 0x57:
    case 0x61:
      ptrInc = 3;
      break;
    case 0x66:
      ptrInc = 1;
      curPos = (bufEnd);
      break;
    case 0x67:
      printf("DEBUG: Curr addr 0x%X\n", curPos - fileBuffer);
      ptrInc = ((*(int *)(curPos + 3)));
      printf("DEBUG: Offset Data Block 0x%X\n", ptrInc);
      curPos += ptrInc + 0x07;
      printf("DEBUG: New addr 0x%X\n", curPos - fileBuffer);
      ptrInc = 0;
      break;
    default:
      if (curPos[0] & 0x70)
        ptrInc = 1;
      else
        ptrInc = 3;
      break;
    }
    curPos += ptrInc;
  }
  fwrite(fileBuffer, 1, fileSize, outFile);
  fclose(outFile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
movq   $0x0,-0xa0(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xb8(%rbp),%rsi
sub    $0x4,%eax
cltq
add    %rax,%rsi
lea    0xe10(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1268 <run+0xa8>
lea    0xdff(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ed <run+0x52d>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x4,%eax
cltq
lea    -0x70(%rbp),%rdi
add    %rax,%rdi
lea    0xdcf(%rip),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x90(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xdae(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x90(%rbp)
je     12ea <run+0x12a>
cmpq   $0x0,-0x98(%rbp)
jne    1307 <run+0x147>
lea    0xd82(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ed <run+0x52d>
mov    -0x90(%rbp),%rdi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x90(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x90(%rbp),%rdi
mov    0x2c99(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0xa0(%rbp),%rsi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1385 <run+0x1c5>
lea    0xd1c(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ed <run+0x52d>
mov    -0x78(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
mov    -0x90(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x90(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x78(%rbp),%rax
add    $0xe0,%rax
mov    %rax,-0x80(%rbp)
mov    -0x78(%rbp),%rax
mov    -0xa0(%rbp),%rcx
sub    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rax
cmp    -0x88(%rbp),%rax
ja     16b9 <run+0x4f9>
mov    -0x80(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffab,%eax
mov    %eax,%ecx
mov    %rcx,-0xc0(%rbp)
sub    $0x12,%eax
ja     1672 <run+0x4b2>
mov    -0xc0(%rbp),%rax
lea    0xbf1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x3,-0xa8(%rbp)
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jl     15b9 <run+0x3f9>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0xf,%eax
jg     15b9 <run+0x3f9>
movb   $0x0,-0xa9(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    1582 <run+0x3c2>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0xc4(%rbp)
sub    $0x30,%eax
je     149d <run+0x2dd>
jmp    1475 <run+0x2b5>
mov    -0xc4(%rbp),%eax
sub    $0x31,%eax
je     14e3 <run+0x323>
jmp    1489 <run+0x2c9>
mov    -0xc4(%rbp),%eax
sub    $0x32,%eax
je     1529 <run+0x369>
jmp    156f <run+0x3af>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     14d0 <run+0x310>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x1,%eax
je     14d0 <run+0x310>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x8,%eax
jne    14de <run+0x31e>
mov    -0xa9(%rbp),%al
add    $0x1,%al
mov    %al,-0xa9(%rbp)
jmp    157d <run+0x3bd>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2,%eax
je     1516 <run+0x356>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3,%eax
je     1516 <run+0x356>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x9,%eax
jne    1524 <run+0x364>
mov    -0xa9(%rbp),%al
add    $0x1,%al
mov    %al,-0xa9(%rbp)
jmp    157d <run+0x3bd>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x4,%eax
je     155c <run+0x39c>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x5,%eax
je     155c <run+0x39c>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
jne    156a <run+0x3aa>
mov    -0xa9(%rbp),%al
add    $0x1,%al
mov    %al,-0xa9(%rbp)
jmp    157d <run+0x3bd>
mov    -0xa9(%rbp),%al
add    $0x1,%al
mov    %al,-0xa9(%rbp)
jmp    1590 <run+0x3d0>
mov    -0xa9(%rbp),%al
add    $0x1,%al
mov    %al,-0xa9(%rbp)
cmpb   $0x0,-0xa9(%rbp)
jne    15a2 <run+0x3e2>
jmp    16a5 <run+0x4e5>
mov    -0x80(%rbp),%rax
movb   $0x61,(%rax)
mov    -0x80(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x80(%rbp),%rax
movb   $0x0,0x2(%rax)
jmp    16a5 <run+0x4e5>
movq   $0x1,-0xa8(%rbp)
jmp    16a5 <run+0x4e5>
movq   $0x3,-0xa8(%rbp)
jmp    16a5 <run+0x4e5>
movq   $0x1,-0xa8(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    16a5 <run+0x4e5>
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xa9e(%rip),%rdi
call   1070 <printf@plt>
mov    -0x80(%rbp),%rax
movslq 0x3(%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
mov    %eax,%esi
lea    0xa91(%rip),%rdi
call   1070 <printf@plt>
mov    -0xa8(%rbp),%rax
add    $0x7,%rax
add    -0x80(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xa84(%rip),%rdi
call   1070 <printf@plt>
movq   $0x0,-0xa8(%rbp)
jmp    16a5 <run+0x4e5>
mov    -0x80(%rbp),%rax
movsbl (%rax),%eax
and    $0x70,%eax
cmp    $0x0,%eax
je     1695 <run+0x4d5>
movq   $0x1,-0xa8(%rbp)
jmp    16a0 <run+0x4e0>
movq   $0x3,-0xa8(%rbp)
jmp    16a5 <run+0x4e5>
mov    -0xa8(%rbp),%rax
add    -0x80(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    13d4 <run+0x214>
mov    -0x78(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
mov    -0x98(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x98(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x28e0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,0x18(%rsp)
mov    %esi,0x4(%rsp)
mov    %rdi,%rbx
call   1060 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe5c(%rip),%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     146c <run+0x2ac>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rax,%r12,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe39(%rip),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
lea    0xe30(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbp
lea    0xe21(%rip),%rsi
mov    %r12,%rdi
call   10c0 <fopen@plt>
test   %rbp,%rbp
je     1475 <run+0x2b5>
mov    %rax,%r14
test   %rax,%rax
je     1475 <run+0x2b5>
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbx
mov    0x2d47(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1080 <calloc@plt>
test   %rax,%rax
je     147e <run+0x2be>
mov    %rax,%r13
mov    %r14,0x10(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rax
mov    %rbx,0x8(%rsp)
lea    -0x1(%rbx),%rax
cmp    $0xe0,%rax
jge    1324 <run+0x164>
mov    %r13,%rdi
mov    $0x1,%esi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rbx
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rax
lea    (%rax,%r13,1),%r15
add    $0xffffffffffffffff,%r15
mov    %r13,%r14
add    $0xe0,%r14
lea    0xcbe(%rip),%r12
mov    $0x430,%ebx
jmp    135d <run+0x19d>
nopl   0x0(%rax)
mov    $0x3,%eax
add    %rax,%r14
cmp    %r15,%r14
ja     12ea <run+0x12a>
movsbl (%r14),%ecx
lea    -0x55(%rcx),%edx
cmp    $0x12,%edx
ja     13ca <run+0x20a>
mov    $0x1,%eax
movslq (%r12,%rdx,4),%rdx
add    %r12,%rdx
jmp    *%rdx
movzbl 0x1(%r14),%ecx
mov    $0x3,%eax
cmp    $0xf,%cl
ja     1355 <run+0x195>
cmpl   $0x3,0x4(%rsp)
jl     145c <run+0x29c>
mov    0x18(%rsp),%rdx
mov    0x10(%rdx),%rdx
movsbl (%rdx),%edx
cmp    $0x32,%edx
je     142a <run+0x26a>
cmp    $0x31,%edx
je     1441 <run+0x281>
cmp    $0x30,%edx
jne    145c <run+0x29c>
cmp    $0x8,%cl
ja     1355 <run+0x195>
movzbl %cl,%ecx
mov    $0x103,%edx
jmp    1452 <run+0x292>
xor    %eax,%eax
test   $0x70,%cl
sete   %al
add    %rax,%rax
add    $0x1,%rax
jmp    1355 <run+0x195>
mov    %r15,%r14
jmp    1355 <run+0x195>
mov    %r14d,%esi
sub    %r13d,%esi
lea    0xcb8(%rip),%rdi
call   1070 <printf@plt>
movslq 0x3(%r14),%rbp
lea    0xcbf(%rip),%rdi
mov    %ebp,%esi
call   1070 <printf@plt>
add    %rbp,%r14
add    $0x7,%r14
mov    %r14d,%esi
sub    %r13d,%esi
lea    0xcc3(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
jmp    1355 <run+0x195>
cmp    $0xa,%cl
ja     1355 <run+0x195>
movzbl %cl,%ecx
bt     %rcx,%rbx
jb     145c <run+0x29c>
jmp    1355 <run+0x195>
cmp    $0x9,%cl
ja     1355 <run+0x195>
movzbl %cl,%ecx
mov    $0x20c,%edx
bt     %rcx,%rdx
jae    1355 <run+0x195>
movw   $0x61,(%r14)
movb   $0x0,0x2(%r14)
jmp    1355 <run+0x195>
lea    0xbde(%rip),%rdi
jmp    1485 <run+0x2c5>
lea    0xbf7(%rip),%rdi
jmp    1485 <run+0x2c5>
lea    0xc06(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b3f(%rip),%rax
jmp    1313 <run+0x153>

LLVM IR (-O0):
@.str = [5 x i8] c".vgz\00"
@.str.1 = [20 x i8] c".vgz not supported\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"-ay.vgm\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"File cannot be opened.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [32 x i8] c"Cannot initialize file buffer.\0A\00"
@.str.7 = [23 x i8] c"DEBUG: Curr addr 0x%X\0A\00"
@.str.8 = [31 x i8] c"DEBUG: Offset Data Block 0x%X\0A\00"
@.str.9 = [22 x i8] c"DEBUG: New addr 0x%X\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @run(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca [80 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i8* null, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i32* null, i32** %12
store i32* null, i32** %13
store i64 0, i64* %14
%17 = load i8*, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %4
br label %248
28: ; preds = %3
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = call i32 @strncpy(i8* %29, i8* %30, i32 80)
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 %33, 4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %35
%37 = call i32 @strncpy(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 80)
%38 = load i8*, i8** %5
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %12
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %13
%42 = load i32*, i32** %12
%43 = icmp eq i32* %42, null
br i1 %43, label %47, label %44
44: ; preds = %28
%45 = load i32*, i32** %13
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44, %28
%48 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
store i32 %49, i32* %4
br label %248
50: ; preds = %44
%51 = load i32*, i32** %12
%52 = load i32, i32* @SEEK_END
%53 = call i32 @fseek(i32* %51, i32 0, i32 %52)
%54 = load i32*, i32** %12
%55 = call i64 @ftell(i32* %54)
store i64 %55, i64* %14
%56 = load i32*, i32** %12
%57 = load i32, i32* @SEEK_SET
%58 = call i32 @fseek(i32* %56, i32 0, i32 %57)
%59 = load i64, i64* %14
%60 = call i8* @calloc(i32 1, i64 %59)
store i8* %60, i8** %9
%61 = load i8*, i8** %9
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %50
%64 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %4
br label %248
66: ; preds = %50
%67 = load i8*, i8** %9
%68 = load i64, i64* %14
%69 = load i32*, i32** %12
%70 = call i32 @fread(i8* %67, i32 1, i64 %68, i32* %69)
%71 = load i32*, i32** %12
%72 = call i32 @fclose(i32* %71)
%73 = load i8*, i8** %9
%74 = getelementptr inbounds i8, i8* %73, i64 224
store i8* %74, i8** %10
%75 = load i8*, i8** %9
%76 = load i64, i64* %14
%77 = sub i64 %76, 1
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8* %78, i8** %11
br label %79
79: ; preds = %236, %66
%80 = load i8*, i8** %10
%81 = load i8*, i8** %11
%82 = icmp ule i8* %80, %81
br i1 %82, label %83, label %240
83: ; preds = %79
%84 = load i8*, i8** %10
%85 = getelementptr inbounds i8, i8* %84, i64 0
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
switch i32 %87, label %226 [
i32 85, label %88
i32 86, label %88
i32 98, label %195
i32 99, label %195
i32 87, label %196
i32 97, label %196
i32 102, label %197
i32 103, label %199
]
88: ; preds = %83, %83
store i64 3, i64* %15
%89 = load i8*, i8** %10
%90 = getelementptr inbounds i8, i8* %89, i64 1
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp sge i32 %92, 0
br i1 %93, label %94, label %194
94: ; preds = %88
%95 = load i8*, i8** %10
%96 = getelementptr inbounds i8, i8* %95, i64 1
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp sle i32 %98, 15
br i1 %99, label %100, label %194
100: ; preds = %94
store i8 0, i8* %16
%101 = load i32, i32* %6
%102 = icmp sgt i32 %101, 2
br i1 %102, label %103, label %180
103: ; preds = %100
%104 = load i8**, i8*** %7
%105 = getelementptr inbounds i8*, i8** %104, i64 2
%106 = load i8*, i8** %105
%107 = getelementptr inbounds i8, i8* %106, i64 0
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
switch i32 %109, label %176 [
i32 48, label %110
i32 49, label %132
i32 50, label %154
]
110: ; preds = %103
%111 = load i8*, i8** %10
%112 = getelementptr inbounds i8, i8* %111, i64 1
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = icmp eq i32 %114, 0
br i1 %115, label %128, label %116
116: ; preds = %110
%117 = load i8*, i8** %10
%118 = getelementptr inbounds i8, i8* %117, i64 1
%119 = load i8, i8* %118
%120 = sext i8 %119 to i32
%121 = icmp eq i32 %120, 1
br i1 %121, label %128, label %122
122: ; preds = %116
%123 = load i8*, i8** %10
%124 = getelementptr inbounds i8, i8* %123, i64 1
%125 = load i8, i8* %124
%126 = sext i8 %125 to i32
%127 = icmp eq i32 %126, 8
br i1 %127, label %128, label %131
128: ; preds = %122, %116, %110
%129 = load i8, i8* %16
%130 = add i8 %129, 1
store i8 %130, i8* %16
br label %131
131: ; preds = %128, %122
br label %179
132: ; preds = %103
%133 = load i8*, i8** %10
%134 = getelementptr inbounds i8, i8* %133, i64 1
%135 = load i8, i8* %134
%136 = sext i8 %135 to i32
%137 = icmp eq i32 %136, 2
br i1 %137, label %150, label %138
138: ; preds = %132
%139 = load i8*, i8** %10
%140 = getelementptr inbounds i8, i8* %139, i64 1
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
%143 = icmp eq i32 %142, 3
br i1 %143, label %150, label %144
144: ; preds = %138
%145 = load i8*, i8** %10
%146 = getelementptr inbounds i8, i8* %145, i64 1
%147 = load i8, i8* %146
%148 = sext i8 %147 to i32
%149 = icmp eq i32 %148, 9
br i1 %149, label %150, label %153
150: ; preds = %144, %138, %132
%151 = load i8, i8* %16
%152 = add i8 %151, 1
store i8 %152, i8* %16
br label %153
153: ; preds = %150, %144
br label %179
154: ; preds = %103
%155 = load i8*, i8** %10
%156 = getelementptr inbounds i8, i8* %155, i64 1
%157 = load i8, i8* %156
%158 = sext i8 %157 to i32
%159 = icmp eq i32 %158, 4
br i1 %159, label %172, label %160
160: ; preds = %154
%161 = load i8*, i8** %10
%162 = getelementptr inbounds i8, i8* %161, i64 1
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = icmp eq i32 %164, 5
br i1 %165, label %172, label %166
166: ; preds = %160
%167 = load i8*, i8** %10
%168 = getelementptr inbounds i8, i8* %167, i64 1
%169 = load i8, i8* %168
%170 = sext i8 %169 to i32
%171 = icmp eq i32 %170, 10
br i1 %171, label %172, label %175
172: ; preds = %166, %160, %154
%173 = load i8, i8* %16
%174 = add i8 %173, 1
store i8 %174, i8* %16
br label %175
175: ; preds = %172, %166
br label %179
176: ; preds = %103
%177 = load i8, i8* %16
%178 = add i8 %177, 1
store i8 %178, i8* %16
br label %179
179: ; preds = %176, %175, %153, %131
br label %183
180: ; preds = %100
%181 = load i8, i8* %16
%182 = add i8 %181, 1
store i8 %182, i8* %16
br label %183
183: ; preds = %180, %179
%184 = load i8, i8* %16
%185 = icmp ne i8 %184, 0
br i1 %185, label %187, label %186
186: ; preds = %183
br label %236
187: ; preds = %183
%188 = load i8*, i8** %10
%189 = getelementptr inbounds i8, i8* %188, i64 0
store i8 97, i8* %189
%190 = load i8*, i8** %10
%191 = getelementptr inbounds i8, i8* %190, i64 1
store i8 0, i8* %191
%192 = load i8*, i8** %10
%193 = getelementptr inbounds i8, i8* %192, i64 2
store i8 0, i8* %193
br label %194
194: ; preds = %187, %94, %88
br label %236
195: ; preds = %83, %83
store i64 1, i64* %15
br label %236
196: ; preds = %83, %83
store i64 3, i64* %15
br label %236
197: ; preds = %83
store i64 1, i64* %15
%198 = load i8*, i8** %11
store i8* %198, i8** %10
br label %236
199: ; preds = %83
%200 = load i8*, i8** %10
%201 = load i8*, i8** %9
%202 = ptrtoint i8* %200 to i64
%203 = ptrtoint i8* %201 to i64
%204 = sub i64 %202, %203
%205 = trunc i64 %204 to i32
%206 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %205)
%207 = load i8*, i8** %10
%208 = getelementptr inbounds i8, i8* %207, i64 3
%209 = bitcast i8* %208 to i32*
%210 = load i32, i32* %209
%211 = sext i32 %210 to i64
store i64 %211, i64* %15
%212 = load i64, i64* %15
%213 = trunc i64 %212 to i32
%214 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %213)
%215 = load i64, i64* %15
%216 = add i64 %215, 7
%217 = load i8*, i8** %10
%218 = getelementptr inbounds i8, i8* %217, i64 %216
store i8* %218, i8** %10
%219 = load i8*, i8** %10
%220 = load i8*, i8** %9
%221 = ptrtoint i8* %219 to i64
%222 = ptrtoint i8* %220 to i64
%223 = sub i64 %221, %222
%224 = trunc i64 %223 to i32
%225 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %224)
store i64 0, i64* %15
br label %236
226: ; preds = %83
%227 = load i8*, i8** %10
%228 = getelementptr inbounds i8, i8* %227, i64 0
%229 = load i8, i8* %228
%230 = sext i8 %229 to i32
%231 = and i32 %230, 112
%232 = icmp ne i32 %231, 0
br i1 %232, label %233, label %234
233: ; preds = %226
store i64 1, i64* %15
br label %235
234: ; preds = %226
store i64 3, i64* %15
br label %235
235: ; preds = %234, %233
br label %236
236: ; preds = %235, %199, %197, %196, %195, %194, %186
%237 = load i64, i64* %15
%238 = load i8*, i8** %10
%239 = getelementptr inbounds i8, i8* %238, i64 %237
store i8* %239, i8** %10
br label %79
240: ; preds = %79
%241 = load i8*, i8** %9
%242 = load i64, i64* %14
%243 = load i32*, i32** %13
%244 = call i32 @fwrite(i8* %241, i32 1, i64 %242, i32* %243)
%245 = load i32*, i32** %13
%246 = call i32 @fclose(i32* %245)
%247 = load i32, i32* @EXIT_SUCCESS
store i32 %247, i32* %4
br label %248
248: ; preds = %240, %63, %47, %25
%249 = load i32, i32* %4
ret i32 %249
}

LLVM IR (-O2):
@.str = [5 x i8] c".vgz\00"
@.str.1 = [20 x i8] c".vgz not supported\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"-ay.vgm\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"File cannot be opened.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [32 x i8] c"Cannot initialize file buffer.\0A\00"
@.str.7 = [23 x i8] c"DEBUG: Curr addr 0x%X\0A\00"
@.str.8 = [31 x i8] c"DEBUG: Offset Data Block 0x%X\0A\00"
@.str.9 = [22 x i8] c"DEBUG: New addr 0x%X\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @run(i8* %0, i32 %1, i8** nocapture %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %97
14: ; preds = %3
%15 = call i32 @strncpy(i8* %5, i8* %0, i32 80)
%16 = call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, -4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %18
%20 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 80)
%21 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32* %21, null
%24 = icmp eq i32* %22, null
%25 = or i1 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %97
28: ; preds = %14
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %21, i32 0, i32 %29)
%31 = call i64 @ftell(i32* %21)
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %21, i32 0, i32 %32)
%34 = call i8* @calloc(i32 1, i64 %31)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %97
38: ; preds = %28
%39 = call i32 @fread(i8* %34, i32 1, i64 %31, i32* %21)
%40 = call i32 @fclose(i32* %21)
%41 = add i64 %31, -1
%42 = getelementptr inbounds i8, i8* %34, i64 %41
%43 = icmp slt i64 %41, 224
br i1 %43, label %94, label %44
44: ; preds = %38
%45 = getelementptr inbounds i8, i8* %34, i64 224
%46 = ptrtoint i8* %34 to i64
%47 = icmp sgt i32 %1, 2
%48 = getelementptr inbounds i8*, i8** %2, i64 2
br label %49
49: ; preds = %44, %89
%50 = phi i8* [ %45, %44 ], [ %92, %89 ]
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
switch i32 %52, label %85 [
i32 85, label %53
i32 86, label %53
i32 98, label %89
i32 99, label %89
i32 87, label %67
i32 97, label %67
i32 102, label %68
i32 103, label %69
]
53: ; preds = %49, %49
%54 = getelementptr inbounds i8, i8* %50, i64 1
%55 = load i8, i8* %54
%56 = icmp ult i8 %55, 16
br i1 %56, label %57, label %89
57: ; preds = %53
br i1 %47, label %58, label %65
58: ; preds = %57
%59 = load i8*, i8** %48
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
switch i32 %61, label %65 [
i32 48, label %62
i32 49, label %63
i32 50, label %64
]
62: ; preds = %58
switch i8 %55, label %89 [
i8 0, label %65
i8 1, label %65
i8 8, label %65
]
63: ; preds = %58
switch i8 %55, label %89 [
i8 2, label %65
i8 3, label %65
i8 9, label %65
]
64: ; preds = %58
switch i8 %55, label %89 [
i8 4, label %65
i8 5, label %65
i8 10, label %65
]
65: ; preds = %64, %64, %64, %63, %63, %63, %62, %62, %62, %58, %57
store i8 97, i8* %50
store i8 0, i8* %54
%66 = getelementptr inbounds i8, i8* %50, i64 2
store i8 0, i8* %66
br label %89
67: ; preds = %49, %49
br label %89
68: ; preds = %49
br label %89
69: ; preds = %49
%70 = ptrtoint i8* %50 to i64
%71 = sub i64 %70, %46
%72 = trunc i64 %71 to i32
%73 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %72)
%74 = getelementptr inbounds i8, i8* %50, i64 3
%75 = bitcast i8* %74 to i32*
%76 = load i32, i32* %75
%77 = sext i32 %76 to i64
%78 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %76)
%79 = add nsw i64 %77, 7
%80 = getelementptr inbounds i8, i8* %50, i64 %79
%81 = ptrtoint i8* %80 to i64
%82 = sub i64 %81, %46
%83 = trunc i64 %82 to i32
%84 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %83)
br label %89
85: ; preds = %49
%86 = and i32 %52, 112
%87 = icmp eq i32 %86, 0
%88 = select i1 %87, i64 3, i64 1
br label %89
89: ; preds = %64, %63, %62, %85, %49, %49, %65, %53, %69, %68, %67
%90 = phi i8* [ %80, %69 ], [ %42, %68 ], [ %50, %67 ], [ %50, %53 ], [ %50, %65 ], [ %50, %49 ], [ %50, %49 ], [ %50, %85 ], [ %50, %62 ], [ %50, %63 ], [ %50, %64 ]
%91 = phi i64 [ 0, %69 ], [ 1, %68 ], [ 3, %67 ], [ 3, %53 ], [ 3, %65 ], [ 1, %49 ], [ 1, %49 ], [ %88, %85 ], [ 3, %62 ], [ 3, %63 ], [ 3, %64 ]
%92 = getelementptr inbounds i8, i8* %90, i64 %91
%93 = icmp ugt i8* %92, %42
br i1 %93, label %94, label %49
94: ; preds = %89, %38
%95 = call i32 @fwrite(i8* %34, i32 1, i64 %31, i32* %22)
%96 = call i32 @fclose(i32* %22)
br label %97
97: ; preds = %94, %36, %26, %12
%98 = phi i32* [ @EXIT_FAILURE, %12 ], [ @EXIT_FAILURE, %26 ], [ @EXIT_FAILURE, %36 ], [ @EXIT_SUCCESS, %94 ]
%99 = load i32, i32* %98
ret i32 %99
}