#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 const *, 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;
  }
  const char magic_bytes[6] = {0x90, 0x90, 0x30, 0xc0, 0xfe, 0xc0};
  fseek(fp, 0x105038 + 16, SEEK_SET);
  fwrite(magic_bytes, 6, 1, fp);
  const char not_magic_bytes[13] = "            ";
  fseek(fp, 0x25A988, SEEK_SET);
  fwrite(not_magic_bytes, 12, 1, fp);
  fclose(fp);
  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    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    127e <main+0x12e>
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    127e <main+0x12e>
mov    0xe52(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe4c(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    $0x105048,%esi
call   1050 <fseek@plt>
lea    -0x1e(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    0xe02(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xe00(%rip),%eax
mov    %eax,-0x23(%rbp)
mov    0xdfb(%rip),%al
mov    %al,-0x1f(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    $0x25a988,%esi
call   1050 <fseek@plt>
lea    -0x2b(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xc,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     116e <main+0x1e>
mov    (%rbx),%rsi
lea    0xe97(%rip),%rdi
jmp    1223 <main+0xd3>
mov    0x8(%rbx),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1218 <main+0xc8>
mov    %rax,%r14
movw   $0xc0fe,0x4(%rsp)
movl   $0xc0309090,(%rsp)
mov    0x2e41(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0x105048,%esi
call   1050 <fseek@plt>
mov    %rsp,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
movabs $0x20202020202020,%rax
mov    %rax,0xd(%rsp)
movabs $0x2020202020202020,%rax
20 20 20
mov    %rax,0x8(%rsp)
mov    (%rbx),%edx
mov    %r14,%rdi
mov    $0x25a988,%esi
call   1050 <fseek@plt>
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2dba(%rip),%rax
jmp    122f <main+0xdf>
mov    0x8(%rbx),%rsi
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
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
@__const.main.not_magic_bytes = [13 x i8] c" \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 [6 x i8]
%8 = alloca [13 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 %48
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 %48
30: ; preds = %17
%31 = bitcast [6 x i8]* %7 to i8*
%32 = load i32*, i32** %6
%33 = load i32, i32* @SEEK_SET
%34 = call i32 @fseek(i32* %32, i32 1069128, i32 %33)
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%36 = load i32*, i32** %6
%37 = call i32 @fwrite(i8* %35, i32 6, i32 1, i32* %36)
%38 = bitcast [13 x i8]* %8 to i8*
%39 = load i32*, i32** %6
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %39, i32 2468232, i32 %40)
%42 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%43 = load i32*, i32** %6
%44 = call i32 @fwrite(i8* %42, i32 12, i32 1, i32* %43)
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %3
br label %48
48: ; preds = %30, %24, %11
%49 = load i32, i32* %3
ret i32 %49
}

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
@__const.main.not_magic_bytes = [13 x i8] c" \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%4 = alloca [13 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 %30
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 %30
19: ; preds = %10
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %13, i32 1069128, i32 %21)
%23 = call i32 @fwrite(i8* %20, i32 6, i32 1, i32* %13)
%24 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %13, i32 2468232, i32 %25)
%27 = call i32 @fwrite(i8* %24, i32 12, i32 1, i32* %13)
%28 = tail call i32 @fclose(i32* %13)
%29 = load i32, i32* @EXIT_SUCCESS
br label %30
30: ; preds = %15, %19, %6
%31 = phi i32 [ %9, %6 ], [ %18, %15 ], [ %29, %19 ]
ret i32 %31
}