#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 */
scalar_t__ socketpair(int, int, int, int *);
int util_safeio_get_fd(int);
int util_safeio_socketpair(int domain, int type, int protocol, int sv[2]) {
  if (socketpair(domain, type, protocol, sv) < 0)
    return -1;
  sv[0] = util_safeio_get_fd(sv[0]);
  sv[1] = util_safeio_get_fd(sv[1]);
  return 0;
}


x86 assembly (clang, -O0):
<util_safeio_socketpair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <socketpair@plt>
cmp    $0x0,%rax
jge    115d <util_safeio_socketpair+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <util_safeio_socketpair+0x6c>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <util_safeio_get_fd@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <util_safeio_get_fd@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_safeio_socketpair>:
push   %rbx
mov    %rcx,%rbx
call   1030 <socketpair@plt>
test   %rax,%rax
js     1146 <util_safeio_socketpair+0x26>
mov    (%rbx),%edi
call   1040 <util_safeio_get_fd@plt>
mov    %eax,(%rbx)
mov    0x4(%rbx),%edi
call   1040 <util_safeio_get_fd@plt>
mov    %eax,0x4(%rbx)
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @util_safeio_socketpair(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = tail call i64 @socketpair(i32 %0, i32 %1, i32 %2, i32* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = load i32, i32* %3
%9 = tail call i32 @util_safeio_get_fd(i32 %8)
store i32 %9, i32* %3
%10 = getelementptr inbounds i32, i32* %3, i64 1
%11 = load i32, i32* %10
%12 = tail call i32 @util_safeio_get_fd(i32 %11)
store i32 %12, i32* %10
br label %13
13: ; preds = %4, %7
%14 = phi i32 [ 0, %7 ], [ -1, %4 ]
ret i32 %14
}