#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 O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char buf[512];
  for (int i = 0; i < 512; i++)
    buf[i] = 0;
  int inputFile = open(argv[1], O_RDONLY);
  read(inputFile, buf, 510);
  close(inputFile);
  buf[510] = 0x55;
  buf[511] = 0xaa;
  int outputFile = open(argv[2], O_CREAT | O_WRONLY);
  write(outputFile, buf, 512);
  close(outputFile);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x214(%rbp)
cmpl   $0x200,-0x214(%rbp)
jge    1196 <main+0x56>
movslq -0x214(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1163 <main+0x23>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x218(%rbp)
mov    -0x218(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1fe,%edx
call   1050 <read@plt>
mov    -0x218(%rbp),%edi
call   1040 <close@plt>
movb   $0x55,-0x12(%rbp)
movb   $0xaa,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    0x2dd4(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x21c(%rbp)
mov    -0x21c(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    -0x21c(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    %rsp,%r14
mov    $0x200,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x8(%rbx),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1fe,%edx
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
movw   $0xaa55,0x1fe(%rsp)
mov    0x10(%rbx),%rdi
mov    0x2e49(%rip),%rax
mov    0x2e12(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %10
10: ; preds = %17, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 512
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %10
20: ; preds = %10
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 510)
%29 = load i32, i32* %8
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 510
store i8 85, i8* %31
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 511
store i8 -86, i8* %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_CREAT
%37 = load i32, i32* @O_WRONLY
%38 = or i32 %36, %37
%39 = call i32 @open(i8* %35, i32 %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%42 = call i32 @write(i32 %40, i8* %41, i32 512)
%43 = load i32, i32* %9
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
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 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* %7, i32 %8)
%10 = call i32 @read(i32 %9, i8* %5, i32 510)
%11 = tail call i32 @close(i32 %9)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 510
store i8 85, i8* %12
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 511
store i8 -86, i8* %13
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_WRONLY
%18 = or i32 %17, %16
%19 = tail call i32 @open(i8* %15, i32 %18)
%20 = call i32 @write(i32 %19, i8* %5, i32 512)
%21 = tail call i32 @close(i32 %19)
ret i32 0
}