#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int, ...);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char **argv) {
  int source = open(argv[1], O_RDONLY);
  if (source == -1) {
    error(1, errno, "The source file %s failed to open.", argv[1]);
  }
  int target = open(argv[2], O_WRONLY | O_CREAT, S_IRWXU);
  if (target == -1) {
    error(1, errno, "The target file %s failed to open.", argv[2]);
  }
  static char buf[512];
  int bytes_read = read(source, buf, 446);
  if (bytes_read == -1) {
    error(1, errno, "Reading from source file failed.");
  }
  memset(buf + 446, 0xff, 64);
  buf[510] = 0x55;
  buf[511] = 0xaa;
  int bytes_written = write(target, buf, 512);
  if (bytes_written == -1) {
    error(1, errno, "Writing to target failed.");
  }
  close(source);
  close(target);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11bf <main+0x5f>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x1,%edi
lea    0xe48(%rip),%rdx
mov    $0x0,%al
call   1070 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    121a <main+0xba>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x1,%edi
lea    0xe10(%rip),%rdx
mov    $0x0,%al
call   1070 <error@plt>
mov    -0x14(%rbp),%edi
lea    0x2e5c(%rip),%rsi
mov    $0x1be,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1257 <main+0xf7>
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdf6(%rip),%rdx
mov    $0x0,%al
call   1070 <error@plt>
lea    0x2fe0(%rip),%rdi
mov    $0xff,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movb   $0x55,0x300a(%rip)
movb   $0xaa,0x3004(%rip)
mov    -0x18(%rbp),%edi
lea    0x2dfb(%rip),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12b8 <main+0x158>
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdb6(%rip),%rdx
mov    $0x0,%al
call   1070 <error@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11a3 <main+0x43>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rbx),%rcx
lea    0xe69(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <error@plt>
mov    0x10(%rbx),%rdi
mov    0x2e0a(%rip),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11f0 <main+0x90>
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    0x10(%rbx),%rcx
lea    0xe3f(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <error@plt>
lea    0x2e89(%rip),%rsi
mov    %r14d,%edi
mov    $0x1be,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0xc5>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <error@plt>
lea    0x3012(%rip),%rdi
mov    $0xff,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    0x2e3e(%rip),%rsi
movw   $0xaa55,0x3033(%rip)
55 aa
mov    %ebp,%edi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1278 <main+0x118>
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
lea    0xdfb(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <error@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"The source file %s failed to open.\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [35 x i8] c"The target file %s failed to open.\00"
@main.buf = internal global [512 x i8] zeroinitializer
@.str.2 = [33 x i8] c"Reading from source file failed.\00"
@.str.3 = [26 x i8] c"Writing to target failed.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %17, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRWXU
%31 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %40
34: ; preds = %23
%35 = load i32, i32* @errno
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %34, %23
%41 = load i32, i32* %6
%42 = call i32 @read(i32 %41, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 0), i32 446)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* @errno
%47 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %45, %40
%49 = call i32 @memset(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 446), i32 255, i32 64)
store i8 85, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 510)
store i8 -86, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 511)
%50 = load i32, i32* %7
%51 = call i32 @write(i32 %50, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 0), i32 512)
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* @errno
%56 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %55, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %54, %48
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* %7
%61 = call i32 @close(i32 %60)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"The source file %s failed to open.\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [35 x i8] c"The target file %s failed to open.\00"
@main.buf = internal global [512 x i8] zeroinitializer
@.str.2 = [33 x i8] c"Reading from source file failed.\00"
@.str.3 = [26 x i8] c"Writing to target failed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 (i8*, i32, ...) @open(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = load i8*, i8** %3
%11 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %8, %2
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = load i32, i32* @S_IRWXU
%19 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %12
%22 = load i32, i32* @errno
%23 = load i8*, i8** %13
%24 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %12
%26 = tail call i32 @read(i32 %6, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 0), i32 446)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @errno
%30 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %28, %25
%32 = tail call i32 @memset(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 446), i32 255, i32 64)
store i8 85, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 510)
store i8 -86, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 511)
%33 = tail call i32 @write(i32 %19, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @main.buf, i64 0, i64 0), i32 512)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* @errno
%37 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %35, %31
%39 = tail call i32 @close(i32 %6)
%40 = tail call i32 @close(i32 %19)
ret i32 0
}