#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_INET;
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int *);
int main(void) {
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  int sockfds[2];
  socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds);
  if (sockfds[0] > 0)
    close(sockfds[0]);
  if (sockfds[1] > 0)
    close(sockfds[1]);
  if (sockfd > 0)
    close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rcx
xor    %edx,%edx
call   1040 <socketpair@plt>
cmpl   $0x0,-0x10(%rbp)
jle    118a <main+0x5a>
mov    -0x10(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0xc(%rbp)
jle    119c <main+0x6c>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11ae <main+0x7e>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    0x2e8c(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,%ebx
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
mov    %rsp,%rcx
xor    %edx,%edx
call   1040 <socketpair@plt>
mov    (%rsp),%edi
test   %edi,%edi
jle    1172 <main+0x42>
call   1030 <close@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    117f <main+0x4f>
call   1030 <close@plt>
test   %ebx,%ebx
jle    118a <main+0x5a>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_UNIX = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
store i32 0, i32* %1
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @socketpair(i32 %7, i32 %8, i32 0, i32* %9)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
br label %18
18: ; preds = %14, %0
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %22, %18
%27 = load i32, i32* %2
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %2
%31 = call i32 @close(i32 %30)
br label %32
32: ; preds = %29, %26
ret i32 0
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_UNIX = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = bitcast [2 x i32]* %1 to i8*
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i32 @socketpair(i32 %6, i32 %7, i32 0, i32* %8)
%10 = load i32, i32* %8
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @close(i32 %10)
br label %14
14: ; preds = %12, %0
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @close(i32 %16)
br label %20
20: ; preds = %18, %14
%21 = icmp sgt i32 %4, 0
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = call i32 @close(i32 %4)
br label %24
24: ; preds = %22, %20
ret i32 0
}