#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 int ssize_t;
typedef int mode_t;

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, size_t);
int /*<<< orphan*/ stderr;
int write(int, char *, size_t);
int main(int argc, char **argv) {
  char *inputFile;
  char *copiedFile;
  char *buf;
  int input;
  int output;
  if (argc == 3) {
    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    inputFile = argv[1];
    copiedFile = argv[2];
    input = open(inputFile, O_RDONLY | O_CREAT);
    output = open(copiedFile, O_WRONLY | O_CREAT | O_TRUNC, mode);
    buf = malloc(128 * sizeof(char));
    size_t nbytes;
    ssize_t bytes_read;
    ssize_t bytes_written;
    int totalBytes;
    while (1) {
      nbytes = 128;
      bytes_read = read(input, buf, nbytes);
      totalBytes += bytes_read;
      if (bytes_read < 128) {
        bytes_written = write(output, buf, (size_t)bytes_read);
        break;
      }
      bytes_written = write(output, buf, nbytes);
    }
    printf("copied %d bytes\n", totalBytes);
    free(buf);
    close(input);
    close(output);
    exit(0);
  } else {
    fprintf(stderr, "Please enter two arguments.\n");
    exit(1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    12eb <main+0x15b>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    0x2e08(%rip),%rcx
or     (%rcx),%eax
mov    0x2de7(%rip),%rcx
or     (%rcx),%eax
mov    0x2dfe(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcd(%rip),%rcx
or     (%rcx),%eax
mov    0x2da4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
mov    0x2de3(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
or     (%rax),%esi
mov    0x2db2(%rip),%rax
or     (%rax),%esi
mov    -0x34(%rbp),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x30(%rbp)
mov    $0x80,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x80,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1070 <read@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x80,-0x44(%rbp)
jge    12a4 <main+0x114>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x44(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x48(%rbp)
jmp    12bc <main+0x12c>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x48(%rbp)
jmp    125b <main+0xcb>
mov    -0x4c(%rbp),%esi
lea    0xd3a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xd16(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    12b4 <main+0x124>
mov    0x2df9(%rip),%rax
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2df7(%rip),%rax
or     (%rax),%ebx
mov    0x2e0e(%rip),%rax
or     (%rax),%ebx
mov    0x2ddd(%rip),%rax
or     (%rax),%ebx
mov    0x2db4(%rip),%rax
or     (%rax),%ebx
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbp
mov    0x2df3(%rip),%rax
mov    0x2e0c(%rip),%r14
mov    (%r14),%esi
or     (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
mov    0x2d91(%rip),%rcx
mov    (%r14),%esi
or     (%rcx),%esi
mov    %eax,%r14d
mov    0x2de2(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%r15d
mov    $0x80,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x80,%edx
mov    %r14d,%edi
mov    %rax,%rsi
call   1070 <read@plt>
cmp    $0x80,%eax
jl     1279 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x80,%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
mov    $0x80,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
add    %eax,%ebp
cmp    $0x80,%eax
jge    1250 <main+0xc0>
movslq %eax,%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
lea    0xd72(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str = [17 x i8] c"copied %d bytes\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Please enter two arguments.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %81
18: ; preds = %2
%19 = load i32, i32* @S_IRUSR
%20 = load i32, i32* @S_IWUSR
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IRGRP
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IWGRP
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IROTH
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IWOTH
%29 = or i32 %27, %28
store i32 %29, i32* %11
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
store i8* %32, i8** %6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
store i8* %35, i8** %7
%36 = load i8*, i8** %6
%37 = load i32, i32* @O_RDONLY
%38 = load i32, i32* @O_CREAT
%39 = or i32 %37, %38
%40 = call i32 (i8*, i32, ...) @open(i8* %36, i32 %39)
store i32 %40, i32* %9
%41 = load i8*, i8** %7
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_CREAT
%44 = or i32 %42, %43
%45 = load i32, i32* @O_TRUNC
%46 = or i32 %44, %45
%47 = load i32, i32* %11
%48 = call i32 (i8*, i32, ...) @open(i8* %41, i32 %46, i32 %47)
store i32 %48, i32* %10
%49 = call i8* @malloc(i32 128)
store i8* %49, i8** %8
br label %50
50: ; preds = %18, %66
store i64 128, i64* %12
%51 = load i32, i32* %9
%52 = load i8*, i8** %8
%53 = load i64, i64* %12
%54 = call i32 @read(i32 %51, i8* %52, i64 %53)
store i32 %54, i32* %13
%55 = load i32, i32* %13
%56 = load i32, i32* %15
%57 = add nsw i32 %56, %55
store i32 %57, i32* %15
%58 = load i32, i32* %13
%59 = icmp slt i32 %58, 128
br i1 %59, label %60, label %66
60: ; preds = %50
%61 = load i32, i32* %10
%62 = load i8*, i8** %8
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = call i32 @write(i32 %61, i8* %62, i64 %64)
store i32 %65, i32* %14
br label %71
66: ; preds = %50
%67 = load i32, i32* %10
%68 = load i8*, i8** %8
%69 = load i64, i64* %12
%70 = call i32 @write(i32 %67, i8* %68, i64 %69)
store i32 %70, i32* %14
br label %50
71: ; preds = %60
%72 = load i32, i32* %15
%73 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %72)
%74 = load i8*, i8** %8
%75 = call i32 @free(i8* %74)
%76 = load i32, i32* %9
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %10
%79 = call i32 @close(i32 %78)
%80 = call i32 @exit(i32 0)
unreachable
81: ; preds = %2
%82 = load i32, i32* @stderr
%83 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str = [17 x i8] c"copied %d bytes\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Please enter two arguments.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %49
4: ; preds = %2
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRGRP
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IWOTH
%15 = or i32 %13, %14
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %21, %20
%23 = tail call i32 (i8*, i32, ...) @open(i8* %17, i32 %22)
%24 = load i32, i32* @O_WRONLY
%25 = load i32, i32* @O_CREAT
%26 = or i32 %25, %24
%27 = load i32, i32* @O_TRUNC
%28 = or i32 %26, %27
%29 = tail call i32 (i8*, i32, ...) @open(i8* %19, i32 %28, i32 %15)
%30 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%31 = tail call i32 @read(i32 %23, i8* %30, i64 128)
%32 = icmp slt i32 %31, 128
br i1 %32, label %33, label %43
33: ; preds = %43, %4
%34 = phi i32 [ %31, %4 ], [ %46, %43 ]
%35 = phi i32 [ undef, %4 ], [ %47, %43 ]
%36 = sext i32 %34 to i64
%37 = tail call i32 @write(i32 %29, i8* %30, i64 %36)
%38 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %35)
%39 = tail call i32 @free(i8* %30)
%40 = tail call i32 @close(i32 %23)
%41 = tail call i32 @close(i32 %29)
%42 = tail call i32 @exit(i32 0)
unreachable
43: ; preds = %4, %43
%44 = phi i32 [ %47, %43 ], [ undef, %4 ]
%45 = tail call i32 @write(i32 %29, i8* %30, i64 128)
%46 = tail call i32 @read(i32 %23, i8* %30, i64 128)
%47 = add nsw i32 %46, %44
%48 = icmp slt i32 %46, 128
br i1 %48, label %33, label %43
49: ; preds = %2
%50 = load i32, i32* @stderr
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%52 = tail call i32 @exit(i32 1)
unreachable
}