#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*/ printf(char *, char *);
char *strdup(char const *);
char *strtok(char *, char *);
char **parse_cmdline(const char *cmdline) {
  char *cmdline_ = strdup(cmdline);
  char **result = malloc(sizeof(char *) * 100);
  int counter = 0;
  result[counter] = strtok(cmdline_, " ");
  while (result[counter] != NULL) {
    result[++counter] = strtok(NULL, " ");
  }
  printf("%s\n", result[0]);
  return result;
}


x86 assembly (clang, -O0):
<parse_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe87(%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
cmpq   $0x0,(%rax,%rcx,8)
je     11cc <parse_cmdline+0x8c>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe55(%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    118d <parse_cmdline+0x4d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmdline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    %rax,%r15
mov    %rax,(%r14)
test   %rax,%rax
je     11a6 <parse_cmdline+0x66>
mov    %r14,%rbx
add    $0x8,%rbx
lea    0xe7b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
test   %rax,%rax
jne    1190 <parse_cmdline+0x50>
lea    0xe55(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i8** @parse_cmdline(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strdup(i8* %6)
store i8* %7, i8** %3
%8 = call i8** @malloc(i32 800)
store i8** %8, i8*** %4
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = load i8**, i8*** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
store i8* %10, i8** %14
br label %15
15: ; preds = %22, %1
%16 = load i8**, i8*** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = load i8**, i8*** %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* %23, i8** %28
br label %15
29: ; preds = %15
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i8**, i8*** %4
ret i8** %34
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define noalias i8** @parse_cmdline(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8** @malloc(i32 800)
%4 = tail call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %9, %6 ], [ 0, %1 ]
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = add nuw nsw i64 %7, 1
%10 = getelementptr inbounds i8*, i8** %3, i64 %9
store i8* %8, i8** %10
%11 = icmp eq i8* %8, null
br i1 %11, label %12, label %6
12: ; preds = %6, %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret i8** %3
}