#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_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("usage: %s filename\n", argv[0]);
    return EXIT_FAILURE;
  }
  FILE *fp = fopen(argv[1], "r+");
  if (fp == NULL) {
    printf("can't open %s\n ", argv[1]);
    return EXIT_FAILURE;
  }
  char jmp[2] = {0x0f, 0x84};
  char nops[6] = {0x90, 0x90, 0x90, 0x90, 0x90, 0x90};
  fseek(fp, 0x00030c25, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x00031e32, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x00031f52, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x00032072, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x00036970, SEEK_SET);
  fwrite(nops, 2, 1, fp);
  fseek(fp, 0x0003699d, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fclose(fp);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <main+0x1d4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe71(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dc <main+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <main+0x1d4>
mov    0xe44(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    0xe3c(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe36(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    $0x30c25,%esi
call   1050 <fseek@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
mov    $0x31e32,%esi
call   1050 <fseek@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
mov    $0x31f52,%esi
call   1050 <fseek@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
mov    $0x32072,%esi
call   1050 <fseek@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d22(%rip),%rax
mov    (%rax),%edx
mov    $0x36970,%esi
call   1050 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
mov    $0x3699d,%esi
call   1050 <fseek@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1170 <main+0x20>
mov    (%rbx),%rsi
lea    0xe95(%rip),%rdi
jmp    12a4 <main+0x154>
mov    0x8(%rbx),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1299 <main+0x149>
mov    %rax,%r15
movw   $0x840f,0x6(%rsp)
movw   $0x9090,0xc(%rsp)
movl   $0x90909090,0x8(%rsp)
90
mov    0x2e37(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0x30c25,%esi
call   1050 <fseek@plt>
lea    0x6(%rsp),%r14
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x31e32,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x31f52,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x32072,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x36970,%esi
call   1050 <fseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x3699d,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x2d39(%rip),%rax
jmp    12b0 <main+0x160>
mov    0x8(%rbx),%rsi
lea    0xd73(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"usage: %s filename\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [16 x i8] c"can't open %s\0A \00"
@__const.main.jmp = [2 x i8] c"\0F\84"
@__const.main.nops = [6 x i8] c"\90\90\90\90\90\90"
@SEEK_SET = global i32 0
@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 [2 x i8]
%8 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %72
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %72
30: ; preds = %17
%31 = bitcast [2 x i8]* %7 to i8*
%32 = bitcast [6 x i8]* %8 to i8*
%33 = load i32*, i32** %6
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseek(i32* %33, i32 199717, i32 %34)
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%37 = load i32*, i32** %6
%38 = call i32 @fwrite(i8* %36, i32 2, i32 1, i32* %37)
%39 = load i32*, i32** %6
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %39, i32 204338, i32 %40)
%42 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%43 = load i32*, i32** %6
%44 = call i32 @fwrite(i8* %42, i32 2, i32 1, i32* %43)
%45 = load i32*, i32** %6
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @fseek(i32* %45, i32 204626, i32 %46)
%48 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%49 = load i32*, i32** %6
%50 = call i32 @fwrite(i8* %48, i32 2, i32 1, i32* %49)
%51 = load i32*, i32** %6
%52 = load i32, i32* @SEEK_SET
%53 = call i32 @fseek(i32* %51, i32 204914, i32 %52)
%54 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%55 = load i32*, i32** %6
%56 = call i32 @fwrite(i8* %54, i32 2, i32 1, i32* %55)
%57 = load i32*, i32** %6
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @fseek(i32* %57, i32 223600, i32 %58)
%60 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%61 = load i32*, i32** %6
%62 = call i32 @fwrite(i8* %60, i32 2, i32 1, i32* %61)
%63 = load i32*, i32** %6
%64 = load i32, i32* @SEEK_SET
%65 = call i32 @fseek(i32* %63, i32 223645, i32 %64)
%66 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%67 = load i32*, i32** %6
%68 = call i32 @fwrite(i8* %66, i32 2, i32 1, i32* %67)
%69 = load i32*, i32** %6
%70 = call i32 @fclose(i32* %69)
%71 = load i32, i32* @EXIT_SUCCESS
store i32 %71, i32* %3
br label %72
72: ; preds = %30, %24, %11
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [20 x i8] c"usage: %s filename\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [16 x i8] c"can't open %s\0A \00"
@SEEK_SET = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca [6 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
br label %42
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 ([3 x i8], [3 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 = load i8*, i8** %11
%17 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
br label %42
19: ; preds = %10
%20 = bitcast i16* %3 to i8*
store i16 -31729, i16* %3
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @fseek(i32* %13, i32 199717, i32 %22)
%24 = call i32 @fwrite(i8* %20, i32 2, i32 1, i32* %13)
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %13, i32 204338, i32 %25)
%27 = call i32 @fwrite(i8* %20, i32 2, i32 1, i32* %13)
%28 = load i32, i32* @SEEK_SET
%29 = tail call i32 @fseek(i32* %13, i32 204626, i32 %28)
%30 = call i32 @fwrite(i8* %20, i32 2, i32 1, i32* %13)
%31 = load i32, i32* @SEEK_SET
%32 = tail call i32 @fseek(i32* %13, i32 204914, i32 %31)
%33 = call i32 @fwrite(i8* %20, i32 2, i32 1, i32* %13)
%34 = load i32, i32* @SEEK_SET
%35 = tail call i32 @fseek(i32* %13, i32 223600, i32 %34)
%36 = call i32 @fwrite(i8* %21, i32 2, i32 1, i32* %13)
%37 = load i32, i32* @SEEK_SET
%38 = tail call i32 @fseek(i32* %13, i32 223645, i32 %37)
%39 = call i32 @fwrite(i8* %20, i32 2, i32 1, i32* %13)
%40 = tail call i32 @fclose(i32* %13)
%41 = load i32, i32* @EXIT_SUCCESS
br label %42
42: ; preds = %15, %19, %6
%43 = phi i32 [ %9, %6 ], [ %18, %15 ], [ %41, %19 ]
ret i32 %43
}