#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_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ min(int, int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    write(STDOUT_FILENO, "Utilização: ./a.out source dest\n", 34);
    return 1;
  }
  char buffer[10240];
  int src;
  int dst;
  int status, lSize;
  src = open(argv[1], O_RDONLY);
  if (src == -1) {
    printf("There was an error opening the file %s for reading!\n", argv[1]);
    exit(1);
  }
  dst = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0555);
  if (dst == -1) {
    printf("There was an error opening the file %s for writing!\n", argv[2]);
    exit(1);
  }
  lSize = lseek(src, 0, SEEK_END);
  lseek(src, 0, SEEK_SET);
  if (lSize > 10240) {
    printf("Source file is bigger than the available buffer! However, there "
           "are loops!\n");
  }
  int i = 1;
  while ((status = read(src, buffer, min(lSize, 10240)))) {
    write(dst, buffer, status);
    lSize -= status;
    i++;
  }
  close(dst);
  close(src);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c9 <main+0x49>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x22,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    137a <main+0x1fa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x2814(%rbp)
cmpl   $0xffffffff,-0x2814(%rbp)
jne    1214 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    0x2dc4(%rip),%rax
or     (%rax),%esi
mov    0x2dc3(%rip),%rax
or     (%rax),%esi
mov    $0x16d,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x2818(%rbp)
cmpl   $0xffffffff,-0x2818(%rbp)
jne    1276 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x2814(%rbp),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x2820(%rbp)
mov    -0x2814(%rbp),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmpl   $0x2800,-0x2820(%rbp)
jle    12c6 <main+0x146>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x2824(%rbp)
mov    -0x2814(%rbp),%eax
mov    %eax,-0x2834(%rbp)
lea    -0x2810(%rbp),%rax
mov    %rax,-0x2830(%rbp)
mov    -0x2820(%rbp),%edi
mov    $0x2800,%esi
call   1050 <min@plt>
mov    -0x2834(%rbp),%edi
mov    -0x2830(%rbp),%rsi
mov    %eax,%edx
call   1080 <read@plt>
mov    %eax,-0x281c(%rbp)
cmp    $0x0,%eax
je     135d <main+0x1dd>
mov    -0x2818(%rbp),%edi
lea    -0x2810(%rbp),%rsi
mov    -0x281c(%rbp),%edx
call   1030 <write@plt>
mov    -0x281c(%rbp),%ecx
mov    -0x2820(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2820(%rbp)
mov    -0x2824(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2824(%rbp)
jmp    12d0 <main+0x150>
mov    -0x2818(%rbp),%edi
call   1070 <close@plt>
mov    -0x2814(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2800,%rsp
cmp    $0x3,%edi
jne    12a2 <main+0x112>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     12d1 <main+0x141>
mov    %eax,%r14d
mov    0x2dd6(%rip),%rax
mov    0x2e17(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
mov    $0x16d,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     12de <main+0x14e>
mov    %eax,%r15d
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,%ebx
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0x2801,%ebx
jl     123e <main+0xae>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    $0x2800,%esi
call   1060 <min@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    %eax,%edx
call   1090 <read@plt>
test   %eax,%eax
je     128e <main+0xfe>
mov    %eax,%ebp
mov    %rsp,%r12
mov    %r15d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
sub    %ebp,%ebx
mov    %ebx,%edi
mov    $0x2800,%esi
call   1060 <min@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1090 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1260 <main+0xd0>
mov    %r15d,%edi
call   1080 <close@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    12c1 <main+0x131>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    $0x22,%edx
call   1040 <write@plt>
mov    $0x1,%eax
add    $0x2800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rsi
lea    0xd47(%rip),%rdi
jmp    12e9 <main+0x159>
mov    0x10(%rbx),%rsi
lea    0xd6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [35 x i8] c"Utiliza\C3\A7\C3\A3o: ./a.out source dest\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [53 x i8] c"There was an error opening the file %s for reading!\0A\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.2 = [53 x i8] c"There was an error opening the file %s for writing!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [76 x i8] c"Source file is bigger than the available buffer! However, there are loops!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10240 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 34)
store i32 1, i32* %3
br label %83
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 (i8*, i32, ...) @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %31
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_WRONLY
%36 = load i32, i32* @O_TRUNC
%37 = or i32 %35, %36
%38 = load i32, i32* @O_CREAT
%39 = or i32 %37, %38
%40 = call i32 (i8*, i32, ...) @open(i8* %34, i32 %39, i32 365)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %49
43: ; preds = %31
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %31
%50 = load i32, i32* %7
%51 = load i32, i32* @SEEK_END
%52 = call i32 @lseek(i32 %50, i32 0, i32 %51)
store i32 %52, i32* %10
%53 = load i32, i32* %7
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %53, i32 0, i32 %54)
%56 = load i32, i32* %10
%57 = icmp sgt i32 %56, 10240
br i1 %57, label %58, label %60
58: ; preds = %49
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %49
store i32 1, i32* %11
br label %61
61: ; preds = %68, %60
%62 = load i32, i32* %7
%63 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%64 = load i32, i32* %10
%65 = call i32 @min(i32 %64, i32 10240)
%66 = call i32 @read(i32 %62, i8* %63, i32 %65)
store i32 %66, i32* %9
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %78
68: ; preds = %61
%69 = load i32, i32* %8
%70 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%71 = load i32, i32* %9
%72 = call i32 @write(i32 %69, i8* %70, i32 %71)
%73 = load i32, i32* %9
%74 = load i32, i32* %10
%75 = sub nsw i32 %74, %73
store i32 %75, i32* %10
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 1
store i32 %77, i32* %11
br label %61
78: ; preds = %61
%79 = load i32, i32* %8
%80 = call i32 @close(i32 %79)
%81 = load i32, i32* %7
%82 = call i32 @close(i32 %81)
store i32 0, i32* %3
br label %83
83: ; preds = %78, %14
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [35 x i8] c"Utiliza\C3\A7\C3\A3o: ./a.out source dest\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [53 x i8] c"There was an error opening the file %s for reading!\0A\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.2 = [53 x i8] c"There was an error opening the file %s for writing!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [75 x i8] c"Source file is bigger than the available buffer! However, there are loops!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10240 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @STDOUT_FILENO
%7 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 34)
br label %56
8: ; preds = %2
%9 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i8*, i8** %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_TRUNC
%24 = or i32 %23, %22
%25 = load i32, i32* @O_CREAT
%26 = or i32 %24, %25
%27 = tail call i32 (i8*, i32, ...) @open(i8* %21, i32 %26, i32 365)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %19
%30 = load i8*, i8** %20
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %19
%34 = load i32, i32* @SEEK_END
%35 = tail call i32 @lseek(i32 %13, i32 0, i32 %34)
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @lseek(i32 %13, i32 0, i32 %36)
%38 = icmp sgt i32 %35, 10240
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %39, %33
%42 = tail call i32 @min(i32 %35, i32 10240)
%43 = call i32 @read(i32 %13, i8* %9, i32 %42)
%44 = icmp eq i32 %43, 0
br i1 %44, label %53, label %45
45: ; preds = %41, %45
%46 = phi i32 [ %51, %45 ], [ %43, %41 ]
%47 = phi i32 [ %49, %45 ], [ %35, %41 ]
%48 = call i32 @write(i32 %27, i8* %9, i32 %46)
%49 = sub nsw i32 %47, %46
%50 = tail call i32 @min(i32 %49, i32 10240)
%51 = call i32 @read(i32 %13, i8* %9, i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %45
53: ; preds = %45, %41
%54 = tail call i32 @close(i32 %27)
%55 = tail call i32 @close(i32 %13)
br label %56
56: ; preds = %53, %5
%57 = phi i32 [ 1, %5 ], [ 0, %53 ]
ret i32 %57
}