#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*/ memcpy(char *, char *, 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);
  memcpy(&fileBuffer[0x2C], &fileBuffer[0x48], 4);
  curPos = &(fileBuffer[0xE0]);
  bufEnd = &(fileBuffer[fileSize - 1]);
  while (curPos <= bufEnd) {
    size_t ptrInc;
    switch (curPos[0]) {
    case 0x55:
    case 0x56:
    case 0x57:
      ptrInc = 3;
      if (curPos[1] & 0xE0) {
        printf("DEBUG: CONVERTED ADDR 0x%X\r", (curPos - fileBuffer));
        curPos[0] = (char)(0x52 | (curPos[0] == 0x55 ? 0 : (curPos[0] & 0x01)));
      }
      break;
    case 0x62:
    case 0x63:
      ptrInc = 1;
      break;
    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    $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    0xe0d(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    126b <run+0x9b>
lea    0xdfc(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15c3 <run+0x3f3>
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    0xdcc(%rip),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     12e7 <run+0x117>
cmpq   $0x0,-0x88(%rbp)
jne    1304 <run+0x134>
lea    0xd89(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15c3 <run+0x3f3>
mov    -0x80(%rbp),%rdi
mov    0x2cd9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x80(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x90(%rbp)
mov    -0x80(%rbp),%rdi
mov    0x2ca5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x90(%rbp),%rsi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1379 <run+0x1a9>
lea    0xd2c(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15c3 <run+0x3f3>
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    $0x2c,%rdi
mov    -0x68(%rbp),%rsi
add    $0x48,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0xe0,%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     158f <run+0x3bf>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffab,%eax
mov    %eax,%ecx
mov    %rcx,-0xa8(%rbp)
sub    $0x12,%eax
ja     1548 <run+0x378>
mov    -0xa8(%rbp),%rax
lea    0xbef(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x3,-0x98(%rbp)
mov    -0x70(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xe0,%eax
cmp    $0x0,%eax
je     1492 <run+0x2c2>
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xc60(%rip),%rdi
call   1070 <printf@plt>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x55,%eax
jne    1471 <run+0x2a1>
xor    %eax,%eax
mov    %eax,-0xac(%rbp)
jmp    1481 <run+0x2b1>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
and    $0x1,%eax
mov    %eax,-0xac(%rbp)
mov    -0xac(%rbp),%eax
or     $0x52,%eax
mov    %al,%cl
mov    -0x70(%rbp),%rax
mov    %cl,(%rax)
jmp    157b <run+0x3ab>
movq   $0x1,-0x98(%rbp)
jmp    157b <run+0x3ab>
movq   $0x3,-0x98(%rbp)
jmp    157b <run+0x3ab>
movq   $0x1,-0x98(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    157b <run+0x3ab>
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xbe8(%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    0xbdb(%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    0xbce(%rip),%rdi
call   1070 <printf@plt>
movq   $0x0,-0x98(%rbp)
jmp    157b <run+0x3ab>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
and    $0x70,%eax
cmp    $0x0,%eax
je     156b <run+0x39b>
movq   $0x1,-0x98(%rbp)
jmp    1576 <run+0x3a6>
movq   $0x3,-0x98(%rbp)
jmp    157b <run+0x3ab>
mov    -0x98(%rbp),%rax
add    -0x70(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    13d9 <run+0x209>
mov    -0x68(%rbp),%rdi
mov    -0x90(%rbp),%rdx
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x88(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2a0a(%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    $0x68,%rsp
mov    %rdi,%rbx
call   1060 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe55(%rip),%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     140e <run+0x23e>
lea    0x10(%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    0xe32(%rip),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbp
lea    0xe1e(%rip),%rsi
mov    %r14,%rdi
call   10d0 <fopen@plt>
test   %rbp,%rbp
je     1417 <run+0x247>
mov    %rax,%r14
test   %rax,%rax
je     1417 <run+0x247>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
mov    %rax,%r15
mov    0x2d40(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    $0x1,%edi
mov    %r15,%rsi
call   1080 <calloc@plt>
test   %rax,%rax
je     1420 <run+0x250>
mov    %rax,%rbx
mov    %r14,0x8(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0x2c(%rbx),%rdi
lea    0x48(%rbx),%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    -0x1(%r15),%rax
cmp    $0xe0,%rax
jge    1333 <run+0x163>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    0x8(%rsp),%rbx
mov    %rbx,%rcx
call   10f0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    (%rbx,%r15,1),%r12
add    $0xffffffffffffffff,%r12
mov    %rbx,%r13
add    $0xe0,%r13
lea    0xcb4(%rip),%r14
jmp    1368 <run+0x198>
xor    %ecx,%ecx
test   $0x70,%al
sete   %cl
lea    (%rcx,%rcx,1),%rbp
add    $0x1,%rbp
nopl   (%rax)
add    %rbp,%r13
cmp    %r12,%r13
ja     12fb <run+0x12b>
movsbl 0x0(%r13),%eax
lea    -0x55(%rax),%ecx
cmp    $0x12,%ecx
ja     134e <run+0x17e>
mov    $0x1,%ebp
movslq (%r14,%rcx,4),%rcx
add    %r14,%rcx
jmp    *%rcx
mov    $0x3,%ebp
cmpb   $0x20,0x1(%r13)
jb     1360 <run+0x190>
mov    %r13d,%esi
sub    %ebx,%esi
lea    0xd14(%rip),%rdi
call   1070 <printf@plt>
movzbl 0x0(%r13),%eax
mov    %eax,%ecx
and    $0x1,%cl
or     $0x52,%cl
cmp    $0x55,%al
movzbl %cl,%eax
mov    $0x52,%ecx
cmove  %ecx,%eax
mov    %al,0x0(%r13)
jmp    1360 <run+0x190>
mov    $0x3,%ebp
jmp    1360 <run+0x190>
mov    %r12,%r13
jmp    1360 <run+0x190>
mov    %r13d,%esi
sub    %ebx,%esi
lea    0xcf3(%rip),%rdi
call   1070 <printf@plt>
movslq 0x3(%r13),%rbp
lea    0xcfa(%rip),%rdi
mov    %ebp,%esi
call   1070 <printf@plt>
add    %rbp,%r13
add    $0x7,%r13
mov    %r13d,%esi
sub    %ebx,%esi
lea    0xcff(%rip),%rdi
call   1070 <printf@plt>
xor    %ebp,%ebp
jmp    1360 <run+0x190>
lea    0xc3c(%rip),%rdi
jmp    1427 <run+0x257>
lea    0xc59(%rip),%rdi
jmp    1427 <run+0x257>
lea    0xc68(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b9d(%rip),%rax
jmp    1322 <run+0x152>

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 = [28 x i8] c"DEBUG: CONVERTED ADDR 0x%X\0D\00"
@.str.8 = [23 x i8] c"DEBUG: Curr addr 0x%X\0A\00"
@.str.9 = [31 x i8] c"DEBUG: Offset Data Block 0x%X\0A\00"
@.str.10 = [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 %175
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 %175
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 %175
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 44
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i64 72
%72 = call i32 @memcpy(i8* %69, i8* %71, i32 4)
%73 = load i8*, i8** %5
%74 = getelementptr inbounds i8, i8* %73, i64 224
store i8* %74, i8** %6
%75 = load i8*, i8** %5
%76 = load i64, i64* %10
%77 = sub i64 %76, 1
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8* %78, i8** %7
br label %79
79: ; preds = %163, %61
%80 = load i8*, i8** %6
%81 = load i8*, i8** %7
%82 = icmp ule i8* %80, %81
br i1 %82, label %83, label %167
83: ; preds = %79
%84 = load i8*, i8** %6
%85 = getelementptr inbounds i8, i8* %84, i64 0
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
switch i32 %87, label %153 [
i32 85, label %88
i32 86, label %88
i32 87, label %88
i32 98, label %122
i32 99, label %122
i32 97, label %123
i32 102, label %124
i32 103, label %126
]
88: ; preds = %83, %83, %83
store i64 3, i64* %11
%89 = load i8*, i8** %6
%90 = getelementptr inbounds i8, i8* %89, i64 1
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = and i32 %92, 224
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %121
95: ; preds = %88
%96 = load i8*, i8** %6
%97 = load i8*, i8** %5
%98 = ptrtoint i8* %96 to i64
%99 = ptrtoint i8* %97 to i64
%100 = sub i64 %98, %99
%101 = trunc i64 %100 to i32
%102 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %101)
%103 = load i8*, i8** %6
%104 = getelementptr inbounds i8, i8* %103, i64 0
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 85
br i1 %107, label %108, label %109
108: ; preds = %95
br label %115
109: ; preds = %95
%110 = load i8*, i8** %6
%111 = getelementptr inbounds i8, i8* %110, i64 0
%112 = load i8, i8* %111
%113 = sext i8 %112 to i32
%114 = and i32 %113, 1
br label %115
115: ; preds = %109, %108
%116 = phi i32 [ 0, %108 ], [ %114, %109 ]
%117 = or i32 82, %116
%118 = trunc i32 %117 to i8
%119 = load i8*, i8** %6
%120 = getelementptr inbounds i8, i8* %119, i64 0
store i8 %118, i8* %120
br label %121
121: ; preds = %115, %88
br label %163
122: ; preds = %83, %83
store i64 1, i64* %11
br label %163
123: ; preds = %83
store i64 3, i64* %11
br label %163
124: ; preds = %83
store i64 1, i64* %11
%125 = load i8*, i8** %7
store i8* %125, i8** %6
br label %163
126: ; preds = %83
%127 = load i8*, i8** %6
%128 = load i8*, i8** %5
%129 = ptrtoint i8* %127 to i64
%130 = ptrtoint i8* %128 to i64
%131 = sub i64 %129, %130
%132 = trunc i64 %131 to i32
%133 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %132)
%134 = load i8*, i8** %6
%135 = getelementptr inbounds i8, i8* %134, i64 3
%136 = bitcast i8* %135 to i32*
%137 = load i32, i32* %136
%138 = sext i32 %137 to i64
store i64 %138, i64* %11
%139 = load i64, i64* %11
%140 = trunc i64 %139 to i32
%141 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %140)
%142 = load i64, i64* %11
%143 = add i64 %142, 7
%144 = load i8*, i8** %6
%145 = getelementptr inbounds i8, i8* %144, i64 %143
store i8* %145, i8** %6
%146 = load i8*, i8** %6
%147 = load i8*, i8** %5
%148 = ptrtoint i8* %146 to i64
%149 = ptrtoint i8* %147 to i64
%150 = sub i64 %148, %149
%151 = trunc i64 %150 to i32
%152 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %151)
store i64 0, i64* %11
br label %163
153: ; preds = %83
%154 = load i8*, i8** %6
%155 = getelementptr inbounds i8, i8* %154, i64 0
%156 = load i8, i8* %155
%157 = sext i8 %156 to i32
%158 = and i32 %157, 112
%159 = icmp ne i32 %158, 0
br i1 %159, label %160, label %161
160: ; preds = %153
store i64 1, i64* %11
br label %162
161: ; preds = %153
store i64 3, i64* %11
br label %162
162: ; preds = %161, %160
br label %163
163: ; preds = %162, %126, %124, %123, %122, %121
%164 = load i64, i64* %11
%165 = load i8*, i8** %6
%166 = getelementptr inbounds i8, i8* %165, i64 %164
store i8* %166, i8** %6
br label %79
167: ; preds = %79
%168 = load i8*, i8** %5
%169 = load i64, i64* %10
%170 = load i32*, i32** %9
%171 = call i32 @fwrite(i8* %168, i32 1, i64 %169, i32* %170)
%172 = load i32*, i32** %9
%173 = call i32 @fclose(i32* %172)
%174 = load i32, i32* @EXIT_SUCCESS
store i32 %174, i32* %2
br label %175
175: ; preds = %167, %58, %42, %20
%176 = load i32, i32* %2
ret i32 %176
}

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 = [28 x i8] c"DEBUG: CONVERTED ADDR 0x%X\0D\00"
@.str.8 = [23 x i8] c"DEBUG: Curr addr 0x%X\0A\00"
@.str.9 = [31 x i8] c"DEBUG: Offset Data Block 0x%X\0A\00"
@.str.10 = [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 %96
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 %96
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 %96
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 44
%40 = getelementptr inbounds i8, i8* %32, i64 72
%41 = call i32 @memcpy(i8* %39, i8* %40, i32 4)
%42 = add i64 %29, -1
%43 = getelementptr inbounds i8, i8* %32, i64 %42
%44 = icmp slt i64 %42, 224
br i1 %44, label %93, label %45
45: ; preds = %36
%46 = getelementptr inbounds i8, i8* %32, i64 224
%47 = ptrtoint i8* %32 to i64
br label %48
48: ; preds = %45, %88
%49 = phi i8* [ %46, %45 ], [ %91, %88 ]
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
switch i32 %51, label %84 [
i32 85, label %52
i32 86, label %52
i32 87, label %52
i32 98, label %88
i32 99, label %88
i32 97, label %66
i32 102, label %67
i32 103, label %68
]
52: ; preds = %48, %48, %48
%53 = getelementptr inbounds i8, i8* %49, i64 1
%54 = load i8, i8* %53
%55 = icmp ult i8 %54, 32
br i1 %55, label %88, label %56
56: ; preds = %52
%57 = ptrtoint i8* %49 to i64
%58 = sub i64 %57, %47
%59 = trunc i64 %58 to i32
%60 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %59)
%61 = load i8, i8* %49
%62 = icmp eq i8 %61, 85
%63 = and i8 %61, 1
%64 = or i8 %63, 82
%65 = select i1 %62, i8 82, i8 %64
store i8 %65, i8* %49
br label %88
66: ; preds = %48
br label %88
67: ; preds = %48
br label %88
68: ; preds = %48
%69 = ptrtoint i8* %49 to i64
%70 = sub i64 %69, %47
%71 = trunc i64 %70 to i32
%72 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds i8, i8* %49, i64 3
%74 = bitcast i8* %73 to i32*
%75 = load i32, i32* %74
%76 = sext i32 %75 to i64
%77 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %75)
%78 = add nsw i64 %76, 7
%79 = getelementptr inbounds i8, i8* %49, i64 %78
%80 = ptrtoint i8* %79 to i64
%81 = sub i64 %80, %47
%82 = trunc i64 %81 to i32
%83 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %82)
br label %88
84: ; preds = %48
%85 = and i32 %51, 112
%86 = icmp eq i32 %85, 0
%87 = select i1 %86, i64 3, i64 1
br label %88
88: ; preds = %84, %48, %48, %52, %56, %68, %67, %66
%89 = phi i8* [ %79, %68 ], [ %43, %67 ], [ %49, %66 ], [ %49, %56 ], [ %49, %52 ], [ %49, %48 ], [ %49, %48 ], [ %49, %84 ]
%90 = phi i64 [ 0, %68 ], [ 1, %67 ], [ 3, %66 ], [ 3, %56 ], [ 3, %52 ], [ 1, %48 ], [ 1, %48 ], [ %87, %84 ]
%91 = getelementptr inbounds i8, i8* %89, i64 %90
%92 = icmp ugt i8* %91, %43
br i1 %92, label %93, label %48
93: ; preds = %88, %36
%94 = call i32 @fwrite(i8* %32, i32 1, i64 %29, i32* %20)
%95 = call i32 @fclose(i32* %20)
br label %96
96: ; preds = %93, %34, %24, %10
%97 = phi i32* [ @EXIT_FAILURE, %10 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_SUCCESS, %93 ]
%98 = load i32, i32* %97
ret i32 %98
}