#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*/ close(int);
int /*<<< orphan*/ ioerror(char *);
int pipe(int *);
scalar_t__ setup_fd(int, int, char *);
int s_pipe(int pipefd[2], int nonblock, char *msg) {
  int retval;
  retval = pipe(pipefd);
  if (retval < 0) {
    ioerror(msg);
    return -1;
  }
  if (setup_fd(pipefd[0], nonblock, msg) < 0) {
    close(pipefd[1]);
    return -1;
  }
  if (setup_fd(pipefd[1], nonblock, msg) < 0) {
    close(pipefd[0]);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<s_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    117e <s_pipe+0x3e>
mov    -0x20(%rbp),%rdi
call   1050 <ioerror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <s_pipe+0xad>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <setup_fd@plt>
cmp    $0x0,%rax
jge    11b2 <s_pipe+0x72>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <s_pipe+0xad>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <setup_fd@plt>
cmp    $0x0,%rax
jge    11e6 <s_pipe+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <s_pipe+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_pipe>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <pipe@plt>
test   %eax,%eax
js     1186 <s_pipe+0x46>
mov    (%rbx),%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1060 <setup_fd@plt>
mov    0x4(%rbx),%edi
test   %rax,%rax
js     117f <s_pipe+0x3f>
mov    %ebp,%esi
mov    %r14,%rdx
call   1060 <setup_fd@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    1193 <s_pipe+0x53>
mov    (%rbx),%edi
call   1030 <close@plt>
jmp    118e <s_pipe+0x4e>
mov    %r14,%rdi
call   1050 <ioerror@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @s_pipe(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i32*, i32** %5
%10 = call i32 @pipe(i32* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i32 @ioerror(i8* %14)
store i32 -1, i32* %4
br label %43
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = call i64 @setup_fd(i32 %19, i32 %20, i8* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %4
br label %43
29: ; preds = %16
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = load i32, i32* %31
%33 = load i32, i32* %6
%34 = load i8*, i8** %7
%35 = call i64 @setup_fd(i32 %32, i32 %33, i8* %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i32*, i32** %5
%39 = getelementptr inbounds i32, i32* %38, i64 0
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
store i32 -1, i32* %4
br label %43
42: ; preds = %29
store i32 0, i32* %4
br label %43
43: ; preds = %42, %37, %24, %13
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
define i32 @s_pipe(i32* %0, i32 %1, i8* %2) {
%4 = tail call i32 @pipe(i32* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @ioerror(i8* %2)
br label %22
8: ; preds = %3
%9 = load i32, i32* %0
%10 = tail call i64 @setup_fd(i32 %9, i32 %1, i8* %2)
%11 = icmp slt i64 %10, 0
%12 = getelementptr inbounds i32, i32* %0, i64 1
%13 = load i32, i32* %12
br i1 %11, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @close(i32 %13)
br label %22
16: ; preds = %8
%17 = tail call i64 @setup_fd(i32 %13, i32 %1, i8* %2)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %0
%21 = tail call i32 @close(i32 %20)
br label %22
22: ; preds = %16, %19, %14, %6
%23 = phi i32 [ -1, %6 ], [ -1, %14 ], [ -1, %19 ], [ 0, %16 ]
ret i32 %23
}