#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
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[]) {
  printf("El número de argumentos pasados al main es: %d\n", argc);
  int fd;
  char *buffer[512];
  if ((fd = open(argv[1], O_RDWR)) == -1) {
    perror("open");
    exit(-1);
  }
  printf("El descriptor del fichero %s es %d\n", argv[1], fd);
  int readbytes = read(fd, buffer, 512);
  printf("Se han leido %d bytes, en lugar de %d bytes.\n", readbytes, 512);
  char *puntero = "hola\n";
  for (int i = 0; i < 10; i++) {
    write(fd, puntero, 5);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d2 <main+0x62>
lea    0xe6e(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x1024(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x200,%edx
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe63(%rip),%rax
mov    %rax,-0x1030(%rbp)
movl   $0x0,-0x1034(%rbp)
cmpl   $0xa,-0x1034(%rbp)
jge    126b <main+0xfb>
mov    -0x14(%rbp),%edi
mov    -0x1030(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1034(%rbp)
jmp    1236 <main+0xc6>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r14
mov    %edi,%esi
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1293 <main+0x123>
mov    %eax,%ebx
mov    0x8(%r14),%rsi
lea    0xe81(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   1060 <read@plt>
lea    0xe86(%rip),%rdi
mov    %eax,%esi
mov    $0x200,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9f(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd97(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"El n\C3\BAmero de argumentos pasados al main es: %d\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [36 x i8] c"El descriptor del fichero %s es %d\0A\00"
@.str.3 = [46 x i8] c"Se han leido %d bytes, en lugar de %d bytes.\0A\00"
@.str.4 = [6 x i8] c"hola\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [512 x i8*]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %26)
%28 = load i32, i32* %6
%29 = getelementptr inbounds [512 x i8*], [512 x i8*]* %7, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8** %29, i32 512)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 512)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %9
store i32 0, i32* %10
br label %33
33: ; preds = %40, %22
%34 = load i32, i32* %10
%35 = icmp slt i32 %34, 10
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i32, i32* %6
%38 = load i8*, i8** %9
%39 = call i32 @write(i32 %37, i8* %38, i32 5)
br label %40
40: ; preds = %36
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %33
43: ; preds = %33
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [49 x i8] c"El n\C3\BAmero de argumentos pasados al main es: %d\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [36 x i8] c"El descriptor del fichero %s es %d\0A\00"
@.str.3 = [46 x i8] c"Se han leido %d bytes, en lugar de %d bytes.\0A\00"
@.str.4 = [6 x i8] c"hola\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8*]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = bitcast [512 x i8*]* %3 to i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %9)
%17 = getelementptr inbounds [512 x i8*], [512 x i8*]* %3, i64 0, i64 0
%18 = call i32 @read(i32 %9, i8** %17, i32 512)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 512)
%20 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%21 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%22 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%23 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%24 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%25 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%26 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%27 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%28 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%29 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%30 = tail call i32 @close(i32 %9)
ret i32 0
}