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

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int f1;
  int f2;
  int n;
  char buffer[512];
  if (argc <= 2) {
    printf("Debe ejecutar %s (archivo_origen) (archivo_destino)\n", argv[0]);
    exit(-1);
  }
  f1 = open(argv[1], O_RDONLY);
  if (f1 < 0) {
    perror("Error abriendo origen");
    exit(-1);
  }
  f2 = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
  while ((n = read(f1, buffer, sizeof(buffer))) > 0) {
    write(f2, buffer, n);
  }
  close(f1);
  close(f2);
  printf("Archivo copiado exitosamente!\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     11b2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ed <main+0x7d>
lea    0xe57(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
mov    0x2df3(%rip),%rax
or     (%rax),%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
mov    0x2dc1(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    125a <main+0xea>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
jmp    1223 <main+0xb3>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jle    1249 <main+0xc9>
mov    0x8(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     1265 <main+0xe5>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
mov    0x2df7(%rip),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df5(%rip),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x200,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1220 <main+0xa0>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     1200 <main+0x80>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xdac(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdc9(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"Debe ejecutar %s (archivo_origen) (archivo_destino)\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Error abriendo origen\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [31 x i8] c"Archivo copiado exitosamente!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %18
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_WRONLY
%34 = load i32, i32* @O_CREAT
%35 = or i32 %33, %34
%36 = load i32, i32* @S_IRUSR
%37 = load i32, i32* @S_IWUSR
%38 = or i32 %36, %37
%39 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %35, i32 %38)
store i32 %39, i32* %7
br label %40
40: ; preds = %45, %29
%41 = load i32, i32* %6
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 512)
store i32 %43, i32* %8
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i32, i32* %7
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* %8
%49 = call i32 @write(i32 %46, i8* %47, i32 %48)
br label %40
50: ; preds = %40
%51 = load i32, i32* %6
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"Debe ejecutar %s (archivo_origen) (archivo_destino)\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Error abriendo origen\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@str = [30 x i8] c"Archivo copiado exitosamente!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_CREAT
%24 = or i32 %23, %22
%25 = load i32, i32* @S_IRUSR
%26 = load i32, i32* @S_IWUSR
%27 = or i32 %26, %25
%28 = tail call i32 (i8*, i32, ...) @open(i8* %21, i32 %24, i32 %27)
%29 = call i32 @read(i32 %14, i8* %4, i32 512)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %19, %31
%32 = phi i32 [ %34, %31 ], [ %29, %19 ]
%33 = call i32 @write(i32 %28, i8* %4, i32 %32)
%34 = call i32 @read(i32 %14, i8* %4, i32 512)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %31, label %36
36: ; preds = %31, %19
%37 = tail call i32 @close(i32 %14)
%38 = tail call i32 @close(i32 %28)
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
ret i32 0
}