#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*/ F_SETFD;
int /*<<< orphan*/ blocking_disable(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int);
int pipe(int *);
int open_pipe(int *fd) {
  int i;
  if (pipe(fd) == -1)
    return -1;
  for (i = 0; i < 2; ++i) {
    fcntl(fd[i], F_SETFD, 1);
    blocking_disable(fd[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<open_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
jne    115a <open_pipe+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <open_pipe+0x7e>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11a7 <open_pipe+0x77>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <fcntl@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <blocking_disable@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <open_pipe+0x31>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_pipe>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
je     117a <open_pipe+0x4a>
mov    (%rbx),%edi
mov    0x2e96(%rip),%r14
mov    (%r14),%esi
mov    $0x1,%edx
call   1030 <fcntl@plt>
mov    (%rbx),%edi
call   1050 <blocking_disable@plt>
mov    0x4(%rbx),%edi
mov    (%r14),%esi
mov    $0x1,%edx
call   1030 <fcntl@plt>
mov    0x4(%rbx),%edi
call   1050 <blocking_disable@plt>
xor    %eax,%eax
jmp    117f <open_pipe+0x4f>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@F_SETFD = global i32 0
define i32 @open_pipe(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)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %31
9: ; preds = %1
store i32 0, i32* %4
br label %10
10: ; preds = %27, %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* @F_SETFD
%20 = call i32 @fcntl(i32 %18, i32 %19, i32 1)
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @blocking_disable(i32 %25)
br label %27
27: ; preds = %13
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %10
30: ; preds = %10
store i32 0, i32* %2
br label %31
31: ; preds = %30, %8
%32 = load i32, i32* %2
ret i32 %32
}

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