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

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char const *);
char **startperf_getcmd(const char *cmdstr, pid_t parent_pid) {
  assert(cmdstr);
  char **cmd = NULL, *copy = NULL, *tok = NULL;
  char c = '\0';
  int nelts = 1, i = 0;
  const char *delim = " ";
  const char *p = cmdstr;
  while (c = *p++) {
    if (c == ' ')
      nelts++;
  }
  cmd = (char **)calloc(nelts + 1, sizeof(char *));
  assert(cmd != NULL);
  cmd[nelts] = (char *)NULL;
  copy = (char *)calloc(strlen(cmdstr) + 1, sizeof(char));
  assert(copy != NULL);
  strcpy(copy, cmdstr);
  tok = strtok(copy, delim);
  for (i = 0; tok != NULL; i++) {
    if (strncmp(tok, "%d", 2) == 0) {
      char pid_s[16];
      snprintf(pid_s, sizeof(pid_s), "%d", parent_pid);
      cmd[i] = (char *)calloc(strlen(pid_s) + 1, sizeof(char));
      assert(cmd[i] != NULL);
      strcpy(cmd[i], pid_s);
    } else {
      cmd[i] = (char *)calloc(strlen(tok) + 1, sizeof(char));
      assert(cmd[i] != NULL);
      strcpy(cmd[i], tok);
    }
    tok = strtok(NULL, delim);
  }
  free(copy);
  return cmd;
}


