#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_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ free(void *);
void *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, void *, int);
char *strerror(int);
int write(int, void *, int);
int main(int argc, char **argv) {
  void *buf;
  int sf, df, rb, wb;
  int going = 1;
  int e = 0;
  if (argc != 3) {
    printf("usage: cpnt <sourcefile> <destfile>\n");
    printf("       sorry, only one file at a time yet.\n");
    return (1);
  }
  buf = malloc(16384);
  if (!buf) {
    printf("cpnt: could not allocate buffer\n");
    return (1);
  }
  sf = open(argv[1], O_RDONLY);
  if (sf < 0) {
    e = errno;
    printf("cpnt: %s: %s\n", argv[1], strerror(e));
    return (1);
  }
  df = open(argv[2], O_WRONLY | O_CREAT, 00666);
  if (df < 0) {
    e = errno;
    printf("cpnt: %s: %s\n", argv[2], strerror(e));
    return (1);
  }
  while (going) {
    rb = read(sf, buf, 16384);
    if (rb < 0) {
      e = errno;
      printf("cpnt: error while reading: %s\n", strerror(e));
      going = 0;
      break;
    }
    if (rb == 0)
      going = 0;
    wb = write(df, buf, rb);
    if (wb < 0) {
      e = errno;
      printf("cpnt: error while writing: %s\n", strerror(e));
      going = 0;
    }
  }
  close(sf);
  close(df);
  free(buf);
  return (e ? 1 : 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d6 <main+0x56>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cb <main+0x24b>
mov    $0x4000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1209 <main+0x89>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cb <main+0x24b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    126f <main+0xef>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cb <main+0x24b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
mov    0x2d71(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12e3 <main+0x163>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cb <main+0x24b>
jmp    12e8 <main+0x168>
cmpl   $0x0,-0x2c(%rbp)
je     139f <main+0x21f>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4000,%edx
call   1070 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1341 <main+0x1c1>
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
jmp    139f <main+0x21f>
cmpl   $0x0,-0x24(%rbp)
jne    1352 <main+0x1d2>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    139a <main+0x21a>
mov    0x2c5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
jmp    12e8 <main+0x168>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1256 <main+0xc6>
mov    %rsi,%rbp
mov    $0x4000,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     126b <main+0xdb>
mov    %rax,%rbx
mov    0x8(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     127e <main+0xee>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     128d <main+0xfd>
mov    %eax,%r15d
lea    0xdfe(%rip),%r12
lea    0xe16(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4000,%edx
call   1080 <read@plt>
test   %eax,%eax
js     12bd <main+0x12d>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %eax,%eax
js     12ba <main+0x12a>
test   %ebp,%ebp
jne    1220 <main+0x90>
xor    %ebp,%ebp
jmp    12e5 <main+0x155>
lea    0xe0f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe27(%rip),%rdi
jmp    1272 <main+0xe2>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    12fd <main+0x16d>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rbx
jmp    129a <main+0x10a>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%rbx
call   10b0 <strerror@plt>
lea    0xd5a(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebp
jmp    12fd <main+0x16d>
mov    %r13,%r12
mov    0x2d0c(%rip),%rax
mov    (%rax),%r13d
mov    %r13d,%edi
call   10b0 <strerror@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %ebp,%ebp
test   %r13d,%r13d
setne  %bpl
mov    %r14d,%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"usage: cpnt <sourcefile> <destfile>\0A\00"
@.str.1 = [44 x i8] c" sorry, only one file at a time yet.\0A\00"
@.str.2 = [33 x i8] c"cpnt: could not allocate buffer\0A\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.3 = [14 x i8] c"cpnt: %s: %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.4 = [31 x i8] c"cpnt: error while reading: %s\0A\00"
@.str.5 = [31 x i8] c"cpnt: error while writing: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %101
18: ; preds = %2
%19 = call i8* @malloc(i32 16384)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %101
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 (i8*, i32, ...) @open(i8* %27, i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %24
%33 = load i32, i32* @errno
store i32 %33, i32* %12
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* %12
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* %38)
store i32 1, i32* %3
br label %101
40: ; preds = %24
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = load i32, i32* @O_WRONLY
%45 = load i32, i32* @O_CREAT
%46 = or i32 %44, %45
%47 = call i32 (i8*, i32, ...) @open(i8* %43, i32 %46, i32 438)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %40
%51 = load i32, i32* @errno
store i32 %51, i32* %12
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = load i32, i32* %12
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %54, i8* %56)
store i32 1, i32* %3
br label %101
58: ; preds = %40
br label %59
59: ; preds = %89, %58
%60 = load i32, i32* %11
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %90
62: ; preds = %59
%63 = load i32, i32* %7
%64 = load i8*, i8** %6
%65 = call i32 @read(i32 %63, i8* %64, i32 16384)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %62
%69 = load i32, i32* @errno
store i32 %69, i32* %12
%70 = load i32, i32* %12
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %71)
store i32 0, i32* %11
br label %90
73: ; preds = %62
%74 = load i32, i32* %9
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %73
store i32 0, i32* %11
br label %77
77: ; preds = %76, %73
%78 = load i32, i32* %8
%79 = load i8*, i8** %6
%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 = icmp slt i32 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %77
%85 = load i32, i32* @errno
store i32 %85, i32* %12
%86 = load i32, i32* %12
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %87)
store i32 0, i32* %11
br label %89
89: ; preds = %84, %77
br label %59
90: ; preds = %68, %59
%91 = load i32, i32* %7
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* %8
%94 = call i32 @close(i32 %93)
%95 = load i8*, i8** %6
%96 = call i32 @free(i8* %95)
%97 = load i32, i32* %12
%98 = icmp ne i32 %97, 0
%99 = zext i1 %98 to i64
%100 = select i1 %98, i32 1, i32 0
store i32 %100, i32* %3
br label %101
101: ; preds = %90, %50, %32, %22, %15
%102 = load i32, i32* %3
ret i32 %102
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.3 = [14 x i8] c"cpnt: %s: %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.4 = [31 x i8] c"cpnt: error while reading: %s\0A\00"
@.str.5 = [31 x i8] c"cpnt: error while writing: %s\0A\00"
@str = [32 x i8] c"cpnt: could not allocate buffer\00"
@str.6 = [36 x i8] c"usage: cpnt <sourcefile> <destfile>\00"
@str.7 = [43 x i8] c" sorry, only one file at a time yet.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.7, i64 0, i64 0))
br label %56
7: ; preds = %2
%8 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %56
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* @errno
%20 = load i8*, i8** %13
%21 = tail call i8* @strerror(i32 %19)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %20, i8* %21)
br label %56
23: ; preds = %12
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = tail call i32 (i8*, i32, ...) @open(i8* %25, i32 %28, i32 438)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %23
%32 = load i32, i32* @errno
%33 = load i8*, i8** %24
%34 = tail call i8* @strerror(i32 %32)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %33, i8* %34)
br label %56
36: ; preds = %23, %42
%37 = tail call i32 @read(i32 %16, i8* %8, i32 16384)
%38 = icmp slt i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %36
%40 = tail call i32 @write(i32 %29, i8* %8, i32 %37)
%41 = icmp slt i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = icmp eq i32 %37, 0
br i1 %43, label %51, label %36
44: ; preds = %39, %36
%45 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), %36 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), %39 ]
%46 = load i32, i32* @errno
%47 = tail call i8* @strerror(i32 %46)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %45, i8* %47)
%49 = icmp ne i32 %46, 0
%50 = zext i1 %49 to i32
br label %51
51: ; preds = %42, %44
%52 = phi i32 [ %50, %44 ], [ 0, %42 ]
%53 = tail call i32 @close(i32 %16)
%54 = tail call i32 @close(i32 %29)
%55 = tail call i32 @free(i8* %8)
br label %56
56: ; preds = %51, %31, %18, %10, %4
%57 = phi i32 [ 1, %4 ], [ 1, %18 ], [ 1, %31 ], [ %52, %51 ], [ 1, %10 ]
ret i32 %57
}