#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_SUCCESS;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int printErrorAndExit(char *);
int /*<<< orphan*/ printf(char *, unsigned int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int updateYMAYOffset(int argc, char **argv) {
  FILE *vgmFile = fopen(argv[1], "r+b");
  unsigned int vgmVer = 0;
  if (vgmFile == NULL || strcmp(".vgz", argv[1] + strlen(argv[1]) - 4) == 0)
    return printErrorAndExit("file dun goofed son");
  fseek(vgmFile, 0x08, SEEK_SET);
  fread(&vgmVer, sizeof(short), 1, vgmFile);
  printf("vgmVer read: 0x%X\n", vgmVer);
  if (vgmVer < 0x170)
    return printErrorAndExit("vgm file not new enough. bog off");
  fseek(vgmFile, 0xCF, SEEK_SET);
  switch (atoi(argv[2])) {
  case 1:
    fputc(0x9A, vgmFile);
    fputc(0x81, vgmFile);
    break;
  case 2:
    fputc(0xCD, vgmFile);
    fputc(0x80, vgmFile);
    break;
  default:
    return printErrorAndExit("incorrect mode");
  }
  fflush(vgmFile);
  fclose(vgmFile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<updateYMAYOffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1225 <updateYMAYOffset+0x75>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rsi
cltq
add    %rax,%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xdee(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1239 <updateYMAYOffset+0x89>
lea    0xddd(%rip),%rdi
call   1090 <printErrorAndExit@plt>
mov    %eax,-0x4(%rbp)
jmp    1353 <updateYMAYOffset+0x1a3>
mov    -0x18(%rbp),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x1c(%rbp),%esi
lea    0xdac(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0x170,-0x1c(%rbp)
jae    1297 <updateYMAYOffset+0xe7>
lea    0xda6(%rip),%rdi
call   1090 <printErrorAndExit@plt>
mov    %eax,-0x4(%rbp)
jmp    1353 <updateYMAYOffset+0x1a3>
mov    -0x18(%rbp),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
mov    $0xcf,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0x1,%eax
je     12df <updateYMAYOffset+0x12f>
jmp    12ce <updateYMAYOffset+0x11e>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     1300 <updateYMAYOffset+0x150>
jmp    1321 <updateYMAYOffset+0x171>
mov    -0x18(%rbp),%rsi
mov    $0x9a,%edi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0x81,%edi
call   1070 <fputc@plt>
jmp    1335 <updateYMAYOffset+0x185>
mov    -0x18(%rbp),%rsi
mov    $0xcd,%edi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rsi
mov    $0x80,%edi
call   1070 <fputc@plt>
jmp    1335 <updateYMAYOffset+0x185>
lea    0xd29(%rip),%rdi
call   1090 <printErrorAndExit@plt>
mov    %eax,-0x4(%rbp)
jmp    1353 <updateYMAYOffset+0x1a3>
mov    -0x18(%rbp),%rdi
call   10a0 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateYMAYOffset>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe3a(%rip),%rsi
call   10c0 <fopen@plt>
movl   $0x0,0x4(%rsp)
test   %rax,%rax
je     1254 <updateYMAYOffset+0xa4>
mov    %rax,%r14
mov    0x8(%r15),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe0c(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1254 <updateYMAYOffset+0xa4>
mov    0x2dd7(%rip),%r12
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0x8,%esi
call   10b0 <fseek@plt>
lea    0x4(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    0x4(%rsp),%ebx
lea    0xde1(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
cmp    $0x16f,%ebx
ja     126b <updateYMAYOffset+0xbb>
lea    0xdde(%rip),%rdi
jmp    125b <updateYMAYOffset+0xab>
lea    0xdae(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1090 <printErrorAndExit@plt>
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0xcf,%esi
call   10b0 <fseek@plt>
mov    0x10(%r15),%rdi
call   10d0 <atoi@plt>
cmp    $0x1,%eax
je     129b <updateYMAYOffset+0xeb>
cmp    $0x2,%eax
jne    12dc <updateYMAYOffset+0x12c>
mov    $0x80,%ebx
mov    $0xcd,%edi
jmp    12a5 <updateYMAYOffset+0xf5>
mov    $0x81,%ebx
mov    $0x9a,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   10a0 <fflush@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd6e(%rip),%rdi
jmp    125b <updateYMAYOffset+0xab>

LLVM IR (-O0):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [5 x i8] c".vgz\00"
@.str.2 = [20 x i8] c"file dun goofed son\00"
@SEEK_SET = global i32 0
@.str.3 = [19 x i8] c"vgmVer read: 0x%X\0A\00"
@.str.4 = [33 x i8] c"vgm file not new enough. bog off\00"
@.str.5 = [15 x i8] c"incorrect mode\00"
@EXIT_SUCCESS = global i32 0
define i32 @updateYMAYOffset(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
store i32 0, i32* %7
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %27, label %14
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -4
%25 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %14, %2
%28 = call i32 @printErrorAndExit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 %28, i32* %3
br label %67
29: ; preds = %14
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @fseek(i32* %30, i32 8, i32 %31)
%33 = load i32*, i32** %6
%34 = call i32 @fread(i32* %7, i32 2, i32 1, i32* %33)
%35 = load i32, i32* %7
%36 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %7
%38 = icmp ult i32 %37, 368
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = call i32 @printErrorAndExit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 %40, i32* %3
br label %67
41: ; preds = %29
%42 = load i32*, i32** %6
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @fseek(i32* %42, i32 207, i32 %43)
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
switch i32 %48, label %59 [
i32 1, label %49
i32 2, label %54
]
49: ; preds = %41
%50 = load i32*, i32** %6
%51 = call i32 @fputc(i32 154, i32* %50)
%52 = load i32*, i32** %6
%53 = call i32 @fputc(i32 129, i32* %52)
br label %61
54: ; preds = %41
%55 = load i32*, i32** %6
%56 = call i32 @fputc(i32 205, i32* %55)
%57 = load i32*, i32** %6
%58 = call i32 @fputc(i32 128, i32* %57)
br label %61
59: ; preds = %41
%60 = call i32 @printErrorAndExit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 %60, i32* %3
br label %67
61: ; preds = %54, %49
%62 = load i32*, i32** %6
%63 = call i32 @fflush(i32* %62)
%64 = load i32*, i32** %6
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* @EXIT_SUCCESS
store i32 %66, i32* %3
br label %67
67: ; preds = %61, %59, %39, %27
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [5 x i8] c".vgz\00"
@.str.2 = [20 x i8] c"file dun goofed son\00"
@SEEK_SET = global i32 0
@.str.3 = [19 x i8] c"vgmVer read: 0x%X\0A\00"
@.str.4 = [33 x i8] c"vgm file not new enough. bog off\00"
@.str.5 = [15 x i8] c"incorrect mode\00"
@EXIT_SUCCESS = global i32 0
define i32 @updateYMAYOffset(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = icmp eq i32* %6, null
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = tail call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -4
%15 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9, %2
%18 = tail call i32 @printErrorAndExit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %45
19: ; preds = %9
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %6, i32 8, i32 %20)
%22 = call i32 @fread(i32* %3, i32 2, i32 1, i32* %6)
%23 = load i32, i32* %3
%24 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = icmp ult i32 %23, 368
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = tail call i32 @printErrorAndExit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %45
28: ; preds = %19
%29 = load i32, i32* @SEEK_SET
%30 = tail call i32 @fseek(i32* %6, i32 207, i32 %29)
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = tail call i32 @atoi(i8* %32)
switch i32 %33, label %35 [
i32 1, label %37
i32 2, label %34
]
34: ; preds = %28
br label %37
35: ; preds = %28
%36 = tail call i32 @printErrorAndExit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %45
37: ; preds = %28, %34
%38 = phi i32 [ 205, %34 ], [ 154, %28 ]
%39 = phi i32 [ 128, %34 ], [ 129, %28 ]
%40 = tail call i32 @fputc(i32 %38, i32* %6)
%41 = tail call i32 @fputc(i32 %39, i32* %6)
%42 = tail call i32 @fflush(i32* %6)
%43 = tail call i32 @fclose(i32* %6)
%44 = load i32, i32* @EXIT_SUCCESS
br label %45
45: ; preds = %37, %35, %26, %17
%46 = phi i32 [ %18, %17 ], [ %27, %26 ], [ %36, %35 ], [ %44, %37 ]
ret i32 %46
}