#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argn, char *argv[]) {
  int fd;
  int readbytes;
  char buffer[512];
  if (argn < 2) {
    printf("Error, se há de introducir un ficher para su apertura\n");
    return -1;
  }
  printf("El número de argumentos es %d, y el primer argumento %s y el segundo "
         "es %s\n",
         argn, argv[0], argv[1]);
  if ((fd = open(argv[1], O_RDWR)) == -1) {
    printf("Error al abrir el archivo.\n");
    return -1;
  }
  while ((readbytes = read(fd, buffer, 512)) != 0) {
    write(1, buffer, readbytes);
  }
  close(fd);
  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)
jge    118d <main+0x3d>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <main+0xe6>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11e9 <main+0x99>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <main+0xe6>
jmp    11ee <main+0x9e>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1227 <main+0xd7>
lea    -0x220(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11ee <main+0x9e>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
cmp    $0x1,%edi
jg     1177 <main+0x17>
lea    0xef3(%rip),%rdi
jmp    11f4 <main+0x94>
mov    %rsi,%rbx
mov    %edi,%esi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11ed <main+0x8d>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x200,%edx
call   1070 <read@plt>
test   %eax,%eax
je     11e2 <main+0x82>
mov    %rsp,%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
test   %eax,%eax
jne    11c0 <main+0x60>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    11fe <main+0x9e>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Error, se h\C3\A1 de introducir un ficher para su apertura\0A\00"
@.str.1 = [77 x i8] c"El n\C3\BAmero de argumentos es %d, y el primer argumento %s y el segundo es %s\0A\00"
@O_RDWR = global i32 0
@.str.2 = [28 x i8] c"Error al abrir el archivo.\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 [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %17, i8* %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %13
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
30: ; preds = %13
br label %31
31: ; preds = %36, %30
%32 = load i32, i32* %6
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 512)
store i32 %34, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @write(i32 1, i8* %37, i32 %38)
br label %31
40: ; preds = %31
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %28, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [77 x i8] c"El n\C3\BAmero de argumentos es %d, y el primer argumento %s y el segundo es %s\0A\00"
@O_RDWR = global i32 0
@str = [27 x i8] c"Error al abrir el archivo.\00"
@str.3 = [55 x i8] c"Error, se h\C3\A1 de introducir un ficher para su apertura\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, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.3, i64 0, i64 0))
br label %29
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %9, i8* %11)
%13 = load i8*, i8** %10
%14 = load i32, i32* @O_RDWR
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %8
%18 = call i32 @read(i32 %15, i8* %4, i32 512)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %22
20: ; preds = %8
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %29
22: ; preds = %17, %22
%23 = phi i32 [ %25, %22 ], [ %18, %17 ]
%24 = call i32 @write(i32 1, i8* %4, i32 %23)
%25 = call i32 @read(i32 %15, i8* %4, i32 512)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %22
27: ; preds = %22, %17
%28 = tail call i32 @close(i32 %15)
br label %29
29: ; preds = %27, %20, %6
%30 = phi i32 [ -1, %6 ], [ -1, %20 ], [ 0, %27 ]
ret i32 %30
}