#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ min(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int /*<<< orphan*/, 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];
  FILE *src;
  FILE *dst;
  int status, lSize;
  src = fopen(argv[1], "r");
  if (src == NULL) {
    printf("There was an error opening the file %s for reading!\n", argv[1]);
    exit(1);
  }
  dst = fopen(argv[2], "w");
  if (dst == NULL) {
    printf("There was an error opening the file %s for writing!\n", argv[2]);
    exit(1);
  }
  fseek(src, 0, SEEK_END);
  lSize = ftell(src);
  rewind(src);
  if (lSize > 10240) {
    printf("Source file is bigger than the available buffer! However, there "
           "are loops!\n");
  }
  int i = 1;
  while ((status = fread(buffer, 1, min(lSize, 10240), src))) {
    fwrite(buffer, status, 1, dst);
    lSize -= status;
    i++;
  }
  fclose(dst);
  fclose(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     11f9 <main+0x49>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    $0x22,%edx
call   1040 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    1394 <main+0x1e4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x2818(%rbp)
cmpq   $0x0,-0x2818(%rbp)
jne    1242 <main+0x92>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe09(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x2820(%rbp)
cmpq   $0x0,-0x2820(%rbp)
jne    128b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x2818(%rbp),%rdi
mov    0x2d47(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x2818(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x2828(%rbp)
mov    -0x2818(%rbp),%rdi
call   1070 <rewind@plt>
cmpl   $0x2800,-0x2828(%rbp)
jle    12de <main+0x12e>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x282c(%rbp)
lea    -0x2810(%rbp),%rax
mov    %rax,-0x2838(%rbp)
mov    -0x2828(%rbp),%edi
mov    $0x2800,%esi
call   1080 <min@plt>
mov    -0x2838(%rbp),%rdi
mov    %eax,%edx
mov    -0x2818(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2824(%rbp)
cmp    $0x0,%eax
je     1375 <main+0x1c5>
lea    -0x2810(%rbp),%rdi
mov    -0x2824(%rbp),%esi
mov    -0x2820(%rbp),%rcx
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    -0x2824(%rbp),%ecx
mov    -0x2828(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2828(%rbp)
mov    -0x282c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x282c(%rbp)
jmp    12e8 <main+0x138>
mov    -0x2820(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2818(%rbp),%rdi
call   1050 <fclose@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    12cc <main+0x10c>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe3d(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12fb <main+0x13b>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe58(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1308 <main+0x148>
mov    %rax,%r14
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r15,%rdi
call   10a0 <ftell@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1080 <rewind@plt>
cmp    $0x2801,%ebp
jl     124c <main+0x8c>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    $0x2800,%esi
call   1090 <min@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     12b8 <main+0xf8>
mov    %eax,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
sub    %ebx,%ebp
mov    %ebp,%edi
mov    $0x2800,%esi
call   1090 <min@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1280 <main+0xc0>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    12eb <main+0x12b>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
mov    $0x22,%edx
call   1050 <write@plt>
mov    $0x1,%eax
add    $0x2800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rsi
lea    0xd1f(%rip),%rdi
jmp    1313 <main+0x153>
mov    0x10(%rbx),%rsi
lea    0xd49(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <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"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [53 x i8] c"There was an error opening the file %s for reading!\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [53 x i8] c"There was an error opening the file %s for writing!\0A\00"
@SEEK_END = global i32 0
@.str.5 = [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 %78
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %8
%35 = load i32*, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
%44 = load i32*, i32** %7
%45 = load i32, i32* @SEEK_END
%46 = call i32 @fseek(i32* %44, i32 0, i32 %45)
%47 = load i32*, i32** %7
%48 = call i32 @ftell(i32* %47)
store i32 %48, i32* %10
%49 = load i32*, i32** %7
%50 = call i32 @rewind(i32* %49)
%51 = load i32, i32* %10
%52 = icmp sgt i32 %51, 10240
br i1 %52, label %53, label %55
53: ; preds = %43
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %43
store i32 1, i32* %11
br label %56
56: ; preds = %63, %55
%57 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%58 = load i32, i32* %10
%59 = call i32 @min(i32 %58, i32 10240)
%60 = load i32*, i32** %7
%61 = call i32 @fread(i8* %57, i32 1, i32 %59, i32* %60)
store i32 %61, i32* %9
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %73
63: ; preds = %56
%64 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%65 = load i32, i32* %9
%66 = load i32*, i32** %8
%67 = call i32 @fwrite(i8* %64, i32 %65, i32 1, i32* %66)
%68 = load i32, i32* %9
%69 = load i32, i32* %10
%70 = sub nsw i32 %69, %68
store i32 %70, i32* %10
%71 = load i32, i32* %11
%72 = add nsw i32 %71, 1
store i32 %72, i32* %11
br label %56
73: ; preds = %56
%74 = load i32*, i32** %8
%75 = call i32 @fclose(i32* %74)
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %73, %14
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [35 x i8] c"Utiliza\C3\A7\C3\A3o: ./a.out source dest\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [53 x i8] c"There was an error opening the file %s for reading!\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [53 x i8] c"There was an error opening the file %s for writing!\0A\00"
@SEEK_END = 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 %50
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 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i32, i32* @SEEK_END
%29 = tail call i32 @fseek(i32* %12, i32 0, i32 %28)
%30 = tail call i32 @ftell(i32* %12)
%31 = tail call i32 @rewind(i32* %12)
%32 = icmp sgt i32 %30, 10240
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
%36 = tail call i32 @min(i32 %30, i32 10240)
%37 = call i32 @fread(i8* %9, i32 1, i32 %36, i32* %12)
%38 = icmp eq i32 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %35, %39
%40 = phi i32 [ %45, %39 ], [ %37, %35 ]
%41 = phi i32 [ %43, %39 ], [ %30, %35 ]
%42 = call i32 @fwrite(i8* %9, i32 %40, i32 1, i32* %21)
%43 = sub nsw i32 %41, %40
%44 = tail call i32 @min(i32 %43, i32 10240)
%45 = call i32 @fread(i8* %9, i32 1, i32 %44, i32* %12)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %39
47: ; preds = %39, %35
%48 = tail call i32 @fclose(i32* %21)
%49 = tail call i32 @fclose(i32* %12)
br label %50
50: ; preds = %47, %5
%51 = phi i32 [ 1, %5 ], [ 0, %47 ]
ret i32 %51
}