#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ error(char *, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char **argv) {
  int n, fd1, fd2, size = 128;
  char buf[128];
  if (argc != 3) {
    error("usgae: cp file1 file2");
  }
  if ((fd1 = open(*++argv, O_RDONLY, 0)) == -1) {
    error("open file %s", *argv);
  }
  if ((fd2 = creat(*++argv, 0644)) == -1) {
    error("create file %s", *argv);
  }
  while ((n = read(fd1, buf, size)) > 0) {
    if (n != write(fd2, buf, n)) {
      error("writing file %s", *argv);
    }
  }
  close(fd2);
  close(fd1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x80,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11dc <main+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    121a <main+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
jmp    121f <main+0xbf>
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1282 <main+0x122>
mov    -0x14(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0xa4(%rbp),%eax
cmp    %ecx,%eax
je     127d <main+0x11d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
jmp    121f <main+0xbf>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     1187 <main+0x27>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1060 <error@plt>
mov    0x8(%r14),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11b5 <main+0x55>
mov    0x8(%r14),%rsi
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1060 <error@plt>
mov    0x10(%r14),%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    11dd <main+0x7d>
mov    0x10(%r14),%rsi
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1060 <error@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x80,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1237 <main+0xd7>
mov    %eax,%ebx
mov    %rsp,%rbp
lea    0xe35(%rip),%r12
jmp    1216 <main+0xb6>
nop
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1237 <main+0xd7>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %eax,%ebx
je     1200 <main+0xa0>
mov    0x10(%r14),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <error@plt>
jmp    1200 <main+0xa0>
mov    %r13d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"usgae: cp file1 file2\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open file %s\00"
@.str.2 = [15 x i8] c"create file %s\00"
@.str.3 = [16 x i8] c"writing file %s\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
%10 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 128, i32* %9
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19, i32 0)
store i32 %20, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i32 1
store i8** %28, i8*** %5
%29 = load i8*, i8** %28
%30 = call i32 @creat(i8* %29, i32 420)
store i32 %30, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %26
br label %37
37: ; preds = %54, %36
%38 = load i32, i32* %7
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %9
%41 = call i32 @read(i32 %38, i8* %39, i32 %40)
store i32 %41, i32* %6
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %37
%44 = load i32, i32* %6
%45 = load i32, i32* %8
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%47 = load i32, i32* %6
%48 = call i32 @write(i32 %45, i8* %46, i32 %47)
%49 = icmp ne i32 %44, %48
br i1 %49, label %50, label %54
50: ; preds = %43
%51 = load i8**, i8*** %5
%52 = load i8*, i8** %51
%53 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %50, %43
br label %37
55: ; preds = %37
%56 = load i32, i32* %8
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %7
%59 = call i32 @close(i32 %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"usgae: cp file1 file2\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open file %s\00"
@.str.2 = [15 x i8] c"create file %s\00"
@.str.3 = [16 x i8] c"writing file %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8*, i8** %9
%16 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %8
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @creat(i8* %19, i32 420)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %18
%24 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %17
%26 = call i32 @read(i32 %12, i8* %4, i32 128)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %25, %35
%29 = phi i32 [ %36, %35 ], [ %26, %25 ]
%30 = call i32 @write(i32 %20, i8* %4, i32 %29)
%31 = icmp eq i32 %29, %30
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i8*, i8** %18
%34 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %28
%36 = call i32 @read(i32 %12, i8* %4, i32 128)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %28, label %38
38: ; preds = %35, %25
%39 = tail call i32 @close(i32 %20)
%40 = tail call i32 @close(i32 %12)
ret i32 0
}