#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd_s, fd_t, flag;
  char buf[512];
  fd_s = open(argv[1], O_RDONLY);
  fd_t = open(argv[2], O_RDWR | O_CREAT, 0777);
  while ((flag = read(fd_s, buf, 512)) > 0)
    write(fd_t, buf, flag);
  close(fd_s);
  close(fd_t);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11d4 <main+0x94>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
jmp    119d <main+0x5d>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%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    0x8(%rsi),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    0x2e70(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x200,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11c0 <main+0x80>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11a0 <main+0x60>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = 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 i32
%9 = alloca [512 x i8]
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 i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDWR
%19 = load i32, i32* @O_CREAT
%20 = or i32 %18, %19
%21 = call i32 (i8*, i32, ...) @open(i8* %17, i32 %20, i32 511)
store i32 %21, i32* %7
br label %22
22: ; preds = %27, %2
%23 = load i32, i32* %6
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 512)
store i32 %25, i32* %8
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %7
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %8
%31 = call i32 @write(i32 %28, i8* %29, i32 %30)
br label %22
32: ; preds = %22
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = 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 i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 (i8*, i32, ...) @open(i8* %6, i32 %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = tail call i32 (i8*, i32, ...) @open(i8* %10, i32 %13, i32 511)
%15 = call i32 @read(i32 %8, i8* %4, i32 512)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %2, %17
%18 = phi i32 [ %20, %17 ], [ %15, %2 ]
%19 = call i32 @write(i32 %14, i8* %4, i32 %18)
%20 = call i32 @read(i32 %8, i8* %4, i32 512)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %2
%23 = tail call i32 @close(i32 %8)
%24 = tail call i32 @close(i32 %14)
ret i32 0
}