#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 */
scalar_t__ malloc(int);
char *strtok(char *, char *);
char tolower(char);
char **cmd_tokenize(char *cmd) {
  char **ret = (char **)malloc(7 * sizeof(char));
  int j;
  for (char *p = cmd; *p; p++) {
    *p = tolower(*p);
    if (*p == '\n')
      *p = '\0';
  }
  ret[0] = strtok(cmd, " .-");
  for (j = 1; j < 7; j++) {
    ret[j] = strtok(NULL, " .-");
  }
  return ret;
}


x86 assembly (clang, -O0):
<cmd_tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x7,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a0 <cmd_tokenize+0x70>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    118a <cmd_tokenize+0x5a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    118f <cmd_tokenize+0x5f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <cmd_tokenize+0x22>
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jge    11f8 <cmd_tokenize+0xc8>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <cmd_tokenize+0x91>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    $0x7,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    (%r15),%al
test   %al,%al
je     117e <cmd_tokenize+0x4e>
lea    0x1(%r15),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1030 <tolower@plt>
cmp    $0xa,%al
movzbl %al,%eax
cmove  %ebp,%eax
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <cmd_tokenize+0x30>
lea    0xe7b(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,(%r12)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,0x8(%r12)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,0x10(%r12)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,0x18(%r12)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,0x20(%r12)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,0x28(%r12)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,0x30(%r12)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c" .-\00"
define i8** @cmd_tokenize(i8* %0) {
%2 = tail call i64 @malloc(i32 7)
%3 = inttoptr i64 %2 to i8**
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %20, %1
%7 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %3, i64 1
store i8* %8, i8** %9
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %3, i64 2
store i8* %10, i8** %11
%12 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %3, i64 3
store i8* %12, i8** %13
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds i8*, i8** %3, i64 4
store i8* %14, i8** %15
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds i8*, i8** %3, i64 5
store i8* %16, i8** %17
%18 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds i8*, i8** %3, i64 6
store i8* %18, i8** %19
ret i8** %3
20: ; preds = %1, %20
%21 = phi i8 [ %27, %20 ], [ %4, %1 ]
%22 = phi i8* [ %26, %20 ], [ %0, %1 ]
%23 = tail call signext i8 @tolower(i8 signext %21)
%24 = icmp eq i8 %23, 10
%25 = select i1 %24, i8 0, i8 %23
store i8 %25, i8* %22
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %6, label %20
}