#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 /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int src, dest, i;
  char buffer[256];
  if (argc < 3) {
    printf("cp src dest");
    return 1;
  }
  src = open(argv[1], 00);
  dest = open(argv[2], 01 | 0100);
  while ((i = read(src, buffer, 256)) > 0)
    write(dest, buffer, i);
  close(src);
  close(dest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    118b <main+0x3b>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1200 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x41,%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11e9 <main+0x99>
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
jmp    11b2 <main+0x62>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
cmp    $0x2,%edi
jg     1176 <main+0x26>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    11ef <main+0x9f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
mov    $0x41,%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x100,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11e0 <main+0x90>
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11c0 <main+0x70>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"cp src dest\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 [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %38
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @open(i8* %17, i32 0)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @open(i8* %21, i32 65)
store i32 %22, i32* %7
br label %23
23: ; preds = %28, %14
%24 = load i32, i32* %6
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 256)
store i32 %26, i32* %8
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i32, i32* %7
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%31 = load i32, i32* %8
%32 = call i32 @write(i32 %29, i8* %30, i32 %31)
br label %23
33: ; preds = %23
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %33, %12
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [12 x i8] c"cp src dest\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %25
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @open(i8* %10, i32 0)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @open(i8* %13, i32 65)
%15 = call i32 @read(i32 %11, i8* %4, i32 256)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %8, %17
%18 = phi i32 [ %20, %17 ], [ %15, %8 ]
%19 = call i32 @write(i32 %14, i8* %4, i32 %18)
%20 = call i32 @read(i32 %11, i8* %4, i32 256)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %8
%23 = tail call i32 @close(i32 %11)
%24 = tail call i32 @close(i32 %14)
br label %25
25: ; preds = %22, %6
%26 = phi i32 [ 1, %6 ], [ 0, %22 ]
ret i32 %26
}