#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*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char **, int);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char *argv[]) {
  char buffer[512];
  int fdi, fdo, readbytes;
  if (argc != 3) {
    printf("Uso del programa %s fichero-in fichero-out\n", argv[0]);
    exit(1);
  }
  fdi = open(argv[1], O_RDONLY);
  fdo = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
  while ((readbytes = read(fdi, &buffer, sizeof(char))) > 0) {
    write(fdo, &buffer, readbytes);
  }
  close(fdi);
  close(fdo);
}


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   $0x3,-0x8(%rbp)
je     11a0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x214(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2e22(%rip),%rax
or     (%rax),%esi
mov    0x2e11(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x218(%rbp)
mov    -0x214(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x21c(%rbp)
cmp    $0x0,%eax
jle    1236 <main+0xd6>
mov    -0x218(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x21c(%rbp),%edx
call   1030 <write@plt>
jmp    11f3 <main+0x93>
mov    -0x214(%rbp),%edi
call   1050 <close@plt>
mov    -0x218(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%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    $0x3,%edi
jne    121d <main+0xbd>
mov    0x8(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x2e2b(%rip),%rax
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbp),%rdi
mov    0x2e45(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1200 <main+0xa0>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11e0 <main+0x80>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Uso del programa %s fichero-in fichero-out\0A\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
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 @printf(i8* getelementptr inbounds ([44 x i8], [44 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* %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = load i32, i32* @O_TRUNC
%31 = or i32 %29, %30
%32 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %31, i32 420)
store i32 %32, i32* %8
br label %33
33: ; preds = %38, %18
%34 = load i32, i32* %7
%35 = bitcast [512 x i8]* %6 to i8**
%36 = call i32 @read(i32 %34, i8** %35, i32 1)
store i32 %36, i32* %9
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* %8
%40 = bitcast [512 x i8]* %6 to i8**
%41 = load i32, i32* %9
%42 = call i32 @write(i32 %39, i8** %40, i32 %41)
br label %33
43: ; preds = %33
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %8
%47 = call i32 @close(i32 %46)
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [44 x i8] c"Uso del programa %s fichero-in fichero-out\0A\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
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 eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 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 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = tail call i32 (i8*, i32, ...) @open(i8* %16, i32 %21, i32 420)
%23 = bitcast [512 x i8]* %3 to i8**
%24 = call i32 @read(i32 %14, i8** %23, i32 1)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %10, %26
%27 = phi i32 [ %29, %26 ], [ %24, %10 ]
%28 = call i32 @write(i32 %22, i8** %23, i32 %27)
%29 = call i32 @read(i32 %14, i8** %23, i32 1)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %26, label %31
31: ; preds = %26, %10
%32 = tail call i32 @close(i32 %14)
%33 = tail call i32 @close(i32 %22)
ret i32 0
}