#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 executable library\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;
  }
  FILE *fp_lib = fopen(argv[2], "r+");
  if (fp_lib == NULL) {
    fclose(fp);
    printf("can't library open %s\n ", argv[1]);
    return EXIT_FAILURE;
  }
  char magic_bytes[6] = {0x90, 0x90, 0x30, 0xc0, 0xfe, 0xc0};
  fseek(fp, 0x000f40dc, SEEK_SET);
  fwrite(magic_bytes, 6, 1, fp);
  fclose(fp);
  char allow_disassembling[6] = {0x90, 0xe9, 0x8f, 0x00, 0x00, 0x00};
  fseek(fp_lib, 0x507478, SEEK_SET);
  fwrite(allow_disassembling, 6, 1, fp_lib);
  fclose(fp_lib);
  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    12cf <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7b(%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    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cf <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe33(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122d <main+0xdd>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cf <main+0x17f>
mov    0xe16(%rip),%eax
mov    %eax,-0x26(%rbp)
mov    0xe10(%rip),%ax
mov    %ax,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
mov    $0xf40dc,%esi
call   1050 <fseek@plt>
lea    -0x26(%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    0xdd1(%rip),%eax
mov    %eax,-0x2c(%rbp)
mov    0xdcb(%rip),%ax
mov    %ax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
mov    $0x507478,%esi
call   1050 <fseek@plt>
lea    -0x2c(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d06(%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   %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    124f <main+0xff>
mov    0x8(%rbx),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122f <main+0xdf>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     123c <main+0xec>
mov    %rax,%r14
movw   $0xc0fe,0xc(%rsp)
movl   $0xc0309090,0x8(%rsp)
c0
mov    0x2e22(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0xf40dc,%esi
call   1050 <fseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
movw   $0x0,0x4(%rsp)
movl   $0x8fe990,(%rsp)
mov    (%rbx),%edx
mov    %r14,%rdi
mov    $0x507478,%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    0x2da3(%rip),%rax
jmp    125b <main+0x10b>
mov    0x8(%rbx),%rsi
lea    0xde7(%rip),%rdi
jmp    124f <main+0xff>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x8(%rbx),%rsi
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"usage: %s executable library\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"
@.str.3 = [24 x i8] c"can't library open %s\0A \00"
@__const.main.magic_bytes = [6 x i8] c"\90\900\C0\FE\C0"
@SEEK_SET = global i32 0
@__const.main.allow_disassembling = [6 x i8] c"\90\E9\8F\00\00\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%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 ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
br label %41
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 %41
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = tail call i32 @fclose(i32* %13)
%26 = load i8*, i8** %11
%27 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
br label %41
29: ; preds = %19
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%31 = load i32, i32* @SEEK_SET
%32 = tail call i32 @fseek(i32* %13, i32 999644, i32 %31)
%33 = call i32 @fwrite(i8* %30, i32 6, i32 1, i32* %13)
%34 = tail call i32 @fclose(i32* %13)
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @fseek(i32* %22, i32 5272696, i32 %36)
%38 = call i32 @fwrite(i8* %35, i32 6, i32 1, i32* %22)
%39 = tail call i32 @fclose(i32* %22)
%40 = load i32, i32* @EXIT_SUCCESS
br label %41
41: ; preds = %15, %29, %24, %6
%42 = phi i32 [ %9, %6 ], [ %18, %15 ], [ %28, %24 ], [ %40, %29 ]
ret i32 %42
}