#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*/ EXIT_FAILURE;
int execv(char const *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *strtok(char *, char *);
int create_process(const char *file, const char *argv) {
  int child;
  char *strargv[128] = {0};
  int i = 0;
  char *tempargv = (char *)malloc(strlen(argv) + 1);
  strcpy(tempargv, argv);
  strargv[i] = strtok(tempargv, " ");
  while (strargv[i] != NULL) {
    i++;
    strargv[i] = strtok(NULL, " ");
  }
  if ((child = fork()) == -1) {
    perror("fork process error\n");
    exit(EXIT_FAILURE);
  } else if (child == 0) {
    if (execv(file, strargv) == -1) {
      perror("execv error");
      exit(EXIT_FAILURE);
    }
  } else {
    return child;
  }
}


x86 assembly (clang, -O0):
<create_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0x424(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x430(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%rcx
movslq -0x424(%rbp),%rax
mov    %rcx,-0x420(%rbp,%rax,8)
ff
movslq -0x424(%rbp),%rax
cmpq   $0x0,-0x420(%rbp,%rax,8)
je     125d <create_process+0xcd>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdbf(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%rcx
movslq -0x424(%rbp),%rax
mov    %rcx,-0x420(%rbp,%rax,8)
ff
jmp    1211 <create_process+0x81>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    128a <create_process+0xfa>
lea    0xd8b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    12cc <create_process+0x13c>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10a0 <execv@plt>
cmp    $0xffffffff,%eax
jne    12c7 <create_process+0x137>
lea    0xd62(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12d7 <create_process+0x147>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12dc <create_process+0x14c>
jmp    12dc <create_process+0x14c>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1216 <create_process+0x86>
lea    0x8(%rsp),%rbx
lea    0xe0d(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
test   %rax,%rax
jne    1200 <create_process+0x70>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1231 <create_process+0xa1>
cmp    $0xffffffff,%ebp
jne    1241 <create_process+0xb1>
lea    0xdd3(%rip),%rdi
jmp    1256 <create_process+0xc6>
mov    %rsp,%rsi
mov    %r14,%rdi
call   10a0 <execv@plt>
cmp    $0xffffffff,%eax
je     124f <create_process+0xbf>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdc0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [20 x i8] c"fork process error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"execv error\00"
define i32 @create_process(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [128 x i8*]
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = bitcast [128 x i8*]* %7 to i8*
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = load i8*, i8** %5
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %9
%20 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [128 x i8*], [128 x i8*]* %7, i64 0, i64 %22
store i8* %20, i8** %23
br label %24
24: ; preds = %30, %2
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [128 x i8*], [128 x i8*]* %7, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [128 x i8*], [128 x i8*]* %7, i64 0, i64 %35
store i8* %33, i8** %36
br label %24
37: ; preds = %24
%38 = call i32 (...) @fork()
store i32 %38, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %37
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %57
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = getelementptr inbounds [128 x i8*], [128 x i8*]* %7, i64 0, i64 0
%50 = call i32 @execv(i8* %48, i8** %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %47
br label %59
57: ; preds = %44
%58 = load i32, i32* %6
store i32 %58, i32* %3
br label %60
59: ; preds = %56
br label %60
60: ; preds = %57, %59
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [20 x i8] c"fork process error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"execv error\00"
define i32 @create_process(i8* %0, i8* %1) {
%3 = alloca [128 x i8*]
%4 = bitcast [128 x i8*]* %3 to i8*
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add nsw i64 %5, 1
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* %1)
%10 = tail call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [128 x i8*], [128 x i8*]* %3, i64 0, i64 0
store i8* %10, i8** %11
%12 = icmp eq i8* %10, null
br i1 %12, label %19, label %13
13: ; preds = %2, %13
%14 = phi i64 [ %15, %13 ], [ 0, %2 ]
%15 = add nuw nsw i64 %14, 1
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [128 x i8*], [128 x i8*]* %3, i64 0, i64 %15
store i8* %16, i8** %17
%18 = icmp eq i8* %16, null
br i1 %18, label %19, label %13
19: ; preds = %13, %2
%20 = tail call i32 (...) @fork()
switch i32 %20, label %32 [
i32 -1, label %21
i32 0, label %25
]
21: ; preds = %19
%22 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %19
%26 = call i32 @execv(i8* %0, i8** %11)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %25, %19
ret i32 %20
}