#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 /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ anetNonBlock(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ anetTcpNoDelay(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ errno;
int socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int anetCreateSocketPair(char *err, int fds[2]) {
  if ((socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) == -1) {
    anetSetError(err, "creating socket: %s", strerror(errno));
    return -1;
  }
  anetNonBlock(NULL, fds[0]);
  anetTcpNoDelay(NULL, fds[0]);
  anetNonBlock(NULL, fds[1]);
  anetTcpNoDelay(NULL, fds[1]);
  return 0;
}


x86 assembly (clang, -O0):
<anetCreateSocketPair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1050 <socketpair@plt>
cmp    $0xffffffff,%eax
jne    11ba <anetCreateSocketPair+0x6a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe57(%rip),%rsi
call   1040 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <anetCreateSocketPair+0xaf>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <anetNonBlock@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <anetTcpNoDelay@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <anetNonBlock@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <anetTcpNoDelay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetCreateSocketPair>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
mov    %rbx,%rcx
call   1050 <socketpair@plt>
cmp    $0xffffffff,%eax
je     11a7 <anetCreateSocketPair+0x57>
mov    (%rbx),%esi
xor    %edi,%edi
call   1030 <anetNonBlock@plt>
mov    (%rbx),%esi
xor    %edi,%edi
call   1060 <anetTcpNoDelay@plt>
mov    0x4(%rbx),%esi
xor    %edi,%edi
call   1030 <anetNonBlock@plt>
mov    0x4(%rbx),%esi
xor    %edi,%edi
call   1060 <anetTcpNoDelay@plt>
jmp    11cc <anetCreateSocketPair+0x7c>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe44(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   1040 <anetSetError@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"creating socket: %s\00"
@errno = global i32 0
define i32 @anetCreateSocketPair(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = load i32*, i32** %5
%9 = call i32 @socketpair(i32 %6, i32 %7, i32 0, i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @anetSetError(i8* %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 -1, i32* %3
br label %33
16: ; preds = %2
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = call i32 @anetNonBlock(i32* null, i32 %19)
%21 = load i32*, i32** %5
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = call i32 @anetTcpNoDelay(i32* null, i32 %23)
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = call i32 @anetNonBlock(i32* null, i32 %27)
%29 = load i32*, i32** %5
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* %30
%32 = call i32 @anetTcpNoDelay(i32* null, i32 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %16, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"creating socket: %s\00"
@errno = global i32 0
define i32 @anetCreateSocketPair(i8* %0, i32* %1) {
%3 = load i32, i32* @AF_UNIX
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socketpair(i32 %3, i32 %4, i32 0, i32* %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @anetSetError(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %21
11: ; preds = %2
%12 = load i32, i32* %1
%13 = tail call i32 @anetNonBlock(i32* null, i32 %12)
%14 = load i32, i32* %1
%15 = tail call i32 @anetTcpNoDelay(i32* null, i32 %14)
%16 = getelementptr inbounds i32, i32* %1, i64 1
%17 = load i32, i32* %16
%18 = tail call i32 @anetNonBlock(i32* null, i32 %17)
%19 = load i32, i32* %16
%20 = tail call i32 @anetTcpNoDelay(i32* null, i32 %19)
br label %21
21: ; preds = %11, %7
%22 = phi i32 [ -1, %7 ], [ 0, %11 ]
ret i32 %22
}