#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EINVAL;
int ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ envia(int, char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int system(char *);
FILE *petic_ropen(int sockCliente, char *path, char *mode,
                  unsigned int numCopia, int *modoAcceso) {
  int error;
  char cadena[300] = "";
  char nombreFich[300] = "";
  struct stat statFich;
  FILE *pFich;
  if ((path == NULL) || (mode == NULL)) {
    error = EINVAL;
    fprintf(stderr, "petic_ropen(): esperaba 2 argumentos: ruta al fichero y "
                    "modo de apertura\n");
    sprintf(cadena, "%d\n", error);
    envia(sockCliente, cadena, strlen(cadena));
    return NULL;
  }
  if (strcmp(mode, "r+") == 0 || mode[0] == 'w')
    *modoAcceso = 1;
  else
    *modoAcceso = 0;
  if (stat(path, &statFich) == -1) {
    if ((errno == ENOENT) && (mode[0] != 'r')) {
      sprintf(nombreFich, "%s.%.3u", path, numCopia);
    } else {
      error = errno;
      perror("petic_ropen(): stat()");
      sprintf(cadena, "%d\n", error);
      envia(sockCliente, cadena, strlen(cadena));
      return NULL;
    }
  } else {
    if (S_ISREG(statFich.st_mode)) {
      fprintf(stderr, "Es un fichero normal: voy a tratarlo\n");
    } else if (S_ISDIR(statFich.st_mode)) {
      error = EINVAL;
      fprintf(stderr,
              "petic_ropen(): no implementada la apertura de directorios\n");
      sprintf(cadena, "%d\n", error);
      envia(sockCliente, cadena, strlen(cadena));
      return NULL;
    } else {
      fprintf(stderr, "No es ni un fichero normal, ni un directorio! Error.\n");
      error = EINVAL;
      fprintf(stderr, "petic_ropen(): la ruta no apunta a un fichero valido\n");
      sprintf(cadena, "%d\n", error);
      envia(sockCliente, cadena, strlen(cadena));
      return NULL;
    }
    sprintf(nombreFich, "%s.%.3u", path, numCopia);
    sprintf(cadena, "cp %s %s\n", path, nombreFich);
    if (system(cadena) == -1) {
      error = errno;
      perror("petic_ropen(): system()");
      sprintf(cadena, "%d\n", error);
      envia(sockCliente, cadena, strlen(cadena));
      return NULL;
    }
  }
  pFich = fopen(nombreFich, mode);
  if (pFich == NULL) {
    error = errno;
    perror("petic_ropen(): fopen()");
    sprintf(cadena, "%d\n", error);
    envia(sockCliente, cadena, strlen(cadena));
    return NULL;
  }
  error = 0;
  sprintf(cadena, "%d\n", error);
  envia(sockCliente, cadena, strlen(cadena));
  return pFich;
}


x86 assembly (clang, -O0):
<petic_ropen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1070 <memset@plt>
lea    -0x290(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     1219 <petic_ropen+0x59>
cmpq   $0x0,-0x20(%rbp)
jne    1296 <petic_ropen+0xd6>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2ac(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x2a8(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2ac(%rbp),%edi
mov    -0x2a8(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    16cb <petic_ropen+0x50b>
mov    -0x20(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12c0 <petic_ropen+0x100>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x77,%eax
jne    12cf <petic_ropen+0x10f>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
jmp    12d9 <petic_ropen+0x119>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x298(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
jne    13b4 <petic_ropen+0x1f4>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
mov    0x2cbe(%rip),%rcx
cmp    (%rcx),%eax
jne    133b <petic_ropen+0x17b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
je     133b <petic_ropen+0x17b>
lea    -0x290(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
jmp    13af <petic_ropen+0x1ef>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
lea    0xd0b(%rip),%rdi
call   10d0 <perror@plt>
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2bc(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x2b8(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2bc(%rbp),%edi
mov    -0x2b8(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    16cb <petic_ropen+0x50b>
jmp    15d1 <petic_ropen+0x411>
mov    -0x298(%rbp),%edi
call   10b0 <S_ISREG@plt>
cmp    $0x0,%rax
je     13e3 <petic_ropen+0x223>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
lea    0xc96(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1507 <petic_ropen+0x347>
mov    -0x298(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1475 <petic_ropen+0x2b5>
mov    0x2bd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xc20(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2cc(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x2c8(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2cc(%rbp),%edi
mov    -0x2c8(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    16cb <petic_ropen+0x50b>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
lea    0xc4b(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2b3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
lea    0xc60(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xb8e(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2dc(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x2d8(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2dc(%rbp),%edi
mov    -0x2d8(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    16cb <petic_ropen+0x50b>
lea    -0x290(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xb35(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
lea    -0x160(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x290(%rbp),%rcx
lea    0xc00(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
lea    -0x160(%rbp),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    15cc <petic_ropen+0x40c>
mov    0x2a79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
lea    0xbdb(%rip),%rdi
call   10d0 <perror@plt>
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xac9(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2ec(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x2e8(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2ec(%rbp),%edi
mov    -0x2e8(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    16cb <petic_ropen+0x50b>
jmp    15d1 <petic_ropen+0x411>
lea    -0x290(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x2a0(%rbp)
cmpq   $0x0,-0x2a0(%rbp)
jne    166a <petic_ropen+0x4aa>
mov    0x29db(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
lea    0xb55(%rip),%rdi
call   10d0 <perror@plt>
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xa2b(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2fc(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x2f8(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2fc(%rbp),%edi
mov    -0x2f8(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    16cb <petic_ropen+0x50b>
movl   $0x0,-0x34(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0x9c8(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30c(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x308(%rbp)
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30c(%rbp),%edi
mov    -0x308(%rbp),%rsi
mov    %eax,%edx
call   1030 <envia@plt>
mov    -0x2a0(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<petic_ropen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x278,%rsp
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0x140(%rsp),%rdi
mov    $0x12c,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x12c,%edx
xor    %esi,%esi
call   1070 <memset@plt>
test   %rbp,%rbp
je     122f <petic_ropen+0x6f>
test   %r12,%r12
je     122f <petic_ropen+0x6f>
lea    0xe38(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1255 <petic_ropen+0x95>
xor    %eax,%eax
cmpb   $0x77,(%r12)
sete   %al
jmp    125a <petic_ropen+0x9a>
mov    0x2d9a(%rip),%rax
mov    (%rax),%r13d
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1090 <fprintf@plt>
xor    %ebp,%ebp
jmp    1353 <petic_ropen+0x193>
mov    $0x1,%eax
mov    %eax,(%rbx)
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
je     12f9 <petic_ropen+0x139>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   10b0 <S_ISREG@plt>
test   %rax,%rax
je     1399 <petic_ropen+0x1d9>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
call   1090 <fprintf@plt>
lea    0xdaf(%rip),%rsi
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    %rbp,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   10e0 <sprintf@plt>
lea    0xe7e(%rip),%rsi
lea    0x140(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    1337 <petic_ropen+0x177>
mov    0x2cee(%rip),%rax
mov    (%rax),%r13d
lea    0xe52(%rip),%rdi
jmp    140b <petic_ropen+0x24b>
mov    0x2cd8(%rip),%rax
mov    (%rax),%r13d
mov    0x2cb6(%rip),%rax
cmp    (%rax),%r13d
jne    13f1 <petic_ropen+0x231>
cmpb   $0x72,(%r12)
je     13f1 <petic_ropen+0x231>
lea    0xd2c(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbp,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   10e0 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    %r12,%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     13fa <petic_ropen+0x23a>
mov    %rax,%rbp
xor    %r13d,%r13d
lea    0xcf0(%rip),%rsi
lea    0x140(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <envia@plt>
mov    %rbp,%rax
add    $0x278,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     13c4 <petic_ropen+0x204>
mov    0x2c24(%rip),%rax
mov    (%rax),%r13d
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
lea    0xcd6(%rip),%rsi
jmp    1249 <petic_ropen+0x89>
mov    0x2c15(%rip),%rbx
mov    (%rbx),%edi
lea    0xcfc(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2bf0(%rip),%rax
mov    (%rax),%r13d
mov    (%rbx),%edi
lea    0xd1a(%rip),%rsi
jmp    1249 <petic_ropen+0x89>
lea    0xc61(%rip),%rdi
jmp    140b <petic_ropen+0x24b>
mov    0x2bd7(%rip),%rax
mov    (%rax),%r13d
lea    0xd53(%rip),%rdi
call   10d0 <perror@plt>
jmp    124e <petic_ropen+0x8e>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EINVAL = global i32 0
@stderr = global i32 0
@.str = [74 x i8] c"petic_ropen(): esperaba 2 argumentos: ruta al fichero y modo de apertura\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"r+\00"
@errno = global i32 0
@ENOENT = global i32 0
@.str.3 = [8 x i8] c"%s.%.3u\00"
@.str.4 = [22 x i8] c"petic_ropen(): stat()\00"
@.str.5 = [38 x i8] c"Es un fichero normal: voy a tratarlo\0A\00"
@.str.6 = [59 x i8] c"petic_ropen(): no implementada la apertura de directorios\0A\00"
@.str.7 = [54 x i8] c"No es ni un fichero normal, ni un directorio! Error.\0A\00"
@.str.8 = [54 x i8] c"petic_ropen(): la ruta no apunta a un fichero valido\0A\00"
@.str.9 = [10 x i8] c"cp %s %s\0A\00"
@.str.10 = [24 x i8] c"petic_ropen(): system()\00"
@.str.11 = [23 x i8] c"petic_ropen(): fopen()\00"
define i32* @petic_ropen(i32 %0, i8* %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca [300 x i8]
%14 = alloca [300 x i8]
%15 = alloca %struct.stat
%16 = alloca i32*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%17 = bitcast [300 x i8]* %13 to i8*
%18 = bitcast [300 x i8]* %14 to i8*
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %5
%22 = load i8*, i8** %9
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %36
24: ; preds = %21, %5
%25 = load i32, i32* @EINVAL
store i32 %25, i32* %12
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
%28 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%29 = load i32, i32* %12
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%33 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @envia(i32 %31, i8* %32, i32 %34)
store i32* null, i32** %6
br label %171
36: ; preds = %21
%37 = load i8*, i8** %9
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 119
br i1 %45, label %46, label %48
46: ; preds = %40, %36
%47 = load i32*, i32** %11
store i32 1, i32* %47
br label %50
48: ; preds = %40
%49 = load i32*, i32** %11
store i32 0, i32* %49
br label %50
50: ; preds = %48, %46
%51 = load i8*, i8** %8
%52 = call i32 @stat(i8* %51, %struct.stat* %15)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %81
54: ; preds = %50
%55 = load i32, i32* @errno
%56 = load i32, i32* @ENOENT
%57 = icmp eq i32 %55, %56
br i1 %57, label %58, label %69
58: ; preds = %54
%59 = load i8*, i8** %9
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 114
br i1 %63, label %64, label %69
64: ; preds = %58
%65 = getelementptr inbounds [300 x i8], [300 x i8]* %14, i64 0, i64 0
%66 = load i8*, i8** %8
%67 = load i32, i32* %10
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %66, i32 %67)
br label %80
69: ; preds = %58, %54
%70 = load i32, i32* @errno
store i32 %70, i32* %12
%71 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%72 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%73 = load i32, i32* %12
%74 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %7
%76 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%77 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%78 = call i32 @strlen(i8* %77)
%79 = call i32 @envia(i32 %75, i8* %76, i32 %78)
store i32* null, i32** %6
br label %171
80: ; preds = %64
br label %144
81: ; preds = %50
%82 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%83 = load i32, i32* %82
%84 = call i64 @S_ISREG(i32 %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %81
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
br label %120
89: ; preds = %81
%90 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%91 = load i32, i32* %90
%92 = call i64 @S_ISDIR(i32 %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %106
94: ; preds = %89
%95 = load i32, i32* @EINVAL
store i32 %95, i32* %12
%96 = load i32, i32* @stderr
%97 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%98 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%99 = load i32, i32* %12
%100 = call i32 (i8*, i8*, ...) @sprintf(i8* %98, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %99)
%101 = load i32, i32* %7
%102 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%103 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%104 = call i32 @strlen(i8* %103)
%105 = call i32 @envia(i32 %101, i8* %102, i32 %104)
store i32* null, i32** %6
br label %171
106: ; preds = %89
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
%109 = load i32, i32* @EINVAL
store i32 %109, i32* %12
%110 = load i32, i32* @stderr
%111 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
%112 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%113 = load i32, i32* %12
%114 = call i32 (i8*, i8*, ...) @sprintf(i8* %112, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %113)
%115 = load i32, i32* %7
%116 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%117 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%118 = call i32 @strlen(i8* %117)
%119 = call i32 @envia(i32 %115, i8* %116, i32 %118)
store i32* null, i32** %6
br label %171
120: ; preds = %86
%121 = getelementptr inbounds [300 x i8], [300 x i8]* %14, i64 0, i64 0
%122 = load i8*, i8** %8
%123 = load i32, i32* %10
%124 = call i32 (i8*, i8*, ...) @sprintf(i8* %121, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %122, i32 %123)
%125 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%126 = load i8*, i8** %8
%127 = getelementptr inbounds [300 x i8], [300 x i8]* %14, i64 0, i64 0
%128 = call i32 (i8*, i8*, ...) @sprintf(i8* %125, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %126, i8* %127)
%129 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%130 = call i32 @system(i8* %129)
%131 = icmp eq i32 %130, -1
br i1 %131, label %132, label %143
132: ; preds = %120
%133 = load i32, i32* @errno
store i32 %133, i32* %12
%134 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%135 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%136 = load i32, i32* %12
%137 = call i32 (i8*, i8*, ...) @sprintf(i8* %135, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %136)
%138 = load i32, i32* %7
%139 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%140 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%141 = call i32 @strlen(i8* %140)
%142 = call i32 @envia(i32 %138, i8* %139, i32 %141)
store i32* null, i32** %6
br label %171
143: ; preds = %120
br label %144
144: ; preds = %143, %80
%145 = getelementptr inbounds [300 x i8], [300 x i8]* %14, i64 0, i64 0
%146 = load i8*, i8** %9
%147 = call i32* @fopen(i8* %145, i8* %146)
store i32* %147, i32** %16
%148 = load i32*, i32** %16
%149 = icmp eq i32* %148, null
br i1 %149, label %150, label %161
150: ; preds = %144
%151 = load i32, i32* @errno
store i32 %151, i32* %12
%152 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%153 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%154 = load i32, i32* %12
%155 = call i32 (i8*, i8*, ...) @sprintf(i8* %153, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %154)
%156 = load i32, i32* %7
%157 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%158 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%159 = call i32 @strlen(i8* %158)
%160 = call i32 @envia(i32 %156, i8* %157, i32 %159)
store i32* null, i32** %6
br label %171
161: ; preds = %144
store i32 0, i32* %12
%162 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%163 = load i32, i32* %12
%164 = call i32 (i8*, i8*, ...) @sprintf(i8* %162, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %163)
%165 = load i32, i32* %7
%166 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%167 = getelementptr inbounds [300 x i8], [300 x i8]* %13, i64 0, i64 0
%168 = call i32 @strlen(i8* %167)
%169 = call i32 @envia(i32 %165, i8* %166, i32 %168)
%170 = load i32*, i32** %16
store i32* %170, i32** %6
br label %171
171: ; preds = %161, %150, %132, %106, %94, %69, %24
%172 = load i32*, i32** %6
ret i32* %172
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EINVAL = global i32 0
@stderr = global i32 0
@.str = [74 x i8] c"petic_ropen(): esperaba 2 argumentos: ruta al fichero y modo de apertura\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"r+\00"
@errno = global i32 0
@ENOENT = global i32 0
@.str.3 = [8 x i8] c"%s.%.3u\00"
@.str.4 = [22 x i8] c"petic_ropen(): stat()\00"
@.str.5 = [38 x i8] c"Es un fichero normal: voy a tratarlo\0A\00"
@.str.6 = [59 x i8] c"petic_ropen(): no implementada la apertura de directorios\0A\00"
@.str.7 = [54 x i8] c"No es ni un fichero normal, ni un directorio! Error.\0A\00"
@.str.8 = [54 x i8] c"petic_ropen(): la ruta no apunta a un fichero valido\0A\00"
@.str.9 = [10 x i8] c"cp %s %s\0A\00"
@.str.10 = [24 x i8] c"petic_ropen(): system()\00"
@.str.11 = [23 x i8] c"petic_ropen(): fopen()\00"
define noalias i32* @petic_ropen(i32 %0, i8* %1, i8* %2, i32 %3, i32* nocapture writeonly %4) {
%6 = alloca [300 x i8]
%7 = alloca [300 x i8]
%8 = alloca %struct.stat
%9 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [300 x i8], [300 x i8]* %7, i64 0, i64 0
%11 = bitcast %struct.stat* %8 to i8*
%12 = icmp eq i8* %1, null
%13 = icmp eq i8* %2, null
%14 = or i1 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %5
%16 = load i32, i32* @EINVAL
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
br label %75
19: ; preds = %5
%20 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i8, i8* %2
%24 = icmp eq i8 %23, 119
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %22, %19
%27 = phi i32 [ 1, %19 ], [ %25, %22 ]
store i32 %27, i32* %4
%28 = call i32 @stat(i8* %1, %struct.stat* %8)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i32, i32* @errno
%32 = load i32, i32* @ENOENT
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i8, i8* %2
%36 = icmp eq i8 %35, 114
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %3)
br label %69
39: ; preds = %34, %30
%40 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %75
41: ; preds = %26
%42 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%43 = load i32, i32* %42
%44 = tail call i64 @S_ISREG(i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %53, label %46
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %3)
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %1, i8* %10)
%51 = call i32 @system(i8* %9)
%52 = icmp eq i32 %51, -1
br i1 %52, label %66, label %69
53: ; preds = %41
%54 = tail call i64 @S_ISDIR(i32 %43)
%55 = icmp eq i64 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %53
%57 = load i32, i32* @EINVAL
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
br label %75
60: ; preds = %53
%61 = load i32, i32* @stderr
%62 = tail call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
%63 = load i32, i32* @EINVAL
%64 = load i32, i32* @stderr
%65 = tail call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
br label %75
66: ; preds = %46
%67 = load i32, i32* @errno
%68 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %75
69: ; preds = %46, %37
%70 = call i32* @fopen(i8* %10, i8* %2)
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load i32, i32* @errno
%74 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
br label %75
75: ; preds = %69, %72, %66, %60, %56, %39, %15
%76 = phi i32 [ %73, %72 ], [ %67, %66 ], [ %63, %60 ], [ %57, %56 ], [ %31, %39 ], [ %16, %15 ], [ 0, %69 ]
%77 = phi i32* [ null, %72 ], [ null, %66 ], [ null, %60 ], [ null, %56 ], [ null, %39 ], [ null, %15 ], [ %70, %69 ]
%78 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %76)
%79 = call i32 @strlen(i8* %9)
%80 = call i32 @envia(i32 %0, i8* %9, i32 %79)
ret i32* %77
}