#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*/ dup(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ pipe(int *);
scalar_t__ strcmp(char *, char *);
void execute(char *args[]) {
  int fd[2], i, f;
  for (i = 0; args[i]; i++) {
    if (strcmp(args[i], "|") == 0) {
      args[i] = ((char *)0);
      if (pipe(fd) || (f = fork()) < 0)
        exit(errno);
      if (f) {
        (void)close(0);
        (void)dup(fd[0]);
        (void)close(fd[0]);
        (void)close(fd[1]);
        (void)execute(&args[i + 1]);
      }
      (void)close(1);
      (void)dup(fd[1]);
      (void)close(fd[0]);
      (void)close(fd[1]);
      break;
    }
  }
  (void)execvp(args[0], args);
  exit(errno);
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1287 <execute+0x107>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe47(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1274 <execute+0xf4>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
lea    -0x10(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jne    11fe <execute+0x7e>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    120c <execute+0x8c>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
je     124d <execute+0xcd>
xor    %edi,%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%edi
call   1030 <dup@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
call   1040 <execute@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1030 <dup@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
jmp    1287 <execute+0x107>
jmp    1279 <execute+0xf9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <execute+0x13>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <execvp@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<execute>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
je     11ba <execute+0x3a>
mov    $0x1,%ebx
lea    0xe60(%rip),%r15
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d3 <execute+0x53>
mov    (%r14,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    11a0 <execute+0x20>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1080 <execvp@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x1(%rbx),%eax
movq   $0x0,(%r14,%rax,8)
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jne    11c5 <execute+0x45>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     11c5 <execute+0x45>
jne    1221 <execute+0xa1>
mov    $0x1,%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1030 <dup@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
jmp    11ba <execute+0x3a>
xor    %edi,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   1030 <dup@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    %ebx,%eax
lea    (%r14,%rax,8),%rdi
call   1040 <execute@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
@errno = global i32 0
define void @execute(i8** %0) {
%2 = alloca i8**
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %4
br label %6
6: ; preds = %66, %1
%7 = load i8**, i8*** %2
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %7, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %69
13: ; preds = %6
%14 = load i8**, i8*** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %65
21: ; preds = %13
%22 = load i8**, i8*** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
store i8* null, i8** %25
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%27 = call i64 @pipe(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %21
%30 = call i32 (...) @fork()
store i32 %30, i32* %5
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29, %21
%33 = load i32, i32* @errno
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %29
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %54
38: ; preds = %35
%39 = call i32 @close(i32 0)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @dup(i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
%49 = load i8**, i8*** %2
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
br label %54
54: ; preds = %38, %35
%55 = call i32 @close(i32 1)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%57 = load i32, i32* %56
%58 = call i32 @dup(i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
br label %69
65: ; preds = %13
br label %66
66: ; preds = %65
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %6
69: ; preds = %54, %6
%70 = load i8**, i8*** %2
%71 = getelementptr inbounds i8*, i8** %70, i64 0
%72 = load i8*, i8** %71
%73 = load i8**, i8*** %2
%74 = call i32 @execvp(i8* %72, i8** %73)
%75 = load i32, i32* @errno
%76 = call i32 @exit(i32 %75)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
@errno = global i32 0
define void @execute(i8** %0) {
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %2 to i8*
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %51, label %6
6: ; preds = %1, %46
%7 = phi i64 [ %47, %46 ], [ 0, %1 ]
%8 = phi i8* [ %49, %46 ], [ %4, %1 ]
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %46
11: ; preds = %6
%12 = and i64 %7, 4294967295
%13 = getelementptr inbounds i8*, i8** %0, i64 %12
store i8* null, i8** %13
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 (...) @fork()
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17, %11
%21 = load i32, i32* @errno
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %17
%24 = icmp eq i32 %18, 0
br i1 %24, label %37, label %25
25: ; preds = %23
%26 = call i32 @close(i32 0)
%27 = load i32, i32* %14
%28 = call i32 @dup(i32 %27)
%29 = load i32, i32* %14
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = add i64 %7, 1
%35 = and i64 %34, 4294967295
%36 = getelementptr inbounds i8*, i8** %0, i64 %35
unreachable
37: ; preds = %23
%38 = call i32 @close(i32 1)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @dup(i32 %40)
%42 = load i32, i32* %14
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %39
%45 = call i32 @close(i32 %44)
br label %51
46: ; preds = %6
%47 = add nuw i64 %7, 1
%48 = getelementptr inbounds i8*, i8** %0, i64 %47
%49 = load i8*, i8** %48
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %6
51: ; preds = %46, %1, %37
%52 = load i8*, i8** %0
%53 = call i32 @execvp(i8* %52, i8** %0)
%54 = load i32, i32* @errno
%55 = call i32 @exit(i32 %54)
unreachable
}