#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 */
char **malloc(int);
int /*<<< orphan*/ run_cmd(int, char **);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
void parse_cmd(char *command) {
  if (strlen(command) <= 0)
    return;
  int bs = 2048;
  int s = 0;
  char **arr = malloc(bs);
  int i = 0;
  arr[i] = strtok(command, " ");
  s += strlen(arr[i]);
  while (arr[i] != NULL) {
    arr[++i] = strtok(NULL, " ");
  }
  run_cmd(i, arr);
}


x86 assembly (clang, -O0):
<parse_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jg     1164 <parse_cmd+0x24>
jmp    120d <parse_cmd+0xcd>
movl   $0x800,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1201 <parse_cmd+0xc1>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe20(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11c2 <parse_cmd+0x82>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <run_cmd@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmd>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
jle    11a7 <parse_cmd+0x67>
mov    $0x800,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    %rax,(%r14)
xor    %ebx,%ebx
test   %rax,%rax
je     1198 <parse_cmd+0x58>
lea    0xe81(%rip),%r15
nop
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,0x8(%r14,%rbx,8)
add    $0x1,%rbx
test   %rax,%rax
jne    1180 <parse_cmd+0x40>
mov    %ebx,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <run_cmd@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @parse_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = icmp sle i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %48
11: ; preds = %1
store i32 2048, i32* %3
store i32 0, i32* %4
%12 = load i32, i32* %3
%13 = call i8** @malloc(i32 %12)
store i8** %13, i8*** %5
store i32 0, i32* %6
%14 = load i8*, i8** %2
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i8**, i8*** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
store i8* %15, i8** %19
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i64 @strlen(i8* %24)
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = add nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %4
br label %30
30: ; preds = %37, %11
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %44
37: ; preds = %30
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%39 = load i8**, i8*** %5
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
store i8* %38, i8** %43
br label %30
44: ; preds = %30
%45 = load i32, i32* %6
%46 = load i8**, i8*** %5
%47 = call i32 @run_cmd(i32 %45, i8** %46)
br label %48
48: ; preds = %44, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @parse_cmd(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp slt i64 %2, 1
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i8** @malloc(i32 2048)
%6 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %4, %8
%9 = phi i64 [ %11, %8 ], [ 0, %4 ]
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = add nuw nsw i64 %9, 1
%12 = getelementptr inbounds i8*, i8** %5, i64 %11
store i8* %10, i8** %12
%13 = icmp eq i8* %10, null
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = trunc i64 %11 to i32
br label %16
16: ; preds = %14, %4
%17 = phi i32 [ 0, %4 ], [ %15, %14 ]
%18 = tail call i32 @run_cmd(i32 %17, i8** %5)
br label %19
19: ; preds = %1, %16
ret void
}