#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 EPROTONOSUPPORT;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ S_IFIFO;
int /*<<< orphan*/ __set_errno(int);
int __socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                 int *);
int errno;
int __pipe(int fds[2]) {
  int save_errno = errno;
  int result;
  result = __socketpair(PF_LOCAL, SOCK_STREAM, S_IFIFO, fds);
  if (result == -1 && errno == EPROTONOSUPPORT) {
    __set_errno(save_errno);
    return __socketpair(PF_LOCAL, SOCK_STREAM, 0, fds);
  }
  return result;
}


x86 assembly (clang, -O0):
<__pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
call   1040 <__socketpair@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11ae <__pipe+0x8e>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%eax
jne    11ae <__pipe+0x8e>
mov    -0x14(%rbp),%edi
call   1030 <__set_errno@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
xor    %edx,%edx
call   1040 <__socketpair@plt>
mov    %eax,-0x4(%rbp)
jmp    11b4 <__pipe+0x94>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__pipe>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    0x2e9e(%rip),%rbp
mov    0x0(%rbp),%r12d
mov    0x2e8b(%rip),%r14
mov    (%r14),%edi
mov    0x2e91(%rip),%r15
mov    (%r15),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rcx
call   1040 <__socketpair@plt>
cmp    $0xffffffff,%eax
jne    1193 <__pipe+0x73>
mov    0x0(%rbp),%ecx
mov    0x2e76(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%ecx
jne    1193 <__pipe+0x73>
mov    %r12d,%edi
call   1030 <__set_errno@plt>
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
mov    %rbx,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <__socketpair@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@S_IFIFO = global i32 0
@EPROTONOSUPPORT = global i32 0
define i32 @__pipe(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32, i32* @errno
store i32 %6, i32* %4
%7 = load i32, i32* @PF_LOCAL
%8 = load i32, i32* @SOCK_STREAM
%9 = load i32, i32* @S_IFIFO
%10 = load i32*, i32** %3
%11 = call i32 @__socketpair(i32 %7, i32 %8, i32 %9, i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %25
14: ; preds = %1
%15 = load i32, i32* @errno
%16 = load i32, i32* @EPROTONOSUPPORT
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %4
%20 = call i32 @__set_errno(i32 %19)
%21 = load i32, i32* @PF_LOCAL
%22 = load i32, i32* @SOCK_STREAM
%23 = load i32*, i32** %3
%24 = call i32 @__socketpair(i32 %21, i32 %22, i32 0, i32* %23)
store i32 %24, i32* %2
br label %27
25: ; preds = %14, %1
%26 = load i32, i32* %5
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %18
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@errno = global i32 0
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@S_IFIFO = global i32 0
@EPROTONOSUPPORT = global i32 0
define i32 @__pipe(i32* %0) {
%2 = load i32, i32* @errno
%3 = load i32, i32* @PF_LOCAL
%4 = load i32, i32* @SOCK_STREAM
%5 = load i32, i32* @S_IFIFO
%6 = tail call i32 @__socketpair(i32 %3, i32 %4, i32 %5, i32* %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = load i32, i32* @EPROTONOSUPPORT
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = tail call i32 @__set_errno(i32 %2)
%14 = load i32, i32* @PF_LOCAL
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @__socketpair(i32 %14, i32 %15, i32 0, i32* %0)
br label %17
17: ; preds = %1, %8, %12
%18 = phi i32 [ %16, %12 ], [ -1, %8 ], [ %6, %1 ]
ret i32 %18
}