#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, 0x000e9f3c, 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    1233 <main+0xe3>
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    1233 <main+0xe3>
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    $0xe9f3c,%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    0x2da2(%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   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1168 <main+0x18>
mov    (%rbx),%rsi
lea    0xe9a(%rip),%rdi
jmp    11d5 <main+0x85>
mov    0x8(%rbx),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ca <main+0x7a>
mov    %rax,%r14
movw   $0xc0fe,0x4(%rsp)
movl   $0xc0309090,(%rsp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0xe9f3c,%esi
call   1050 <fseek@plt>
mov    %rsp,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2e08(%rip),%rax
jmp    11e1 <main+0x91>
mov    0x8(%rbx),%rsi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
add    $0x8,%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
@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 %40
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 %40
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 958268, 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 = call i32 @fclose(i32* %37)
%39 = load i32, i32* @EXIT_SUCCESS
store i32 %39, i32* %3
br label %40
40: ; preds = %29, %23, %10
%41 = load i32, i32* %3
ret i32 %41
}

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 %25
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 %25
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 958268, i32 %20)
%22 = call i32 @fwrite(i8* %19, i32 6, i32 1, i32* %12)
%23 = tail call i32 @fclose(i32* %12)
%24 = load i32, i32* @EXIT_SUCCESS
br label %25
25: ; preds = %14, %18, %5
%26 = phi i32 [ %8, %5 ], [ %17, %14 ], [ %24, %18 ]
ret i32 %26
}