#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*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int errno;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int pipe(int *);
int pipe_cloexec(int pipefd[2]) {
  int ret = pipe(pipefd);
  if (ret) {
    ret = -errno;
    return ret;
  }
  fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
  fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
  return 0;
}


x86 assembly (clang, -O0):
<pipe_cloexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115b <pipe_cloexec+0x3b>
xor    %eax,%eax
mov    0x2e85(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <pipe_cloexec+0x7d>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_cloexec>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <pipe@plt>
test   %eax,%eax
je     113e <pipe_cloexec+0x1e>
mov    0x2e98(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1169 <pipe_cloexec+0x49>
mov    (%rbx),%edi
mov    0x2e99(%rip),%r14
mov    (%r14),%esi
mov    0x2e87(%rip),%r15
mov    (%r15),%edx
call   1030 <fcntl@plt>
mov    0x4(%rbx),%edi
mov    (%r14),%esi
mov    (%r15),%edx
call   1030 <fcntl@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
define i32 @pipe_cloexec(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @pipe(i32* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
store i32 %11, i32* %4
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %26
13: ; preds = %1
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = load i32, i32* @F_SETFD
%18 = load i32, i32* @FD_CLOEXEC
%19 = call i32 @fcntl(i32 %16, i32 %17, i32 %18)
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
%23 = load i32, i32* @F_SETFD
%24 = load i32, i32* @FD_CLOEXEC
%25 = call i32 @fcntl(i32 %22, i32 %23, i32 %24)
store i32 0, i32* %2
br label %26
26: ; preds = %13, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@errno = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
define i32 @pipe_cloexec(i32* %0) {
%2 = tail call i32 @pipe(i32* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = sub nsw i32 0, %5
br label %17
7: ; preds = %1
%8 = load i32, i32* %0
%9 = load i32, i32* @F_SETFD
%10 = load i32, i32* @FD_CLOEXEC
%11 = tail call i32 @fcntl(i32 %8, i32 %9, i32 %10)
%12 = getelementptr inbounds i32, i32* %0, i64 1
%13 = load i32, i32* %12
%14 = load i32, i32* @F_SETFD
%15 = load i32, i32* @FD_CLOEXEC
%16 = tail call i32 @fcntl(i32 %13, i32 %14, i32 %15)
br label %17
17: ; preds = %7, %4
%18 = phi i32 [ %6, %4 ], [ 0, %7 ]
ret i32 %18
}