#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ strcmp(char *, char *);
char **create_pipe(char **arguments, int *fd) {
  int i;
  char **sink_arguments = NULL;
  for (i = 0; arguments[i] != NULL; i++) {
    if (!strcmp(arguments[i], "|")) {
      arguments[i] = NULL;
      sink_arguments = &arguments[i + 1];
      if (pipe(fd) < 0) {
        perror("Cannot create pipe");
        exit(EXIT_FAILURE);
      }
      break;
    }
  }
  return sink_arguments;
}


x86 assembly (clang, -O0):
<create_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1200 <create_pipe+0xc0>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ed <create_pipe+0xad>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pipe@plt>
cmp    $0x0,%rax
jge    11e8 <create_pipe+0xa8>
lea    0xe2d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1200 <create_pipe+0xc0>
jmp    11f2 <create_pipe+0xb2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115f <create_pipe+0x1f>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_pipe>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
mov    (%rdi),%rdi
test   %rdi,%rdi
je     118c <create_pipe+0x4c>
mov    %rsi,%r14
mov    $0x1,%ebx
lea    0xe9d(%rip),%r12
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1191 <create_pipe+0x51>
mov    0x0(%r13,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1170 <create_pipe+0x30>
jmp    11b7 <create_pipe+0x77>
xor    %r15d,%r15d
jmp    11b7 <create_pipe+0x77>
lea    -0x1(%rbx),%eax
movq   $0x0,0x0(%r13,%rax,8)
mov    %r14,%rdi
call   1030 <pipe@plt>
test   %rax,%rax
js     11c4 <create_pipe+0x84>
mov    %ebx,%eax
lea    0x0(,%rax,8),%r15
add    %r13,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe37(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
@.str.1 = [19 x i8] c"Cannot create pipe\00"
@EXIT_FAILURE = global i32 0
define i8** @create_pipe(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i8** null, i8*** %6
store i32 0, i32* %5
br label %7
7: ; preds = %41, %2
%8 = load i8**, i8*** %3
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %44
14: ; preds = %7
%15 = load i8**, i8*** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %40, label %22
22: ; preds = %14
%23 = load i8**, i8*** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
store i8* null, i8** %26
%27 = load i8**, i8*** %3
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
store i8** %31, i8*** %6
%32 = load i32*, i32** %4
%33 = call i64 @pipe(i32* %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %22
%36 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %22
br label %44
40: ; preds = %14
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %7
44: ; preds = %39, %7
%45 = load i8**, i8*** %6
ret i8** %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
@.str.1 = [19 x i8] c"Cannot create pipe\00"
@EXIT_FAILURE = global i32 0
define i8** @create_pipe(i8** %0, i32* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %27, label %5
5: ; preds = %2, %22
%6 = phi i64 [ %23, %22 ], [ 0, %2 ]
%7 = phi i8* [ %25, %22 ], [ %3, %2 ]
%8 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %5
%11 = and i64 %6, 4294967295
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
store i8* null, i8** %12
%13 = add i64 %6, 1
%14 = and i64 %13, 4294967295
%15 = getelementptr inbounds i8*, i8** %0, i64 %14
%16 = tail call i64 @pipe(i32* %1)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %5
%23 = add nuw i64 %6, 1
%24 = getelementptr inbounds i8*, i8** %0, i64 %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %5
27: ; preds = %22, %2, %10
%28 = phi i8** [ %15, %10 ], [ null, %2 ], [ null, %22 ]
ret i8** %28
}