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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ strcpy(char *, char const *);
char *strtok(char *, char *);
int /*<<< orphan*/ wait(int *);
int spawn_prog(const char *pr) {
  pid_t cpid;
  char *argv[32], *p, *d;
  char prm[BUFSIZ];
  int i;
  strcpy(prm, pr);
  d = " ,";
  p = strtok(prm, d);
  for (i = 0; i < 31; ++i) {
    if (p == NULL)
      break;
    argv[i] = p;
    p = strtok(NULL, d);
  }
  argv[i] = NULL;
  if ((cpid = fork()) == 0) {
    execvp(argv[0], argv);
    return (-1);
  }
  wait(&i);
  return (i);
}


x86 assembly (clang, -O0):
<spawn_prog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x138(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x150(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x150(%rbp),%rdi
lea    0xe55(%rip),%rax
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x128(%rbp)
movl   $0x0,-0x144(%rbp)
cmpl   $0x1f,-0x144(%rbp)
jge    1230 <spawn_prog+0xe0>
cmpq   $0x0,-0x128(%rbp)
jne    11ef <spawn_prog+0x9f>
jmp    1230 <spawn_prog+0xe0>
mov    -0x128(%rbp),%rcx
movslq -0x144(%rbp),%rax
mov    %rcx,-0x120(%rbp,%rax,8)
ff
mov    -0x130(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    11cf <spawn_prog+0x7f>
movslq -0x144(%rbp),%rax
movq   $0x0,-0x120(%rbp,%rax,8)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    127f <spawn_prog+0x12f>
mov    -0x120(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1050 <execvp@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x148(%rbp)
jmp    129e <spawn_prog+0x14e>
lea    -0x144(%rbp),%rdi
call   1060 <wait@plt>
mov    -0x144(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x148(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn_prog>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rsi
mov    %rsp,%r14
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
movl   $0x0,-0x1c(%rbp)
xor    %ecx,%ecx
test   %rax,%rax
je     11d6 <spawn_prog+0x86>
lea    0xe54(%rip),%r15
nopl   0x0(%rax)
mov    %rcx,%rbx
mov    %rax,-0x120(%rbp,%rcx,8)
ff
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
lea    0x1(%rbx),%rcx
mov    %ecx,-0x1c(%rbp)
cmp    $0x1d,%ebx
ja     11d6 <spawn_prog+0x86>
test   %rax,%rax
jne    11b0 <spawn_prog+0x60>
movq   $0x0,-0x120(%rbp,%rcx,8)
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11fb <spawn_prog+0xab>
lea    -0x1c(%rbp),%rdi
call   1060 <wait@plt>
mov    -0x1c(%rbp),%eax
jmp    1213 <spawn_prog+0xc3>
mov    -0x120(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1050 <execvp@plt>
mov    $0xffffffff,%eax
mov    %r14,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c" ,\00"
define i32 @spawn_prog(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [32 x i8*]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i8* %15, i8* %16)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7
%18 = load i8*, i8** %7
%19 = call i8* @strtok(i8* %15, i8* %18)
store i8* %19, i8** %6
store i32 0, i32* %10
br label %20
20: ; preds = %34, %1
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 31
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %23
br label %37
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [32 x i8*], [32 x i8*]* %5, i64 0, i64 %30
store i8* %28, i8** %31
%32 = load i8*, i8** %7
%33 = call i8* @strtok(i8* null, i8* %32)
store i8* %33, i8** %6
br label %34
34: ; preds = %27
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %20
37: ; preds = %26, %20
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [32 x i8*], [32 x i8*]* %5, i64 0, i64 %39
store i8* null, i8** %40
%41 = call i32 (...) @fork()
store i32 %41, i32* %4
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = getelementptr inbounds [32 x i8*], [32 x i8*]* %5, i64 0, i64 0
%45 = load i8*, i8** %44
%46 = getelementptr inbounds [32 x i8*], [32 x i8*]* %5, i64 0, i64 0
%47 = call i32 @execvp(i8* %45, i8** %46)
store i32 -1, i32* %2
store i32 1, i32* %11
br label %51
48: ; preds = %37
%49 = call i32 @wait(i32* %10)
%50 = load i32, i32* %10
store i32 %50, i32* %2
store i32 1, i32* %11
br label %51
51: ; preds = %48, %43
%52 = load i8*, i8** %8
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c" ,\00"
define i32 @spawn_prog(i8* %0) {
%2 = alloca [32 x i8*]
%3 = alloca i32
%4 = bitcast [32 x i8*]* %2 to i8*
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = bitcast i32* %3 to i8*
%10 = call i32 @strcpy(i8* %8, i8* %0)
%11 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
%12 = icmp eq i8* %11, null
br i1 %12, label %25, label %13
13: ; preds = %1, %13
%14 = phi i8* [ %18, %13 ], [ %11, %1 ]
%15 = phi i32 [ %19, %13 ], [ 0, %1 ]
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 %16
store i8* %14, i8** %17
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = add nuw nsw i32 %15, 1
store i32 %19, i32* %3
%20 = icmp ugt i32 %15, 29
%21 = icmp eq i8* %18, null
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %23, label %13
23: ; preds = %13
%24 = zext i32 %19 to i64
br label %25
25: ; preds = %23, %1
%26 = phi i64 [ 0, %1 ], [ %24, %23 ]
%27 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 %26
store i8* null, i8** %27
%28 = call i32 (...) @fork()
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = getelementptr inbounds [32 x i8*], [32 x i8*]* %2, i64 0, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @execvp(i8* %32, i8** %31)
br label %37
34: ; preds = %25
%35 = call i32 @wait(i32* %3)
%36 = load i32, i32* %3
br label %37
37: ; preds = %34, %30
%38 = phi i32 [ -1, %30 ], [ %36, %34 ]
ret i32 %38
}