#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*/ EXIT_FAILURE;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fdin, fdout;
  char buf[8192] = {0};
  if (argc != 3)
    do {
      perror("usage: rwcp input output");
      exit(EXIT_FAILURE);
    } while (0);
  fdin = open(argv[1], O_RDONLY);
  if (fdin < 0)
    do {
      perror("open input");
      exit(EXIT_FAILURE);
    } while (0);
  fdout = open(argv[2], O_RDWR | O_CREAT | O_TRUNC,
               (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
  if (fdout < 0)
    do {
      perror("create output");
      exit(EXIT_FAILURE);
    } while (0);
  int rd = 0, wr = 0;
  while (1) {
    rd = read(fdin, buf, 8192);
    if (rd < 0)
      do {
        perror("read input");
        exit(EXIT_FAILURE);
      } while (0);
    else if (rd == 0)
      break;
    wr = write(fdout, buf, rd);
    if (wr < rd)
      do {
        perror("write output");
        exit(EXIT_FAILURE);
      } while (0);
  }
  printf("copy over\n");
  close(fdin);
  close(fdout);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
je     11d5 <main+0x55>
jmp    11bb <main+0x3b>
lea    0xe3e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1219 <main+0x99>
jmp    11ff <main+0x7f>
lea    0xe13(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    0x2dc7(%rip),%rax
or     (%rax),%esi
mov    0x2db6(%rip),%rax
or     (%rax),%esi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
mov    0x2d7c(%rip),%rax
or     (%rax),%edx
mov    0x2d63(%rip),%rax
or     (%rax),%edx
mov    0x2d52(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1293 <main+0x113>
jmp    1279 <main+0xf9>
lea    0xda4(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x0,-0x2024(%rbp)
movl   $0x0,-0x2028(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jge    12ed <main+0x16d>
jmp    12d3 <main+0x153>
lea    0xd58(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x2024(%rbp)
jne    12ff <main+0x17f>
jmp    1355 <main+0x1d5>
jmp    1304 <main+0x184>
mov    -0x18(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    -0x2024(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x2028(%rbp)
mov    -0x2028(%rbp),%eax
cmp    -0x2024(%rbp),%eax
jge    1350 <main+0x1d0>
jmp    1336 <main+0x1b6>
lea    0xd00(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12a7 <main+0x127>
lea    0xcee(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x2000,%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x3,%ebx
jne    11ca <main+0x4a>
mov    0x8(%r14),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
jns    11d6 <main+0x56>
lea    0xe54(%rip),%rdi
jmp    1279 <main+0xf9>
lea    0xe2f(%rip),%rdi
jmp    1279 <main+0xf9>
mov    %eax,%r15d
mov    0x2df8(%rip),%rax
mov    0x2e11(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfe(%rip),%rax
or     (%rax),%esi
mov    0x2da5(%rip),%rax
mov    0x2dc6(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dab(%rip),%rax
or     (%rax),%edx
mov    0x10(%r14),%rdi
mov    0x2d96(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
jns    1230 <main+0xb0>
lea    0xdf6(%rip),%rdi
jmp    1279 <main+0xf9>
mov    %eax,%r14d
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
test   %eax,%eax
js     1272 <main+0xf2>
je     128c <main+0x10c>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
jge    1240 <main+0xc0>
lea    0xdcd(%rip),%rdi
jmp    1279 <main+0xf9>
lea    0xdb9(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdb7(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"usage: rwcp input output\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"open input\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [14 x i8] c"create output\00"
@.str.3 = [11 x i8] c"read input\00"
@.str.4 = [13 x i8] c"write output\00"
@.str.5 = [11 x i8] c"copy over\0A\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 [8192 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [8192 x i8]* %8 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
br label %15
15: ; preds = %14
%16 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; No predecessors!
br label %20
20: ; preds = %19, %2
%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 (i8*, i32, ...) @open(i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %20
br label %29
29: ; preds = %28
%30 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; No predecessors!
br label %34
34: ; preds = %33, %20
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDWR
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = load i32, i32* @O_TRUNC
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRUSR
%44 = load i32, i32* @S_IWUSR
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IRGRP
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IROTH
%49 = or i32 %47, %48
%50 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %42, i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %34
br label %54
54: ; preds = %53
%55 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; No predecessors!
br label %59
59: ; preds = %58, %34
store i32 0, i32* %9
store i32 0, i32* %10
br label %60
60: ; preds = %59, %91
%61 = load i32, i32* %6
%62 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%63 = call i32 @read(i32 %61, i8* %62, i32 8192)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %60
br label %67
67: ; preds = %66
%68 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; No predecessors!
br label %77
72: ; preds = %60
%73 = load i32, i32* %9
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %72
br label %92
76: ; preds = %72
br label %77
77: ; preds = %76, %71
%78 = load i32, i32* %7
%79 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%80 = load i32, i32* %9
%81 = call i32 @write(i32 %78, i8* %79, i32 %80)
store i32 %81, i32* %10
%82 = load i32, i32* %10
%83 = load i32, i32* %9
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %91
85: ; preds = %77
br label %86
86: ; preds = %85
%87 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; No predecessors!
br label %91
91: ; preds = %90, %77
br label %60
92: ; preds = %75
%93 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%94 = load i32, i32* %6
%95 = call i32 @close(i32 %94)
%96 = load i32, i32* %7
%97 = call i32 @close(i32 %96)
%98 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [25 x i8] c"usage: rwcp input output\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"open input\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [14 x i8] c"create output\00"
@.str.3 = [11 x i8] c"read input\00"
@.str.4 = [13 x i8] c"write output\00"
@str = [10 x i8] c"copy over\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = load i32, i32* @O_TRUNC
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %29, %28
%31 = load i32, i32* @S_IRGRP
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IROTH
%34 = or i32 %32, %33
%35 = tail call i32 (i8*, i32, ...) @open(i8* %22, i32 %27, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %20
%38 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %20, %50
%42 = call i32 @read(i32 %14, i8* %4, i32 8192)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %41
%49 = icmp eq i32 %42, 0
br i1 %49, label %57, label %50
50: ; preds = %48
%51 = call i32 @write(i32 %35, i8* %4, i32 %42)
%52 = icmp slt i32 %51, %42
br i1 %52, label %53, label %41
53: ; preds = %50
%54 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = tail call i32 @exit(i32 %55)
unreachable
57: ; preds = %48
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%59 = tail call i32 @close(i32 %14)
%60 = tail call i32 @close(i32 %35)
%61 = tail call i32 @exit(i32 0)
unreachable
}