#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 magic_bytes[6] = {0x90, 0x90, 0x30, 0xc0, 0xfe, 0xc0};
  fseek(fp, 0x10b477 + 10, SEEK_SET);
  fwrite(magic_bytes, 6, 1, fp);
  fseek(fp, 0x10b498 + 5, SEEK_SET);
  fwrite(magic_bytes, 6, 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    1261 <main+0x111>
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    1261 <main+0x111>
mov    0xe45(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe3f(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    $0x10b481,%esi
call   1050 <fseek@plt>
lea    -0x1e(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
mov    $0x10b49d,%esi
call   1050 <fseek@plt>
lea    -0x1e(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d74(%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    1209 <main+0xb9>
mov    0x8(%rbx),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fe <main+0xae>
mov    %rax,%r14
movw   $0xc0fe,0xc(%rsp)
movl   $0xc0309090,0x8(%rsp)
c0
mov    0x2e42(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x10b481,%esi
call   1050 <fseek@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x10b49d,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2dd4(%rip),%rax
jmp    1215 <main+0xc5>
mov    0x8(%rbx),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc3(%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.magic_bytes = [6 x i8] c"\90\900\C0\FE\C0"
@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 [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %46
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %46
29: ; preds = %16
%30 = bitcast [6 x i8]* %7 to i8*
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i32 1094785, i32 %32)
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%35 = load i32*, i32** %6
%36 = call i32 @fwrite(i8* %34, i32 6, i32 1, i32* %35)
%37 = load i32*, i32** %6
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %37, i32 1094813, i32 %38)
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%41 = load i32*, i32** %6
%42 = call i32 @fwrite(i8* %40, i32 6, i32 1, i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %3
br label %46
46: ; preds = %29, %23, %10
%47 = load i32, i32* %3
ret i32 %47
}

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"
@__const.main.magic_bytes = [6 x i8] c"\90\900\C0\FE\C0"
@SEEK_SET = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
br label %28
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
br label %28
18: ; preds = %9
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %12, i32 1094785, i32 %20)
%22 = call i32 @fwrite(i8* %19, i32 6, i32 1, i32* %12)
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @fseek(i32* %12, i32 1094813, i32 %23)
%25 = call i32 @fwrite(i8* %19, i32 6, i32 1, i32* %12)
%26 = tail call i32 @fclose(i32* %12)
%27 = load i32, i32* @EXIT_SUCCESS
br label %28
28: ; preds = %14, %18, %5
%29 = phi i32 [ %8, %5 ], [ %17, %14 ], [ %27, %18 ]
ret i32 %29
}