#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
FILE *abrirArchivo(int n, char **cad, bool *bFILE, char *nFileO) {
  FILE *f;
  if (n >= 2) {
    if (!(f = fopen(cad[1], "r"))) {
      printf("%s \n", strerror(errno));
      perror("No se pudo abrir correctamente el fichero");
      exit(EXIT_FAILURE);
    }
    if (n >= 4)
      if (!strcmp(cad[2], "-f")) {
        strcpy(nFileO, cad[3]);
        *bFILE = true;
      } else
        *bFILE = false;
  } else {
    printf("Inserte el nombre del fichero: ");
    char nombreF[256];
    scanf("%s", nombreF);
    if (!(f = fopen(nombreF, "r"))) {
      printf("%s \n", strerror(errno));
      perror("No se pudo abrir correctamente el fichero");
      exit(EXIT_FAILURE);
    }
  }
  return f;
}


x86 assembly (clang, -O0):
<abrirArchivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x2,-0x4(%rbp)
jl     125a <abrirArchivo+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ff <abrirArchivo+0x7f>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x4,-0x4(%rbp)
jl     1255 <abrirArchivo+0xd5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe19(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1246 <abrirArchivo+0xc6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1250 <abrirArchivo+0xd0>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    1255 <abrirArchivo+0xd5>
jmp    12da <abrirArchivo+0x15a>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12d5 <abrirArchivo+0x155>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd45(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12da <abrirArchivo+0x15a>
mov    -0x28(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abrirArchivo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jl     11de <abrirArchivo+0x5e>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe56(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123e <abrirArchivo+0xbe>
mov    %rax,%rbx
cmp    $0x4,%ebp
jb     1215 <abrirArchivo+0x95>
mov    0x10(%r12),%rdi
lea    0xe65(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1228 <abrirArchivo+0xa8>
movl   $0x0,(%r14)
jmp    1215 <abrirArchivo+0x95>
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xdfb(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     123e <abrirArchivo+0xbe>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%r12),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
movl   $0x1,(%r14)
jmp    1215 <abrirArchivo+0x95>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdaf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xda3(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%s \0A\00"
@errno = global i32 0
@.str.2 = [42 x i8] c"No se pudo abrir correctamente el fichero\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"-f\00"
@.str.4 = [32 x i8] c"Inserte el nombre del fichero: \00"
@.str.5 = [3 x i8] c"%s\00"
define i32* @abrirArchivo(i32 %0, i8** %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca [256 x i8]
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %46
13: ; preds = %4
%14 = load i8**, i8*** %6
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %9
%18 = icmp ne i32* %17, null
br i1 %18, label %26, label %19
19: ; preds = %13
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %13
%27 = load i32, i32* %5
%28 = icmp sge i32 %27, 4
br i1 %28, label %29, label %45
29: ; preds = %26
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %29
%36 = load i8*, i8** %8
%37 = load i8**, i8*** %6
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @strcpy(i8* %36, i8* %39)
%41 = load i32*, i32** %7
store i32 1, i32* %41
br label %44
42: ; preds = %29
%43 = load i32*, i32** %7
store i32 0, i32* %43
br label %44
44: ; preds = %42, %35
br label %45
45: ; preds = %44, %26
br label %61
46: ; preds = %4
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%49 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %51, i32** %9
%52 = icmp ne i32* %51, null
br i1 %52, label %60, label %53
53: ; preds = %46
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %46
br label %61
61: ; preds = %60, %45
%62 = load i32*, i32** %9
ret i32* %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%s \0A\00"
@errno = global i32 0
@.str.2 = [42 x i8] c"No se pudo abrir correctamente el fichero\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"-f\00"
@.str.4 = [32 x i8] c"Inserte el nombre del fichero: \00"
@.str.5 = [3 x i8] c"%s\00"
define noalias i32* @abrirArchivo(i32 %0, i8** nocapture %1, i32* nocapture writeonly %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %31
7: ; preds = %4
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %7
%20 = icmp ugt i32 %0, 3
br i1 %20, label %21, label %45
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %23, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = tail call i32 @strcpy(i8* %3, i8* %28)
store i32 1, i32* %2
br label %45
30: ; preds = %21
store i32 0, i32* %2
br label %45
31: ; preds = %4
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %31
br label %45
45: ; preds = %19, %30, %26, %44
%46 = phi i32* [ %10, %30 ], [ %10, %26 ], [ %10, %19 ], [ %35, %44 ]
ret i32* %46
}