#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int BUFSIZ;
#define EAGAIN 134
#define EBADF 133
#define EFAULT 132
#define EINTR 131
#define EINVAL 130
#define EIO 129
#define EISDIR 128
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ usage();
scalar_t__ write(int, char *, scalar_t__);
int main(int argc, char **argv) {
  if (argc < 3) {
    usage();
    exit(EXIT_FAILURE);
  }
  char *dest = argv[2];
  char *src = argv[1];
  int srcfd = open(src, O_RDONLY);
  if (!srcfd) {
    perror(src);
    return EXIT_FAILURE;
  }
  int destfd = open(dest, O_CREAT | O_WRONLY);
  if (!destfd) {
    perror(dest);
    return EXIT_FAILURE;
  }
  char buffer[BUFSIZ];
  ssize_t nread;
  ssize_t written;
  while (true) {
    errno = 0;
    nread = read(srcfd, buffer, BUFSIZ);
    if (nread < 0)
      switch (errno) {
      case EAGAIN:
      case EINTR:
      default:
        continue;
      case EBADF:
      case EFAULT:
      case EINVAL:
      case EIO:
      case EISDIR:
        perror("copylas");
        exit(EXIT_FAILURE);
      }
    else if (nread == 0)
      break;
    errno = 0;
    written = write(destfd, buffer, nread);
    if (written <= 0) {
      perror(dest);
      exit(EXIT_FAILURE);
    }
  }
  errno = 0;
  close(srcfd);
  close(destfd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a5 <main+0x35>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11f6 <main+0x86>
mov    -0x20(%rbp),%rdi
call   1080 <perror@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a4 <main+0x234>
mov    -0x18(%rbp),%rdi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    0x2d9e(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1238 <main+0xc8>
mov    -0x18(%rbp),%rdi
call   1080 <perror@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a4 <main+0x234>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
jmp    1269 <main+0xf9>
mov    -0x50(%rbp),%rsi
mov    0x2d54(%rip),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jge    1317 <main+0x1a7>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
add    $0xffffff80,%eax
sub    $0x3,%eax
jb     12fd <main+0x18d>
jmp    12b7 <main+0x147>
mov    -0x54(%rbp),%eax
sub    $0x83,%eax
je     12f3 <main+0x183>
jmp    12ca <main+0x15a>
mov    -0x54(%rbp),%eax
add    $0xffffff7c,%eax
sub    $0x2,%eax
jb     12fd <main+0x18d>
jmp    12e0 <main+0x170>
mov    -0x54(%rbp),%eax
sub    $0x86,%eax
jne    12f8 <main+0x188>
jmp    12f3 <main+0x183>
jmp    12f8 <main+0x188>
jmp    1264 <main+0xf4>
lea    0xcfc(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1327 <main+0x1b7>
jmp    1374 <main+0x204>
jmp    132c <main+0x1bc>
mov    -0x50(%rbp),%rsi
mov    0x2c91(%rip),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%edi
mov    -0x40(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jg     136f <main+0x1ff>
mov    -0x18(%rbp),%rdi
call   1080 <perror@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1264 <main+0xf4>
mov    0x2c4d(%rip),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
mov    0x2c20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jle    12b5 <main+0x145>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rbx
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
test   %eax,%eax
je     1286 <main+0x116>
mov    %eax,%r12d
mov    0x2e43(%rip),%rax
mov    0x2dec(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
je     128b <main+0x11b>
mov    %eax,%r15d
mov    %rbx,-0x30(%rbp)
mov    %rsp,-0x38(%rbp)
mov    0x2dee(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2dcb(%rip),%r13
nopl   (%rax)
movl   $0x0,0x0(%r13)
mov    (%r14),%edx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1050 <read@plt>
test   %rax,%rax
js     1240 <main+0xd0>
movl   $0x0,0x0(%r13)
je     125a <main+0xea>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
test   %rax,%rax
jg     1200 <main+0x90>
jmp    129e <main+0x12e>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%eax
add    $0xffffff80,%eax
cmp    $0x5,%eax
ja     1200 <main+0x90>
cmp    $0x3,%eax
je     1200 <main+0x90>
lea    0xda8(%rip),%rdi
jmp    12a2 <main+0x132>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
jmp    128e <main+0x11e>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
jmp    1277 <main+0x107>
mov    -0x30(%rbp),%rdi
call   1080 <perror@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    12a7 <main+0x137>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@BUFSIZ = global i32 0
@errno = global i32 0
@.str = [8 x i8] c"copylas\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 (...) @usage()
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %20
%33 = load i8*, i8** %7
%34 = call i32 @perror(i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %92
36: ; preds = %20
%37 = load i8*, i8** %6
%38 = load i32, i32* @O_CREAT
%39 = load i32, i32* @O_WRONLY
%40 = or i32 %38, %39
%41 = call i32 @open(i8* %37, i32 %40)
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %36
%45 = load i8*, i8** %6
%46 = call i32 @perror(i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %3
br label %92
48: ; preds = %36
%49 = load i32, i32* @BUFSIZ
%50 = zext i32 %49 to i64
%51 = call i8* @llvm.stacksave()
store i8* %51, i8** %10
%52 = alloca i8, i64 %50
store i64 %50, i64* %11
br label %53
53: ; preds = %84, %63, %48
br label %54
54: ; preds = %53
store i32 0, i32* @errno
%55 = load i32, i32* %8
%56 = load i32, i32* @BUFSIZ
%57 = call i64 @read(i32 %55, i8* %52, i32 %56)
store i64 %57, i64* %12
%58 = load i64, i64* %12
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %68
60: ; preds = %54
%61 = load i32, i32* @errno
switch i32 %61, label %63 [
i32 134, label %62
i32 131, label %62
i32 133, label %64
i32 132, label %64
i32 130, label %64
i32 129, label %64
i32 128, label %64
]
62: ; preds = %60, %60
br label %63
63: ; preds = %60, %62
br label %53
64: ; preds = %60, %60, %60, %60, %60
%65 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %54
%69 = load i64, i64* %12
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %68
br label %85
72: ; preds = %68
br label %73
73: ; preds = %72
store i32 0, i32* @errno
%74 = load i32, i32* %9
%75 = load i64, i64* %12
%76 = call i64 @write(i32 %74, i8* %52, i64 %75)
store i64 %76, i64* %13
%77 = load i64, i64* %13
%78 = icmp sle i64 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %73
%80 = load i8*, i8** %6
%81 = call i32 @perror(i8* %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %73
br label %53
85: ; preds = %71
store i32 0, i32* @errno
%86 = load i32, i32* %8
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* %9
%89 = call i32 @close(i32 %88)
%90 = load i32, i32* @EXIT_SUCCESS
store i32 %90, i32* %3
%91 = load i8*, i8** %10
br label %92
92: ; preds = %85, %44, %32
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@BUFSIZ = global i32 0
@errno = global i32 0
@.str = [8 x i8] c"copylas\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i32 (...) @usage()
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @perror(i8* %12)
%18 = load i32, i32* @EXIT_FAILURE
br label %57
19: ; preds = %8
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_WRONLY
%22 = or i32 %21, %20
%23 = tail call i32 @open(i8* %10, i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = tail call i32 @perror(i8* %10)
%27 = load i32, i32* @EXIT_FAILURE
br label %57
28: ; preds = %19
%29 = load i32, i32* @BUFSIZ
%30 = zext i32 %29 to i64
%31 = tail call i8* @llvm.stacksave()
%32 = alloca i8, i64 %30
br label %33
33: ; preds = %48, %28
store i32 0, i32* @errno
%34 = load i32, i32* @BUFSIZ
%35 = call i64 @read(i32 %14, i8* %32, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = load i32, i32* @errno
switch i32 %38, label %48 [
i32 128, label %39
i32 129, label %39
i32 133, label %39
i32 132, label %39
i32 130, label %39
]
39: ; preds = %37, %37, %37, %37, %37
%40 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %33
%44 = icmp eq i64 %35, 0
store i32 0, i32* @errno
br i1 %44, label %53, label %45
45: ; preds = %43
%46 = call i64 @write(i32 %23, i8* %32, i64 %35)
%47 = icmp slt i64 %46, 1
br i1 %47, label %49, label %48
48: ; preds = %45, %37
br label %33
49: ; preds = %45
%50 = tail call i32 @perror(i8* %10)
%51 = load i32, i32* @EXIT_FAILURE
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %43
%54 = tail call i32 @close(i32 %14)
%55 = tail call i32 @close(i32 %23)
%56 = load i32, i32* @EXIT_SUCCESS
tail call void @llvm.stackrestore(i8* %31)
br label %57
57: ; preds = %25, %53, %16
%58 = phi i32 [ %18, %16 ], [ %56, %53 ], [ %27, %25 ]
ret i32 %58
}