#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*/ fputc(char, int /*<<< orphan*/ *);
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, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int);
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) {
  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]), "-ym2612.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);
  memset(&fileBuffer[0x60], 0x204CC00, 4);
  memset(&fileBuffer[0x50], 0, 4);
  fwrite(fileBuffer, 1, 0x80, outFile);
  curPos = &(fileBuffer[0x80]);
  bufEnd = &(fileBuffer[fileSize - 1]);
  while (curPos <= bufEnd) {
    size_t ptrInc;
    switch (curPos[0]) {
    case 0x5A:
      fputc(0xD0, outFile);
      fputc(0x01, outFile);
      fputc(curPos[1], outFile);
      fputc(curPos[2], outFile);
      ptrInc = 3;
      break;
    case 0x62:
    case 0x63:
      ptrInc = 1;
      fputc(curPos[0], outFile);
      break;
    case 0x61:
      ptrInc = 3;
      fwrite(curPos, 1, 3, outFile);
      break;
    case 0x66:
      ptrInc = 1;
      curPos = (bufEnd);
      fputc(0x66, outFile);
      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;
        fputc(curPos[0], outFile);
      } else {
        ptrInc = 3;
        fwrite(curPos, 1, 3, outFile);
      }
      break;
    }
    curPos += ptrInc;
  }
  fclose(outFile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xa0(%rbp),%rsi
sub    $0x4,%eax
cltq
add    %rax,%rsi
lea    0xde9(%rip),%rdi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    127b <run+0x9b>
lea    0xdd8(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1632 <run+0x452>
lea    -0x60(%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    -0x60(%rbp),%rdi
add    %rax,%rdi
lea    0xda8(%rip),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     12f7 <run+0x117>
cmpq   $0x0,-0x88(%rbp)
jne    1314 <run+0x134>
lea    0xd65(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1632 <run+0x452>
mov    -0x80(%rbp),%rdi
mov    0x2cc9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x80(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %rax,-0x90(%rbp)
mov    -0x80(%rbp),%rdi
mov    0x2c95(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x90(%rbp),%rsi
mov    $0x1,%edi
call   10a0 <calloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1389 <run+0x1a9>
lea    0xd08(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1632 <run+0x452>
mov    -0x68(%rbp),%rdi
mov    -0x90(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x80(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x68(%rbp),%rdi
add    $0x60,%rdi
mov    $0x204cc00,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    -0x68(%rbp),%rdi
add    $0x50,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    -0x68(%rbp),%rdi
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1100 <fwrite@plt>
mov    -0x68(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rax
mov    -0x90(%rbp),%rcx
sub    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
cmp    -0x78(%rbp),%rax
ja     161a <run+0x43a>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffa6,%eax
mov    %eax,%ecx
mov    %rcx,-0xa8(%rbp)
sub    $0xd,%eax
ja     15a4 <run+0x3c4>
mov    -0xa8(%rbp),%rax
lea    0xbb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x88(%rbp),%rsi
mov    $0xffffffd0,%edi
call   1090 <fputc@plt>
mov    -0x88(%rbp),%rsi
mov    $0x1,%edi
call   1090 <fputc@plt>
mov    -0x70(%rbp),%rax
mov    0x1(%rax),%al
mov    -0x88(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
mov    -0x70(%rbp),%rax
mov    0x2(%rax),%al
mov    -0x88(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
movq   $0x3,-0x98(%rbp)
jmp    1606 <run+0x426>
movq   $0x1,-0x98(%rbp)
mov    -0x70(%rbp),%rax
mov    (%rax),%al
mov    -0x88(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
jmp    1606 <run+0x426>
movq   $0x3,-0x98(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1100 <fwrite@plt>
jmp    1606 <run+0x426>
movq   $0x1,-0x98(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x88(%rbp),%rsi
mov    $0x66,%edi
call   1090 <fputc@plt>
jmp    1606 <run+0x426>
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xb5c(%rip),%rdi
call   1070 <printf@plt>
mov    -0x70(%rbp),%rax
movslq 0x3(%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %eax,%esi
lea    0xb4f(%rip),%rdi
call   1070 <printf@plt>
mov    -0x98(%rbp),%rax
add    $0x7,%rax
add    -0x70(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xb42(%rip),%rdi
call   1070 <printf@plt>
movq   $0x0,-0x98(%rbp)
jmp    1606 <run+0x426>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
and    $0x70,%eax
cmp    $0x0,%eax
je     15dc <run+0x3fc>
movq   $0x1,-0x98(%rbp)
mov    -0x70(%rbp),%rax
mov    (%rax),%al
mov    -0x88(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
jmp    1601 <run+0x421>
movq   $0x3,-0x98(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1100 <fwrite@plt>
jmp    1606 <run+0x426>
mov    -0x98(%rbp),%rax
add    -0x70(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    1414 <run+0x234>
mov    -0x88(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x299b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
call   1060 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe31(%rip),%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     143f <run+0x25f>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe10(%rip),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbp
lea    0xdfc(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rbp,%rbp
je     1448 <run+0x268>
mov    %rax,%r12
test   %rax,%rax
je     1448 <run+0x268>
mov    0x2d60(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %rbp,%rdi
call   10c0 <ftell@plt>
mov    %rax,%rbx
mov    0x2d32(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   10a0 <calloc@plt>
test   %rax,%rax
je     1451 <run+0x271>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0x60(%r14),%rdi
mov    $0x204cc00,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
lea    0x50(%r14),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r12,%rcx
call   1100 <fwrite@plt>
lea    -0x1(%rbx),%rax
cmp    $0x80,%rax
jge    134a <run+0x16a>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    (%r14,%rbx,1),%r13
add    $0xffffffffffffffff,%r13
mov    %r14,%rbx
sub    $0xffffffffffffff80,%rbx
lea    0xca0(%rip),%rbp
jmp    137d <run+0x19d>
test   $0x70,%dil
je     13c6 <run+0x1e6>
mov    %r12,%rsi
call   1090 <fputc@plt>
mov    $0x1,%eax
add    %rax,%rbx
cmp    %r13,%rbx
ja     132a <run+0x14a>
movsbl (%rbx),%edi
lea    -0x5a(%rdi),%eax
cmp    $0xd,%eax
ja     1362 <run+0x182>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    $0xffffffd0,%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
mov    $0x1,%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
movsbl 0x1(%rbx),%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
movsbl 0x2(%rbx),%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
jmp    13db <run+0x1fb>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r12,%rcx
call   1100 <fwrite@plt>
mov    $0x3,%eax
jmp    1375 <run+0x195>
mov    $0x66,%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
mov    $0x1,%eax
mov    %r13,%rbx
jmp    1375 <run+0x195>
mov    %ebx,%esi
sub    %r14d,%esi
lea    0xc93(%rip),%rdi
call   1070 <printf@plt>
movslq 0x3(%rbx),%r15
lea    0xc9a(%rip),%rdi
mov    %r15d,%esi
call   1070 <printf@plt>
add    %r15,%rbx
add    $0x7,%rbx
mov    %ebx,%esi
sub    %r14d,%esi
lea    0xc9e(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
jmp    1375 <run+0x195>
lea    0xbf7(%rip),%rdi
jmp    1458 <run+0x278>
lea    0xc14(%rip),%rdi
jmp    1458 <run+0x278>
lea    0xc23(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2b6c(%rip),%rax
jmp    1339 <run+0x159>

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 = [12 x i8] c"-ym2612.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) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [80 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %3
store i8* null, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32* null, i32** %8
store i32* null, i32** %9
store i64 0, i64* %10
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %2
br label %174
23: ; preds = %1
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32 @strncpy(i8* %24, i8* %25, i32 80)
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %30
%32 = call i32 @strncpy(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 80)
%33 = load i8*, i8** %3
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %8
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %9
%37 = load i32*, i32** %8
%38 = icmp eq i32* %37, null
br i1 %38, label %42, label %39
39: ; preds = %23
%40 = load i32*, i32** %9
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39, %23
%43 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %2
br label %174
45: ; preds = %39
%46 = load i32*, i32** %8
%47 = load i32, i32* @SEEK_END
%48 = call i32 @fseek(i32* %46, i32 0, i32 %47)
%49 = load i32*, i32** %8
%50 = call i64 @ftell(i32* %49)
store i64 %50, i64* %10
%51 = load i32*, i32** %8
%52 = load i32, i32* @SEEK_SET
%53 = call i32 @fseek(i32* %51, i32 0, i32 %52)
%54 = load i64, i64* %10
%55 = call i8* @calloc(i32 1, i64 %54)
store i8* %55, i8** %5
%56 = load i8*, i8** %5
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %45
%59 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
store i32 %60, i32* %2
br label %174
61: ; preds = %45
%62 = load i8*, i8** %5
%63 = load i64, i64* %10
%64 = load i32*, i32** %8
%65 = call i32 @fread(i8* %62, i32 1, i64 %63, i32* %64)
%66 = load i32*, i32** %8
%67 = call i32 @fclose(i32* %66)
%68 = load i8*, i8** %5
%69 = getelementptr inbounds i8, i8* %68, i64 96
%70 = call i32 @memset(i8* %69, i32 33868800, i32 4)
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i64 80
%73 = call i32 @memset(i8* %72, i32 0, i32 4)
%74 = load i8*, i8** %5
%75 = load i32*, i32** %9
%76 = call i32 @fwrite(i8* %74, i32 1, i32 128, i32* %75)
%77 = load i8*, i8** %5
%78 = getelementptr inbounds i8, i8* %77, i64 128
store i8* %78, i8** %6
%79 = load i8*, i8** %5
%80 = load i64, i64* %10
%81 = sub i64 %80, 1
%82 = getelementptr inbounds i8, i8* %79, i64 %81
store i8* %82, i8** %7
br label %83
83: ; preds = %166, %61
%84 = load i8*, i8** %6
%85 = load i8*, i8** %7
%86 = icmp ule i8* %84, %85
br i1 %86, label %87, label %170
87: ; preds = %83
%88 = load i8*, i8** %6
%89 = getelementptr inbounds i8, i8* %88, i64 0
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
switch i32 %91, label %148 [
i32 90, label %92
i32 98, label %107
i32 99, label %107
i32 97, label %113
i32 102, label %117
i32 103, label %121
]
92: ; preds = %87
%93 = load i32*, i32** %9
%94 = call i32 @fputc(i8 signext -48, i32* %93)
%95 = load i32*, i32** %9
%96 = call i32 @fputc(i8 signext 1, i32* %95)
%97 = load i8*, i8** %6
%98 = getelementptr inbounds i8, i8* %97, i64 1
%99 = load i8, i8* %98
%100 = load i32*, i32** %9
%101 = call i32 @fputc(i8 signext %99, i32* %100)
%102 = load i8*, i8** %6
%103 = getelementptr inbounds i8, i8* %102, i64 2
%104 = load i8, i8* %103
%105 = load i32*, i32** %9
%106 = call i32 @fputc(i8 signext %104, i32* %105)
store i64 3, i64* %11
br label %166
107: ; preds = %87, %87
store i64 1, i64* %11
%108 = load i8*, i8** %6
%109 = getelementptr inbounds i8, i8* %108, i64 0
%110 = load i8, i8* %109
%111 = load i32*, i32** %9
%112 = call i32 @fputc(i8 signext %110, i32* %111)
br label %166
113: ; preds = %87
store i64 3, i64* %11
%114 = load i8*, i8** %6
%115 = load i32*, i32** %9
%116 = call i32 @fwrite(i8* %114, i32 1, i32 3, i32* %115)
br label %166
117: ; preds = %87
store i64 1, i64* %11
%118 = load i8*, i8** %7
store i8* %118, i8** %6
%119 = load i32*, i32** %9
%120 = call i32 @fputc(i8 signext 102, i32* %119)
br label %166
121: ; preds = %87
%122 = load i8*, i8** %6
%123 = load i8*, i8** %5
%124 = ptrtoint i8* %122 to i64
%125 = ptrtoint i8* %123 to i64
%126 = sub i64 %124, %125
%127 = trunc i64 %126 to i32
%128 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %127)
%129 = load i8*, i8** %6
%130 = getelementptr inbounds i8, i8* %129, i64 3
%131 = bitcast i8* %130 to i32*
%132 = load i32, i32* %131
%133 = sext i32 %132 to i64
store i64 %133, i64* %11
%134 = load i64, i64* %11
%135 = trunc i64 %134 to i32
%136 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %135)
%137 = load i64, i64* %11
%138 = add i64 %137, 7
%139 = load i8*, i8** %6
%140 = getelementptr inbounds i8, i8* %139, i64 %138
store i8* %140, i8** %6
%141 = load i8*, i8** %6
%142 = load i8*, i8** %5
%143 = ptrtoint i8* %141 to i64
%144 = ptrtoint i8* %142 to i64
%145 = sub i64 %143, %144
%146 = trunc i64 %145 to i32
%147 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %146)
store i64 0, i64* %11
br label %166
148: ; preds = %87
%149 = load i8*, i8** %6
%150 = getelementptr inbounds i8, i8* %149, i64 0
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = and i32 %152, 112
%154 = icmp ne i32 %153, 0
br i1 %154, label %155, label %161
155: ; preds = %148
store i64 1, i64* %11
%156 = load i8*, i8** %6
%157 = getelementptr inbounds i8, i8* %156, i64 0
%158 = load i8, i8* %157
%159 = load i32*, i32** %9
%160 = call i32 @fputc(i8 signext %158, i32* %159)
br label %165
161: ; preds = %148
store i64 3, i64* %11
%162 = load i8*, i8** %6
%163 = load i32*, i32** %9
%164 = call i32 @fwrite(i8* %162, i32 1, i32 3, i32* %163)
br label %165
165: ; preds = %161, %155
br label %166
166: ; preds = %165, %121, %117, %113, %107, %92
%167 = load i64, i64* %11
%168 = load i8*, i8** %6
%169 = getelementptr inbounds i8, i8* %168, i64 %167
store i8* %169, i8** %6
br label %83
170: ; preds = %83
%171 = load i32*, i32** %9
%172 = call i32 @fclose(i32* %171)
%173 = load i32, i32* @EXIT_SUCCESS
store i32 %173, i32* %2
br label %174
174: ; preds = %170, %58, %42, %20
%175 = load i32, i32* %2
ret i32 %175
}

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 = [12 x i8] c"-ym2612.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) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, -4
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %99
12: ; preds = %1
%13 = call i32 @strncpy(i8* %3, i8* %0, i32 80)
%14 = call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, -4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %16
%18 = call i32 @strncpy(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 80)
%19 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %19, null
%22 = icmp eq i32* %20, null
%23 = or i1 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %99
26: ; preds = %12
%27 = load i32, i32* @SEEK_END
%28 = call i32 @fseek(i32* %19, i32 0, i32 %27)
%29 = call i64 @ftell(i32* %19)
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %19, i32 0, i32 %30)
%32 = call i8* @calloc(i32 1, i64 %29)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %99
36: ; preds = %26
%37 = call i32 @fread(i8* %32, i32 1, i64 %29, i32* %19)
%38 = call i32 @fclose(i32* %19)
%39 = getelementptr inbounds i8, i8* %32, i64 96
%40 = call i32 @memset(i8* %39, i32 33868800, i32 4)
%41 = getelementptr inbounds i8, i8* %32, i64 80
%42 = call i32 @memset(i8* %41, i32 0, i32 4)
%43 = call i32 @fwrite(i8* %32, i32 1, i32 128, i32* %20)
%44 = add i64 %29, -1
%45 = getelementptr inbounds i8, i8* %32, i64 %44
%46 = icmp slt i64 %44, 128
br i1 %46, label %97, label %47
47: ; preds = %36
%48 = getelementptr inbounds i8, i8* %32, i64 128
%49 = ptrtoint i8* %32 to i64
br label %50
50: ; preds = %47, %92
%51 = phi i8* [ %48, %47 ], [ %95, %92 ]
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
switch i32 %53, label %85 [
i32 90, label %54
i32 98, label %63
i32 99, label %63
i32 97, label %65
i32 102, label %67
i32 103, label %69
]
54: ; preds = %50
%55 = call i32 @fputc(i8 signext -48, i32* %20)
%56 = call i32 @fputc(i8 signext 1, i32* %20)
%57 = getelementptr inbounds i8, i8* %51, i64 1
%58 = load i8, i8* %57
%59 = call i32 @fputc(i8 signext %58, i32* %20)
%60 = getelementptr inbounds i8, i8* %51, i64 2
%61 = load i8, i8* %60
%62 = call i32 @fputc(i8 signext %61, i32* %20)
br label %92
63: ; preds = %50, %50
%64 = call i32 @fputc(i8 signext %52, i32* %20)
br label %92
65: ; preds = %50
%66 = call i32 @fwrite(i8* %51, i32 1, i32 3, i32* %20)
br label %92
67: ; preds = %50
%68 = call i32 @fputc(i8 signext 102, i32* %20)
br label %92
69: ; preds = %50
%70 = ptrtoint i8* %51 to i64
%71 = sub i64 %70, %49
%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* %51, 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* %51, i64 %79
%81 = ptrtoint i8* %80 to i64
%82 = sub i64 %81, %49
%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 %92
85: ; preds = %50
%86 = and i32 %53, 112
%87 = icmp eq i32 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %85
%89 = call i32 @fputc(i8 signext %52, i32* %20)
br label %92
90: ; preds = %85
%91 = call i32 @fwrite(i8* %51, i32 1, i32 3, i32* %20)
br label %92
92: ; preds = %88, %90, %69, %67, %65, %63, %54
%93 = phi i8* [ %51, %88 ], [ %51, %90 ], [ %80, %69 ], [ %45, %67 ], [ %51, %65 ], [ %51, %63 ], [ %51, %54 ]
%94 = phi i64 [ 1, %88 ], [ 3, %90 ], [ 0, %69 ], [ 1, %67 ], [ 3, %65 ], [ 1, %63 ], [ 3, %54 ]
%95 = getelementptr inbounds i8, i8* %93, i64 %94
%96 = icmp ugt i8* %95, %45
br i1 %96, label %97, label %50
97: ; preds = %92, %36
%98 = call i32 @fclose(i32* %20)
br label %99
99: ; preds = %97, %34, %24, %10
%100 = phi i32* [ @EXIT_FAILURE, %10 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_SUCCESS, %97 ]
%101 = load i32, i32* %100
ret i32 %101
}