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

/* Variables and functions */
int errno;
int execlp(char *, char *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ printf(char *, char *, ...);
char *strchr(char *, char);
char *strerror(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void async_run_process(char *cmd) {
  char command[256];
  char *argv[2];
  int i;
  strncpy(command, cmd, sizeof(command));
  command[sizeof(command) - 1] = 0;
  argv[0] = strchr(command, ' ');
  if (argv[0]) {
    *argv[0] = 0;
    argv[0]++;
  }
  if (cmd && cmd[0]) {
    switch (fork()) {
    case 0:
      i = execlp(command, command, argv[0], NULL);
      printf("execlp failed %s=%d (errno=%d:%s)\n", cmd, i, errno,
             strerror(errno));
      break;
    case -1:
      printf("Fork %s failed\n", cmd);
      break;
    default:
      printf("Forked %s\n", cmd);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<async_run_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     11ca <async_run_process+0x6a>
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x120(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12c4 <async_run_process+0x164>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12c4 <async_run_process+0x164>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x128(%rbp)
sub    $0xffffffff,%eax
je     1296 <async_run_process+0x136>
jmp    1202 <async_run_process+0xa2>
mov    -0x128(%rbp),%eax
test   %eax,%eax
jne    12ad <async_run_process+0x14d>
jmp    1215 <async_run_process+0xb5>
lea    -0x110(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x120(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execlp@plt>
mov    %eax,-0x124(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x124(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x138(%rbp),%rsi
mov    -0x130(%rbp),%edx
mov    -0x12c(%rbp),%ecx
mov    %rax,%r8
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12bf <async_run_process+0x15f>
mov    -0x8(%rbp),%rsi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12bf <async_run_process+0x15f>
mov    -0x8(%rbp),%rsi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c4 <async_run_process+0x164>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<async_run_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xff(%rsp)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ac <async_run_process+0x4c>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbx
test   %r14,%r14
jne    11b3 <async_run_process+0x53>
jmp    121f <async_run_process+0xbf>
xor    %ebx,%ebx
test   %r14,%r14
je     121f <async_run_process+0xbf>
cmpb   $0x0,(%r14)
je     121f <async_run_process+0xbf>
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     1205 <async_run_process+0xa5>
test   %eax,%eax
jne    120e <async_run_process+0xae>
mov    %rsp,%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1060 <execlp@plt>
mov    %eax,%ebx
mov    0x2dfe(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe0e(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <printf@plt>
jmp    121f <async_run_process+0xbf>
lea    0xe17(%rip),%rdi
jmp    1215 <async_run_process+0xb5>
lea    0xe1e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"execlp failed %s=%d (errno=%d:%s)\0A\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"Fork %s failed\0A\00"
@.str.2 = [11 x i8] c"Forked %s\0A\00"
define void @async_run_process(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca [2 x i8*]
%5 = alloca i32
store i8* %0, i8** %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strncpy(i8* %6, i8* %7, i32 256)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = call i8* @strchr(i8* %10, i8 signext 32)
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
store i8* %11, i8** %12
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %1
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%18 = load i8*, i8** %17
store i8 0, i8* %18
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %19
br label %22
22: ; preds = %16, %1
%23 = load i8*, i8** %2
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %52
25: ; preds = %22
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %52
31: ; preds = %25
%32 = call i32 (...) @fork()
switch i32 %32, label %48 [
i32 0, label %33
i32 -1, label %45
]
33: ; preds = %31
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%36 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @execlp(i8* %34, i8* %35, i8* %37, i32* null)
store i32 %38, i32* %5
%39 = load i8*, i8** %2
%40 = load i32, i32* %5
%41 = load i32, i32* @errno
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %39, i32 %40, i32 %41, i8* %43)
br label %51
45: ; preds = %31
%46 = load i8*, i8** %2
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %51
48: ; preds = %31
%49 = load i8*, i8** %2
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %48, %45, %33
br label %52
52: ; preds = %51, %25, %22
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"execlp failed %s=%d (errno=%d:%s)\0A\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"Fork %s failed\0A\00"
@.str.2 = [11 x i8] c"Forked %s\0A\00"
define void @async_run_process(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 256)
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 255
store i8 0, i8* %5
%6 = call i8* @strchr(i8* %3, i8 signext 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
store i8 0, i8* %6
%9 = getelementptr inbounds i8, i8* %6, i64 1
br label %10
10: ; preds = %8, %1
%11 = phi i8* [ %9, %8 ], [ null, %1 ]
%12 = icmp eq i8* %0, null
br i1 %12, label %27, label %13
13: ; preds = %10
%14 = load i8, i8* %0
%15 = icmp eq i8 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = call i32 (...) @fork()
switch i32 %17, label %25 [
i32 0, label %18
i32 -1, label %23
]
18: ; preds = %16
%19 = call i32 @execlp(i8* %3, i8* %3, i8* %11, i32* null)
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %19, i32 %20, i8* %21)
br label %27
23: ; preds = %16
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
25: ; preds = %16
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %18, %23, %25, %13, %10
ret void
}