#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, long, int, int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fid;
  long len, i;
  char *buf;
  if (argc < 2) {
    fprintf(stderr, "%s: insufficient arguments\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (NULL == (fid = fopen(argv[1], "r+b"))) {
    perror("fopen");
    exit(EXIT_FAILURE);
  }
  fseek(fid, 0, SEEK_END);
  len = ftell(fid);
  fseek(fid, 0, SEEK_SET);
  if (NULL == (buf = malloc(len))) {
    perror("malloc");
    fclose(fid);
    exit(EXIT_FAILURE);
  }
  if (fread(buf, len, 1, fid) <= 0) {
    fputs("fread: failed\n", stderr);
    fclose(fid);
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < len; i++) {
    if (!memcmp(&buf[i], "\x00/dev_hdd0/game/%s",
                sizeof("\x00/dev_hdd0/game/%s"))) {
      fprintf(stderr, "FTP root hack successfully applied on offset %ld!!\n",
              i);
      memcpy(&buf[i],
             "\x00/"
             "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
             sizeof("\x00/dev_hdd0/game/%s"));
      fseek(fid, 0, SEEK_SET);
      fwrite(buf, len, 1, fid);
      break;
    }
  }
  fclose(fid);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    121c <main+0x4c>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    125c <main+0x8c>
lea    0xdd7(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    12cf <main+0xff>
lea    0xd73(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jg     131b <main+0x14b>
mov    0x2ce2(%rip),%rax
mov    (%rax),%esi
lea    0xd2e(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    13cc <main+0x1fc>
mov    -0x30(%rbp),%rdi
add    -0x28(%rbp),%rdi
lea    0xd30(%rip),%rsi
mov    $0x13,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    13b6 <main+0x1e6>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xcd5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
add    -0x28(%rbp),%rdi
lea    0xd06(%rip),%rsi
mov    $0x13,%edx
call   1090 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c3e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   10f0 <fwrite@plt>
jmp    13cc <main+0x1fc>
jmp    13bb <main+0x1eb>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1323 <main+0x153>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1317 <main+0x147>
mov    0x8(%rsi),%rdi
lea    0xe2d(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1333 <main+0x163>
mov    %rax,%r14
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %rax,%r15
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r15,%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1341 <main+0x171>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jle    134f <main+0x17f>
test   %r15,%r15
jle    12f7 <main+0x127>
xor    %ebx,%ebx
lea    0xdfd(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%rbx,1),%r13
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x13,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
je     12a3 <main+0xd3>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1280 <main+0xb0>
jmp    12f7 <main+0x127>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdbf(%rip),%rsi
mov    %r13,%rdi
mov    $0x13,%edx
call   1090 <memcpy@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   10f0 <fwrite@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcd6(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    136c <main+0x19c>
lea    0xce6(%rip),%rdi
call   10d0 <perror@plt>
jmp    136c <main+0x19c>
lea    0xcde(%rip),%rdi
call   10d0 <perror@plt>
jmp    1364 <main+0x194>
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
lea    0xcce(%rip),%rdi
call   1050 <fputs@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"%s: insufficient arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [6 x i8] c"fopen\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [15 x i8] c"fread: failed\0A\00"
@.str.5 = [19 x i8] c"\00/dev_hdd0/game/%s\00"
@.str.6 = [52 x i8] c"FTP root hack successfully applied on offset %ld!!\0A\00"
@.str.7 = [19 x i8] c"\00/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* null, %24
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %6
%35 = call i64 @ftell(i32* %34)
store i64 %35, i64* %7
%36 = load i32*, i32** %6
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %36, i32 0, i32 %37)
%39 = load i64, i64* %7
%40 = call i8* @malloc(i64 %39)
store i8* %40, i8** %9
%41 = icmp eq i8* null, %40
br i1 %41, label %42, label %48
42: ; preds = %30
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %30
%49 = load i8*, i8** %9
%50 = load i64, i64* %7
%51 = load i32*, i32** %6
%52 = call i64 @fread(i8* %49, i64 %50, i32 1, i32* %51)
%53 = icmp sle i64 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %48
store i64 0, i64* %8
br label %62
62: ; preds = %88, %61
%63 = load i64, i64* %8
%64 = load i64, i64* %7
%65 = icmp slt i64 %63, %64
br i1 %65, label %66, label %91
66: ; preds = %62
%67 = load i8*, i8** %9
%68 = load i64, i64* %8
%69 = getelementptr inbounds i8, i8* %67, i64 %68
%70 = call i32 @memcmp(i8* %69, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 19)
%71 = icmp ne i32 %70, 0
br i1 %71, label %87, label %72
72: ; preds = %66
%73 = load i32, i32* @stderr
%74 = load i64, i64* %8
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i64 %74)
%76 = load i8*, i8** %9
%77 = load i64, i64* %8
%78 = getelementptr inbounds i8, i8* %76, i64 %77
%79 = call i32 @memcpy(i8* %78, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 19)
%80 = load i32*, i32** %6
%81 = load i32, i32* @SEEK_SET
%82 = call i32 @fseek(i32* %80, i32 0, i32 %81)
%83 = load i8*, i8** %9
%84 = load i64, i64* %7
%85 = load i32*, i32** %6
%86 = call i32 @fwrite(i8* %83, i64 %84, i32 1, i32* %85)
br label %91
87: ; preds = %66
br label %88
88: ; preds = %87
%89 = load i64, i64* %8
%90 = add nsw i64 %89, 1
store i64 %90, i64* %8
br label %62
91: ; preds = %72, %62
%92 = load i32*, i32** %6
%93 = call i32 @fclose(i32* %92)
%94 = load i32, i32* @EXIT_SUCCESS
ret i32 %94
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"%s: insufficient arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [6 x i8] c"fopen\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [15 x i8] c"fread: failed\0A\00"
@.str.5 = [19 x i8] c"\00/dev_hdd0/game/%s\00"
@.str.6 = [52 x i8] c"FTP root hack successfully applied on offset %ld!!\0A\00"
@.str.7 = [19 x i8] c"\00/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = load i32, i32* @SEEK_END
%21 = tail call i32 @fseek(i32* %13, i32 0, i32 %20)
%22 = tail call i64 @ftell(i32* %13)
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @fseek(i32* %13, i32 0, i32 %23)
%25 = tail call i8* @malloc(i64 %22)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @fclose(i32* %13)
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %19
%33 = tail call i64 @fread(i8* %25, i64 %22, i32 1, i32* %13)
%34 = icmp slt i64 %33, 1
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = icmp sgt i64 %22, 0
br i1 %36, label %43, label %58
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = tail call i32 @fclose(i32* %13)
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %35, %55
%44 = phi i64 [ %56, %55 ], [ 0, %35 ]
%45 = getelementptr inbounds i8, i8* %25, i64 %44
%46 = tail call i32 @memcmp(i8* %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 19)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i64 %44)
%51 = tail call i32 @memcpy(i8* %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 19)
%52 = load i32, i32* @SEEK_SET
%53 = tail call i32 @fseek(i32* %13, i32 0, i32 %52)
%54 = tail call i32 @fwrite(i8* %25, i64 %22, i32 1, i32* %13)
br label %58
55: ; preds = %43
%56 = add nuw nsw i64 %44, 1
%57 = icmp eq i64 %56, %22
br i1 %57, label %58, label %43
58: ; preds = %55, %35, %48
%59 = tail call i32 @fclose(i32* %13)
%60 = load i32, i32* @EXIT_SUCCESS
ret i32 %60
}