#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 fd_safer(int);
int pipe(int *);
int pipe_safer(int fd[2]) {
  int fail = pipe(fd);
  if (fail)
    return fail;
  {
    int i;
    for (i = 0; i < 2; i++) {
      int f = fd_safer(fd[i]);
      if (f < 0)
        return -1;
      fd[i] = f;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<pipe_safer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pipe@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     114d <pipe_safer+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <pipe_safer+0x8a>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    11a3 <pipe_safer+0x83>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <fd_safer@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1187 <pipe_safer+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <pipe_safer+0x8a>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <pipe_safer+0x34>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_safer>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <pipe@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1154 <pipe_safer+0x34>
mov    (%rbx),%edi
call   1040 <fd_safer@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     1154 <pipe_safer+0x34>
mov    %eax,(%rbx)
mov    0x4(%rbx),%edi
call   1040 <fd_safer@plt>
test   %eax,%eax
js     1154 <pipe_safer+0x34>
mov    %eax,0x4(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pipe_safer(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @pipe(i32* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %37
13: ; preds = %1
store i32 0, i32* %5
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = load i32*, i32** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = call i32 @fd_safer(i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 -1, i32* %2
br label %37
27: ; preds = %17
%28 = load i32, i32* %6
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
br label %33
33: ; preds = %27
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %14
36: ; preds = %14
store i32 0, i32* %2
br label %37
37: ; preds = %36, %26, %11
%38 = load i32, i32* %2
ret i32 %38
}

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