x86 assembly (clang, -O0):
<startperf_getcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <assert@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x48(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
cmp    $0x0,%al
je     120c <startperf_getcmd+0x8c>
movsbl -0x29(%rbp),%eax
cmp    $0x20,%eax
jne    1207 <startperf_getcmd+0x87>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d5 <startperf_getcmd+0x55>
mov    -0x30(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1090 <assert@plt>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1090 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13b3 <startperf_getcmd+0x233>
mov    -0x28(%rbp),%rdi
lea    0xd51(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    133b <startperf_getcmd+0x1bb>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x10,%esi
lea    0xd2a(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x60(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1090 <assert@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x60(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    1394 <startperf_getcmd+0x214>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1090 <assert@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    129b <startperf_getcmd+0x11b>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startperf_getcmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
call   1090 <assert@plt>
mov    $0x1,%ebp
mov    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     11c5 <startperf_getcmd+0x45>
add    $0x1,%rax
cmp    $0x20,%cl
jne    11b0 <startperf_getcmd+0x30>
add    $0x1,%ebp
jmp    11b0 <startperf_getcmd+0x30>
lea    0x1(%rbp),%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    %ebp,%eax
mov    %rbx,(%rsp)
movq   $0x0,(%rbx,%rax,8)
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0xdd7(%rip),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   10a0 <strtok@plt>
test   %rax,%rax
je     12fd <startperf_getcmd+0x17d>
mov    %rax,%r14
lea    0xdb9(%rip),%rbx
lea    0x10(%rsp),%rbp
lea    0xdab(%rip),%r13
mov    (%rsp),%r15
jmp    12a7 <startperf_getcmd+0x127>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%r15)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    (%r15),%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r14
add    $0x8,%r15
test   %rax,%rax
je     12fd <startperf_getcmd+0x17d>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1260 <startperf_getcmd+0xe0>
mov    %rbp,%rdi
mov    $0x10,%esi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%r15)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    (%r15),%rdi
mov    %rbp,%rsi
jmp    128c <startperf_getcmd+0x10c>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"%d\00"
define i8** @startperf_getcmd(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [16 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%14 = load i8*, i8** %3
%15 = call i32 @assert(i8* %14)
store i8** null, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8 0, i8* %8
store i32 1, i32* %9
store i32 0, i32* %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11
%16 = load i8*, i8** %3
store i8* %16, i8** %12
br label %17
17: ; preds = %29, %2
%18 = load i8*, i8** %12
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %12
%20 = load i8, i8* %18
store i8 %20, i8* %8
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 32
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %29
29: ; preds = %26, %22
br label %17
30: ; preds = %17
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
%33 = call i64 @calloc(i32 %32, i32 8)
%34 = inttoptr i64 %33 to i8**
store i8** %34, i8*** %5
%35 = load i8**, i8*** %5
%36 = icmp ne i8** %35, null
%37 = zext i1 %36 to i32
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @assert(i8* %39)
%41 = load i8**, i8*** %5
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
store i8* null, i8** %44
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, 1
%48 = call i64 @calloc(i32 %47, i32 1)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %6
%50 = load i8*, i8** %6
%51 = icmp ne i8* %50, null
%52 = zext i1 %51 to i32
%53 = sext i32 %52 to i64
%54 = inttoptr i64 %53 to i8*
%55 = call i32 @assert(i8* %54)
%56 = load i8*, i8** %6
%57 = load i8*, i8** %3
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = load i8*, i8** %6
%60 = load i8*, i8** %11
%61 = call i8* @strtok(i8* %59, i8* %60)
store i8* %61, i8** %7
store i32 0, i32* %10
br label %62
62: ; preds = %129, %30
%63 = load i8*, i8** %7
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %132
65: ; preds = %62
%66 = load i8*, i8** %7
%67 = call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %99
69: ; preds = %65
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%71 = load i32, i32* %4
%72 = call i32 @snprintf(i8* %70, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%74 = call i32 @strlen(i8* %73)
%75 = add nsw i32 %74, 1
%76 = call i64 @calloc(i32 %75, i32 1)
%77 = inttoptr i64 %76 to i8*
%78 = load i8**, i8*** %5
%79 = load i32, i32* %10
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %78, i64 %80
store i8* %77, i8** %81
%82 = load i8**, i8*** %5
%83 = load i32, i32* %10
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = icmp ne i8* %86, null
%88 = zext i1 %87 to i32
%89 = sext i32 %88 to i64
%90 = inttoptr i64 %89 to i8*
%91 = call i32 @assert(i8* %90)
%92 = load i8**, i8*** %5
%93 = load i32, i32* %10
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8*, i8** %92, i64 %94
%96 = load i8*, i8** %95
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%98 = call i32 @strcpy(i8* %96, i8* %97)
br label %126
99: ; preds = %65
%100 = load i8*, i8** %7
%101 = call i32 @strlen(i8* %100)
%102 = add nsw i32 %101, 1
%103 = call i64 @calloc(i32 %102, i32 1)
%104 = inttoptr i64 %103 to i8*
%105 = load i8**, i8*** %5
%106 = load i32, i32* %10
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i8*, i8** %105, i64 %107
store i8* %104, i8** %108
%109 = load i8**, i8*** %5
%110 = load i32, i32* %10
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8*, i8** %109, i64 %111
%113 = load i8*, i8** %112
%114 = icmp ne i8* %113, null
%115 = zext i1 %114 to i32
%116 = sext i32 %115 to i64
%117 = inttoptr i64 %116 to i8*
%118 = call i32 @assert(i8* %117)
%119 = load i8**, i8*** %5
%120 = load i32, i32* %10
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = load i8*, i8** %7
%125 = call i32 @strcpy(i8* %123, i8* %124)
br label %126
126: ; preds = %99, %69
%127 = load i8*, i8** %11
%128 = call i8* @strtok(i8* null, i8* %127)
store i8* %128, i8** %7
br label %129
129: ; preds = %126
%130 = load i32, i32* %10
%131 = add nsw i32 %130, 1
store i32 %131, i32* %10
br label %62
132: ; preds = %62
%133 = load i8*, i8** %6
%134 = call i32 @free(i8* %133)
%135 = load i8**, i8*** %5
ret i8** %135
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"%d\00"
define i8** @startperf_getcmd(i8* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = tail call i32 @assert(i8* %0)
br label %5
5: ; preds = %12, %2
%6 = phi i32 [ %13, %12 ], [ 1, %2 ]
%7 = phi i8* [ %10, %12 ], [ %0, %2 ]
br label %8
8: ; preds = %5, %8
%9 = phi i8* [ %10, %8 ], [ %7, %5 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %9
switch i8 %11, label %8 [
i8 0, label %14
i8 32, label %12
]
12: ; preds = %8
%13 = add nuw nsw i32 %6, 1
br label %5
14: ; preds = %8
%15 = add nuw nsw i32 %6, 1
%16 = tail call i64 @calloc(i32 %15, i32 8)
%17 = inttoptr i64 %16 to i8**
%18 = icmp ne i64 %16, 0
%19 = zext i1 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @assert(i8* %20)
%22 = zext i32 %6 to i64
%23 = getelementptr inbounds i8*, i8** %17, i64 %22
store i8* null, i8** %23
%24 = tail call i32 @strlen(i8* %0)
%25 = add nsw i32 %24, 1
%26 = tail call i64 @calloc(i32 %25, i32 1)
%27 = inttoptr i64 %26 to i8*
%28 = icmp ne i64 %26, 0
%29 = zext i1 %28 to i64
%30 = inttoptr i64 %29 to i8*
%31 = tail call i32 @assert(i8* %30)
%32 = tail call i32 @strcpy(i8* %27, i8* %0)
%33 = tail call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %71, label %35
35: ; preds = %14
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
br label %37
37: ; preds = %35, %67
%38 = phi i64 [ 0, %35 ], [ %69, %67 ]
%39 = phi i8* [ %33, %35 ], [ %68, %67 ]
%40 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %37
%43 = call i32 @snprintf(i8* %36, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%44 = call i32 @strlen(i8* %36)
%45 = add nsw i32 %44, 1
%46 = call i64 @calloc(i32 %45, i32 1)
%47 = inttoptr i64 %46 to i8*
%48 = getelementptr inbounds i8*, i8** %17, i64 %38
store i8* %47, i8** %48
%49 = icmp ne i64 %46, 0
%50 = zext i1 %49 to i64
%51 = inttoptr i64 %50 to i8*
%52 = call i32 @assert(i8* %51)
%53 = load i8*, i8** %48
%54 = call i32 @strcpy(i8* %53, i8* %36)
br label %67
55: ; preds = %37
%56 = call i32 @strlen(i8* %39)
%57 = add nsw i32 %56, 1
%58 = call i64 @calloc(i32 %57, i32 1)
%59 = inttoptr i64 %58 to i8*
%60 = getelementptr inbounds i8*, i8** %17, i64 %38
store i8* %59, i8** %60
%61 = icmp ne i64 %58, 0
%62 = zext i1 %61 to i64
%63 = inttoptr i64 %62 to i8*
%64 = call i32 @assert(i8* %63)
%65 = load i8*, i8** %60
%66 = call i32 @strcpy(i8* %65, i8* %39)
br label %67
67: ; preds = %55, %42
%68 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%69 = add nuw i64 %38, 1
%70 = icmp eq i8* %68, null
br i1 %70, label %71, label %37
71: ; preds = %67, %14
%72 = call i32 @free(i8* %27)
ret i8** %17
}