#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 O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int, ...);
int read(int, char **, int);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char *argv[]) {
  int nb, fdin, fdout;
  char buf[4096];
  fdin = open(argv[1], O_RDONLY);
  fdout = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0666);
  while ((nb = read(fdin, &buf, 4096)) > 0)
    write(fdout, &buf, nb);
  close(fdin);
  close(fdout);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
mov    0x2e4b(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11ed <main+0x9d>
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
jmp    11b6 <main+0x66>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x2e5c(%rip),%rax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2e5e(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11e0 <main+0x90>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11c0 <main+0x70>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = 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 [4096 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* %7
%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 = load i32, i32* @O_TRUNC
%22 = or i32 %20, %21
%23 = call i32 (i8*, i32, ...) @open(i8* %17, i32 %22, i32 438)
store i32 %23, i32* %8
br label %24
24: ; preds = %29, %2
%25 = load i32, i32* %7
%26 = bitcast [4096 x i8]* %9 to i8**
%27 = call i32 @read(i32 %25, i8** %26, i32 4096)
store i32 %27, i32* %6
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* %8
%31 = bitcast [4096 x i8]* %9 to i8**
%32 = load i32, i32* %6
%33 = call i32 @write(i32 %30, i8** %31, i32 %32)
br label %24
34: ; preds = %24
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* %8
%38 = call i32 @close(i32 %37)
%39 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 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 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = tail call i32 (i8*, i32, ...) @open(i8* %10, i32 %15, i32 438)
%17 = bitcast [4096 x i8]* %3 to i8**
%18 = call i32 @read(i32 %8, i8** %17, i32 4096)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %2, %20
%21 = phi i32 [ %23, %20 ], [ %18, %2 ]
%22 = call i32 @write(i32 %16, i8** %17, i32 %21)
%23 = call i32 @read(i32 %8, i8** %17, i32 4096)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %20, label %25
25: ; preds = %20, %2
%26 = tail call i32 @close(i32 %8)
%27 = tail call i32 @close(i32 %16)
%28 = tail call i32 @exit(i32 0)
unreachable
}