#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 /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char const *, int, int,
                          int /*<<< orphan*/ *);
scalar_t__ memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ printerr(char *);
int /*<<< orphan*/ puts(char *);
void handleIso(FILE *f, const unsigned char *wantHdr) {
  if (!f) {
    printerr("Something went wrong with the file!");
    exit(-1);
  }
  fseek(f, 0, SEEK_SET);
  unsigned char gameHdr[0x40];
  fread(gameHdr, 0x40, 1, f);
  if (memcmp(gameHdr, wantHdr, 0x40) == 0)
    puts("Header already patched!");
  else {
    fseek(f, 0, SEEK_SET);
    fwrite(wantHdr, 0x40, 1, f);
    puts("New Header written in!");
  }
}


x86 assembly (clang, -O0):
<handleIso>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a1 <handleIso+0x31>
lea    0xe6e(%rip),%rdi
call   1060 <printerr@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x40,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    11f9 <handleIso+0x89>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
jmp    1230 <handleIso+0xc0>
mov    -0x8(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x40,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleIso>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %rdi,%rdi
je     120d <handleIso+0x9d>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e4f(%rip),%r12
mov    (%r12),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x40,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11f5 <handleIso+0x85>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14,%rdi
mov    $0x40,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xe49(%rip),%rdi
jmp    11fc <handleIso+0x8c>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdec(%rip),%rdi
call   1060 <printerr@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Something went wrong with the file!\00"
@SEEK_SET = global i32 0
@.str.1 = [24 x i8] c"Header already patched!\00"
@.str.2 = [23 x i8] c"New Header written in!\00"
define void @handleIso(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [64 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i32 @printerr(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i32*, i32** %3
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %12, i32 0, i32 %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @fread(i8* %15, i32 64, i32 1, i32* %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i64 @memcmp(i8* %18, i8* %19, i32 64)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %32
24: ; preds = %11
%25 = load i32*, i32** %3
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i8*, i8** %4
%29 = load i32*, i32** %3
%30 = call i32 @fwrite(i8* %28, i32 64, i32 1, i32* %29)
%31 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %24, %22
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"Something went wrong with the file!\00"
@SEEK_SET = global i32 0
@.str.1 = [24 x i8] c"Header already patched!\00"
@.str.2 = [23 x i8] c"New Header written in!\00"
define void @handleIso(i32* %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printerr(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %0, i32 0, i32 %9)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 @fread(i8* %11, i32 64, i32 1, i32* %0)
%13 = call i64 @memcmp(i8* %11, i8* %1, i32 64)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %8
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %0, i32 0, i32 %16)
%18 = call i32 @fwrite(i8* %1, i32 64, i32 1, i32* %0)
br label %19
19: ; preds = %8, %15
%20 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %8 ]
%21 = call i32 @puts(i8* dereferenceable(1) %20)
ret void
}