#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, 0x0002e850 + 5, SEEK_SET);
  fwrite(nops, 6, 1, fp);
  fseek(fp, 0x0002fa60 + 2, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x0002fb80 + 2, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x0002fca0 + 2, SEEK_SET);
  fwrite(jmp, 2, 1, fp);
  fseek(fp, 0x000345a0, SEEK_SET);
  fwrite(nops, 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    12f6 <main+0x1a6>
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    12f6 <main+0x1a6>
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    $0x2e855,%esi
call   1050 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
mov    $0x2fa62,%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    $0x2fb82,%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    $0x2fca2,%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    $0x345a0,%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
call   1030 <fclose@plt>
mov    0x2cdf(%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   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1172 <main+0x22>
mov    (%rbx),%rsi
lea    0xe93(%rip),%rdi
jmp    1285 <main+0x135>
mov    0x8(%rbx),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     127a <main+0x12a>
mov    %rax,%r12
movw   $0x840f,0xe(%rsp)
movw   $0x9090,0x14(%rsp)
movl   $0x90909090,0x10(%rsp)
90
mov    0x2e35(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0x2e855,%esi
call   1050 <fseek@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    $0x2fa62,%esi
call   1050 <fseek@plt>
lea    0xe(%rsp),%r15
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    $0x2fb82,%esi
call   1050 <fseek@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    $0x2fca2,%esi
call   1050 <fseek@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    $0x345a0,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x2d58(%rip),%rax
jmp    1291 <main+0x141>
mov    0x8(%rbx),%rsi
lea    0xd92(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
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 %66
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 %66
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 190549, i32 %34)
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%37 = load i32*, i32** %6
%38 = call i32 @fwrite(i8* %36, i32 6, i32 1, i32* %37)
%39 = load i32*, i32** %6
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %39, i32 195170, 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 195458, 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 195746, 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 214432, 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 = call i32 @fclose(i32* %63)
%65 = load i32, i32* @EXIT_SUCCESS
store i32 %65, i32* %3
br label %66
66: ; preds = %30, %24, %11
%67 = load i32, i32* %3
ret i32 %67
}

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 %39
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 %39
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 190549, i32 %22)
%24 = call i32 @fwrite(i8* %21, i32 6, i32 1, i32* %13)
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %13, i32 195170, 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 195458, 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 195746, 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 214432, i32 %34)
%36 = call i32 @fwrite(i8* %21, i32 2, i32 1, i32* %13)
%37 = tail call i32 @fclose(i32* %13)
%38 = load i32, i32* @EXIT_SUCCESS
br label %39
39: ; preds = %15, %19, %6
%40 = phi i32 [ %9, %6 ], [ %18, %15 ], [ %38, %19 ]
ret i32 %40
}