#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 */
typedef int pid_t;

/* Variables and functions */
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ pipe(int *);
int spawn_proc(int, int, char **);
int /*<<< orphan*/ stderr;
int create_process(char ***arg_list, int cmd_count) {
  int command_i;
  pid_t pid;
  int in, out, pipe_fd[2];
  in = STDIN_FILENO;
  for (command_i = 0; command_i < cmd_count; command_i++) {
    pipe(pipe_fd);
    if (command_i == cmd_count - 1)
      out = STDOUT_FILENO;
    else
      out = pipe_fd[1];
    if ((pid = spawn_proc(in, out, arg_list[command_i])) < 0) {
      fprintf(stderr, "Command '%s' not found\n", arg_list[command_i][0]);
      exit(-1);
    }
    close(pipe_fd[1]);
    in = pipe_fd[0];
  }
  return pid;
}


x86 assembly (clang, -O0):
<create_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121c <create_process+0xcc>
lea    -0x24(%rbp),%rdi
call   1040 <pipe@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11a9 <create_process+0x59>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <create_process+0x5f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1060 <spawn_proc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1200 <create_process+0xb0>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%rdx
lea    0xe0f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%edi
call   1030 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <create_process+0x22>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11c5 <create_process+0x75>
mov    %rdi,%r15
mov    0x2e67(%rip),%rax
mov    (%rax),%r13d
lea    -0x1(%rsi),%r12d
mov    %esi,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rsp,%rdi
call   1040 <pipe@plt>
lea    0x4(%rsp),%rax
cmp    %rbp,%r12
jne    1199 <create_process+0x49>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    (%r15,%rbp,8),%rdx
mov    %r13d,%edi
call   1060 <spawn_proc@plt>
test   %eax,%eax
js     11d6 <create_process+0x86>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1030 <close@plt>
mov    (%rsp),%r13d
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1180 <create_process+0x30>
jmp    11c5 <create_process+0x75>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    (%r15,%rbp,8),%rax
mov    (%rax),%rdx
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Command '%s' not found\0A\00"
define i32 @create_process(i8*** %0, i32 %1) {
%3 = alloca i8***
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
store i8*** %0, i8**** %3
store i32 %1, i32* %4
%10 = load i32, i32* @STDIN_FILENO
store i32 %10, i32* %7
store i32 0, i32* %5
br label %11
11: ; preds = %54, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %57
15: ; preds = %11
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = icmp eq i32 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i32, i32* @STDOUT_FILENO
store i32 %23, i32* %8
br label %27
24: ; preds = %15
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%26 = load i32, i32* %25
store i32 %26, i32* %8
br label %27
27: ; preds = %24, %22
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i8***, i8**** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8**, i8*** %30, i64 %32
%34 = load i8**, i8*** %33
%35 = call i32 @spawn_proc(i32 %28, i32 %29, i8** %34)
store i32 %35, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %27
%38 = load i32, i32* @stderr
%39 = load i8***, i8**** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8**, i8*** %39, i64 %41
%43 = load i8**, i8*** %42
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %27
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%53 = load i32, i32* %52
store i32 %53, i32* %7
br label %54
54: ; preds = %48
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %11
57: ; preds = %11
%58 = load i32, i32* %6
ret i32 %58
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Command '%s' not found\0A\00"
define i32 @create_process(i8*** nocapture %0, i32 %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %39
6: ; preds = %2
%7 = load i32, i32* @STDIN_FILENO
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = add nsw i32 %1, -1
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%11 = zext i32 %9 to i64
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %6, %33
%14 = phi i64 [ 0, %6 ], [ %37, %33 ]
%15 = phi i32 [ %7, %6 ], [ %36, %33 ]
%16 = call i32 @pipe(i32* %8)
%17 = icmp eq i64 %14, %11
%18 = load i32, i32* @STDOUT_FILENO
%19 = load i32, i32* %10
%20 = select i1 %17, i32 %18, i32 %19
%21 = getelementptr inbounds i8**, i8*** %0, i64 %14
%22 = load i8**, i8*** %21
%23 = call i32 @spawn_proc(i32 %15, i32 %20, i8** %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %13
%26 = and i64 %14, 4294967295
%27 = getelementptr inbounds i8**, i8*** %0, i64 %26
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %27
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %13
%34 = load i32, i32* %10
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %8
%37 = add nuw nsw i64 %14, 1
%38 = icmp eq i64 %37, %12
br i1 %38, label %39, label %13
39: ; preds = %33, %2
%40 = phi i32 [ undef, %2 ], [ %23, %33 ]
ret i32 %40
}