#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 __make_fd_async(int);
int /*<<< orphan*/ close(int);
int errno;
int pipe(int *);
int aqpipe(int fd[2]) {
  if ((pipe(fd)) == -1) {
    return -1;
  };
  if ((__make_fd_async(fd[0])) == -1) {
    int tmp_errno = errno;
    do {
      {
        close(fd[0]);
        close(fd[1]);
      }
    } while (0);
    errno = tmp_errno;
    return -1;
  };
  if ((__make_fd_async(fd[1])) == -1) {
    int tmp_errno = errno;
    do {
      {
        close(fd[0]);
        close(fd[1]);
      }
    } while (0);
    errno = tmp_errno;
    return -1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<aqpipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
jne    115a <aqpipe+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <aqpipe+0xd0>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <__make_fd_async@plt>
cmp    $0xffffffff,%eax
jne    11a9 <aqpipe+0x79>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%ecx
mov    0x2e45(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <aqpipe+0xd0>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <__make_fd_async@plt>
cmp    $0xffffffff,%eax
jne    11f9 <aqpipe+0xc9>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%ecx
mov    0x2df5(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <aqpipe+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aqpipe>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <pipe@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ecx
je     11a3 <aqpipe+0x73>
mov    (%rbx),%edi
call   1050 <__make_fd_async@plt>
cmp    $0xffffffff,%eax
je     117a <aqpipe+0x4a>
mov    0x4(%rbx),%edi
call   1050 <__make_fd_async@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11a3 <aqpipe+0x73>
mov    0x2e75(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%edi
add    $0x4,%rbx
call   1030 <close@plt>
jmp    118e <aqpipe+0x5e>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%edi
call   1030 <close@plt>
add    $0x4,%rbx
mov    (%rbx),%edi
call   1030 <close@plt>
mov    0x2e44(%rip),%rax
mov    %ebp,(%rax)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @aqpipe(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @pipe(i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %49
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = call i32 @__make_fd_async(i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %29
16: ; preds = %10
%17 = load i32, i32* @errno
store i32 %17, i32* %4
br label %18
18: ; preds = %16
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %18
%28 = load i32, i32* %4
store i32 %28, i32* @errno
store i32 -1, i32* %2
br label %49
29: ; preds = %10
%30 = load i32*, i32** %3
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = load i32, i32* %31
%33 = call i32 @__make_fd_async(i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %48
35: ; preds = %29
%36 = load i32, i32* @errno
store i32 %36, i32* %5
br label %37
37: ; preds = %35
%38 = load i32*, i32** %3
%39 = getelementptr inbounds i32, i32* %38, i64 0
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = load i32*, i32** %3
%43 = getelementptr inbounds i32, i32* %42, i64 1
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %5
store i32 %47, i32* @errno
store i32 -1, i32* %2
br label %49
48: ; preds = %29
store i32 0, i32* %2
br label %49
49: ; preds = %48, %46, %27, %9
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @aqpipe(i32* %0) {
%2 = tail call i32 @pipe(i32* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %27, label %4
4: ; preds = %1
%5 = load i32, i32* %0
%6 = tail call i32 @__make_fd_async(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* @errno
%10 = load i32, i32* %0
%11 = tail call i32 @close(i32 %10)
%12 = getelementptr inbounds i32, i32* %0, i64 1
br label %22
13: ; preds = %4
%14 = getelementptr inbounds i32, i32* %0, i64 1
%15 = load i32, i32* %14
%16 = tail call i32 @__make_fd_async(i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* @errno
%20 = load i32, i32* %0
%21 = tail call i32 @close(i32 %20)
br label %22
22: ; preds = %8, %18
%23 = phi i32* [ %14, %18 ], [ %12, %8 ]
%24 = phi i32 [ %19, %18 ], [ %9, %8 ]
%25 = load i32, i32* %23
%26 = tail call i32 @close(i32 %25)
store i32 %24, i32* @errno
br label %27
27: ; preds = %22, %13, %1
%28 = phi i32 [ -1, %1 ], [ 0, %13 ], [ -1, %22 ]
ret i32 %28
}