#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char **malloc(int);
char **realloc(char **, int);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
char **mysh_split_line(char *line) {
  int num_max_tokens = 64;
  char **tokens = malloc(num_max_tokens * sizeof(char *));
  char *token;
  int position = 0;
  if (!tokens) {
    fprintf(stderr, "Memory Allocation Failure\n");
    exit(EXIT_FAILURE);
  }
  token = strtok(line, " \t\r\n");
  while (token != NULL) {
    tokens[position++] = token;
    if (position >= num_max_tokens) {
      num_max_tokens += 64;
      tokens = realloc(tokens, num_max_tokens * sizeof(char *));
      if (!tokens) {
        fprintf(stderr, "Memory Allocation Failure\n");
        exit(EXIT_FAILURE);
      }
    }
    token = strtok(NULL, " \t\r\n");
  }
  tokens[position] = (char *)NULL;
  return tokens;
}


x86 assembly (clang, -O0):
<mysh_split_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x40,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <mysh_split_line+0x5b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     125c <mysh_split_line+0x10c>
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1243 <mysh_split_line+0xf3>
mov    -0xc(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123e <mysh_split_line+0xee>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1243 <mysh_split_line+0xf3>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdcd(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11bf <mysh_split_line+0x6f>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysh_split_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x200,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11d8 <mysh_split_line+0x88>
mov    %rax,%r15
lea    0xea7(%rip),%rsi
mov    %r14,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11ff <mysh_split_line+0xaf>
mov    $0x40,%r12d
xor    %ebx,%ebx
lea    0xe8b(%rip),%r14
jmp    11b6 <mysh_split_line+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r15
add    $0x40,%r12d
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11fb <mysh_split_line+0xab>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %ebx,%r12d
jg     11a7 <mysh_split_line+0x57>
lea    0x200(,%r12,8),%esi
mov    %r15,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
jne    11a0 <mysh_split_line+0x50>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %ebx,%eax
jmp    1201 <mysh_split_line+0xb1>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Memory Allocation Failure\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c" \09\0D\0A\00"
define i8** @mysh_split_line(i8* %0) {
%2 = tail call i8** @malloc(i32 512)
%3 = icmp eq i8** %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %38, label %12
12: ; preds = %9, %31
%13 = phi i64 [ %17, %31 ], [ 0, %9 ]
%14 = phi i8* [ %34, %31 ], [ %10, %9 ]
%15 = phi i8** [ %33, %31 ], [ %2, %9 ]
%16 = phi i32 [ %32, %31 ], [ 64, %9 ]
%17 = add nuw i64 %13, 1
%18 = getelementptr inbounds i8*, i8** %15, i64 %13
store i8* %14, i8** %18
%19 = trunc i64 %17 to i32
%20 = icmp sgt i32 %16, %19
br i1 %20, label %31, label %21
21: ; preds = %12
%22 = add nsw i32 %16, 64
%23 = shl i32 %22, 3
%24 = tail call i8** @realloc(i8** %15, i32 %23)
%25 = icmp eq i8** %24, null
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %21, %12
%32 = phi i32 [ %22, %21 ], [ %16, %12 ]
%33 = phi i8** [ %24, %21 ], [ %15, %12 ]
%34 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %12
36: ; preds = %31
%37 = and i64 %17, 4294967295
br label %38
38: ; preds = %36, %9
%39 = phi i8** [ %2, %9 ], [ %33, %36 ]
%40 = phi i64 [ 0, %9 ], [ %37, %36 ]
%41 = getelementptr inbounds i8*, i8** %39, i64 %40
store i8* null, i8** %41
ret i8** %39
}