#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 /*<<< orphan*/ copy_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *boot, *sys, *img;
  char buf[512];
  if (argc != 4) {
    fprintf(stderr, "Usage: build boot system image\n");
    exit(0);
  }
  boot = fopen(argv[1], "rb");
  if (boot == NULL) {
    fprintf(stderr, "File Open Error:%s", argv[1]);
    exit(0);
  }
  sys = fopen(argv[2], "rb");
  if (sys == NULL) {
    fprintf(stderr, "File Open Error:%s", argv[2]);
    exit(0);
  }
  img = fopen(argv[3], "wb");
  if (img == NULL) {
    fprintf(stderr, "File Open Error:%s", argv[3]);
    exit(0);
  }
  fread(buf, 512, 1, boot);
  fwrite(buf, 512, 1, img);
  copy_file(img, sys);
  fseek(img, (80 * 18 * 2 * 512) - 1, 0);
  fputc(0, img);
  fclose(img);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11ca <main+0x3a>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1213 <main+0x83>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdfe(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125c <main+0xcc>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdcb(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12a5 <main+0x115>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <copy_file@plt>
mov    -0x28(%rbp),%rdi
mov    $0x167fff,%esi
xor    %edx,%edx
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputc@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
cmp    $0x4,%edi
jne    1268 <main+0xd8>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1286 <main+0xf6>
mov    %rax,%r15
mov    0x10(%r14),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1295 <main+0x105>
mov    %rax,%r12
mov    0x18(%r14),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12a4 <main+0x114>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <copy_file@plt>
mov    %rbx,%rdi
mov    $0x167fff,%esi
xor    %edx,%edx
call   1080 <fseek@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
jmp    12b1 <main+0x121>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
jmp    12b1 <main+0x121>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    0x18(%r14),%rdx
lea    0xd6b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: build boot system image\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"File Open Error:%s\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [512 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %5
%20 = load i32*, i32** %5
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %15
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %43
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %29
%44 = load i8**, i8*** %4
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %47, i32** %7
%48 = load i32*, i32** %7
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %57
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %4
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %43
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%59 = load i32*, i32** %5
%60 = call i32 @fread(i8* %58, i32 512, i32 1, i32* %59)
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%62 = load i32*, i32** %7
%63 = call i32 @fwrite(i8* %61, i32 512, i32 1, i32* %62)
%64 = load i32*, i32** %7
%65 = load i32*, i32** %6
%66 = call i32 @copy_file(i32* %64, i32* %65)
%67 = load i32*, i32** %7
%68 = call i32 @fseek(i32* %67, i32 1474559, i32 0)
%69 = load i32*, i32** %7
%70 = call i32 @fputc(i32 0, i32* %69)
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: build boot system image\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"File Open Error:%s\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
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 %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %21
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = tail call i32 @exit(i32 0)
unreachable
30: ; preds = %20
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %31
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = tail call i32 @exit(i32 0)
unreachable
40: ; preds = %30
%41 = call i32 @fread(i8* %4, i32 512, i32 1, i32* %13)
%42 = call i32 @fwrite(i8* %4, i32 512, i32 1, i32* %33)
%43 = tail call i32 @copy_file(i32* %33, i32* %23)
%44 = tail call i32 @fseek(i32* %33, i32 1474559, i32 0)
%45 = tail call i32 @fputc(i32 0, i32* %33)
%46 = tail call i32 @fclose(i32* %33)
ret i32 0
}