#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 /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strtok(char *, char *);
pid_t MwSpawn(const char *command) {
  char *argv[20], *p, cmd[1024];
  int argc = 0;
  pid_t pid;
  strncpy(cmd, command, sizeof cmd);
  for (p = strtok(cmd, " \t\r\n"); p && argc < 20;
       p = strtok(NULL, " \t\r\n")) {
    argv[argc++] = p;
  }
  argv[argc] = NULL;
  pid = fork();
  if (!pid) {
    execvp(argv[0], argv);
    exit(0);
  }
  return pid;
}


x86 assembly (clang, -O0):
<MwSpawn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x4c4(%rbp)
lea    -0x4c0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x4c0(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0xb8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0xb8(%rbp)
mov    %al,-0x4c9(%rbp)
je     11be <MwSpawn+0x6e>
cmpl   $0x14,-0x4c4(%rbp)
setl   %al
mov    %al,-0x4c9(%rbp)
mov    -0x4c9(%rbp),%al
test   $0x1,%al
jne    11d1 <MwSpawn+0x81>
jmp    120f <MwSpawn+0xbf>
mov    -0xb8(%rbp),%rcx
mov    -0x4c4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x4c4(%rbp)
cltq
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xe02(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0xb8(%rbp)
jmp    1198 <MwSpawn+0x48>
movslq -0x4c4(%rbp),%rax
movq   $0x0,-0xb0(%rbp,%rax,8)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x4c8(%rbp)
cmpl   $0x0,-0x4c8(%rbp)
jne    1256 <MwSpawn+0x106>
mov    -0xb0(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1050 <execvp@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x4c8(%rbp),%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MwSpawn>:
push   %r15
push   %r14
push   %rbx
sub    $0x4a0,%rsp
mov    %rdi,%rsi
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     11c2 <MwSpawn+0x72>
xor    %ebx,%ebx
lea    0xe6f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r15
mov    %rax,(%rsp,%rbx,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     11c5 <MwSpawn+0x75>
cmp    $0x13,%rbx
mov    %r15,%rbx
jb     11a0 <MwSpawn+0x50>
jmp    11c5 <MwSpawn+0x75>
xor    %r15d,%r15d
movq   $0x0,(%rsp,%r15,8)
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11e5 <MwSpawn+0x95>
add    $0x4a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%rsp),%rdi
mov    %rsp,%rsi
call   1050 <execvp@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0D\0A\00"
define i32 @MwSpawn(i8* %0) {
%2 = alloca [20 x i8*]
%3 = alloca [1024 x i8]
%4 = bitcast [20 x i8*]* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @strncpy(i8* %5, i8* %0, i32 1024)
%7 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %12, %9 ], [ 0, %1 ]
%11 = phi i8* [ %14, %9 ], [ %7, %1 ]
%12 = add nuw nsw i64 %10, 1
%13 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %10
store i8* %11, i8** %13
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i8* %14, null
%16 = icmp ult i64 %10, 19
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %9, label %18
18: ; preds = %9, %1
%19 = phi i64 [ 0, %1 ], [ %12, %9 ]
%20 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 %19
store i8* null, i8** %20
%21 = call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @execvp(i8* %25, i8** %24)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %18
ret i32 %21
}