#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 open(char const *, int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int abrir_pipe(const char *pathname, int flags) {
  int abierto = 0, id_pipe;
  do {
    id_pipe = open(pathname, flags);
    if (id_pipe == -1) {
      perror(pathname);
      printf("Se volvera a intentar despues\n");
      sleep(5);
    } else
      abierto = 1;
  } while (abierto == 0);
  return id_pipe;
}


x86 assembly (clang, -O0):
<abrir_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1193 <abrir_pipe+0x53>
mov    -0x8(%rbp),%rdi
call   1050 <perror@plt>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    119a <abrir_pipe+0x5a>
movl   $0x1,-0x10(%rbp)
jmp    119f <abrir_pipe+0x5f>
cmpl   $0x0,-0x10(%rbp)
je     1156 <abrir_pipe+0x16>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abrir_pipe>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    1183 <abrir_pipe+0x43>
lea    0xea6(%rip),%r14
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     115a <abrir_pipe+0x1a>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Se volvera a intentar despues\0A\00"
define i32 @abrir_pipe(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %20, %2
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = call i32 @perror(i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @sleep(i32 5)
br label %19
18: ; preds = %7
store i32 1, i32* %5
br label %19
19: ; preds = %18, %13
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %7, label %23
23: ; preds = %20
%24 = load i32, i32* %6
ret i32 %24
}

LLVM IR (-O2):
@str = [30 x i8] c"Se volvera a intentar despues\00"
define i32 @abrir_pipe(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @open(i8* %0, i32 %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %2, %5
%6 = tail call i32 @perror(i8* %0)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @sleep(i32 5)
%9 = tail call i32 @open(i8* %0, i32 %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %5, label %11
11: ; preds = %5, %2
%12 = phi i32 [ %3, %2 ], [ %9, %5 ]
ret i32 %12
}