#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*/ clean_array(char **);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int split_input_to_array(char *input_string, char **output_array) {
  int args_count = 0;
  char *token_result;
  clean_array(output_array);
  for (args_count = 0; args_count < 513; args_count++) {
    if (args_count == 0) {
      token_result = strtok(input_string, " ");
    } else {
      token_result = strtok(NULL, " ");
    }
    if (token_result == NULL) {
      break;
    }
    output_array[args_count] =
        malloc((strlen(token_result) + 1) * sizeof(char));
    strcpy(output_array[args_count], token_result);
  }
  return args_count;
}


x86 assembly (clang, -O0):
<split_input_to_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <clean_array@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x201,-0x14(%rbp)
jge    1216 <split_input_to_array+0xc6>
cmpl   $0x0,-0x14(%rbp)
jne    11a7 <split_input_to_array+0x57>
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11bb <split_input_to_array+0x6b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4e(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cb <split_input_to_array+0x7b>
jmp    1216 <split_input_to_array+0xc6>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <split_input_to_array+0x27>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_input_to_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <clean_array@plt>
xor    %r13d,%r13d
lea    0xe8f(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %r13,%r13
mov    $0x0,%edi
cmove  %r15,%rdi
mov    %r12,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11ce <split_input_to_array+0x7e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,(%r14,%r13,8)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
add    $0x1,%r13
cmp    $0x201,%r13
jne    1180 <split_input_to_array+0x30>
mov    $0x201,%r13d
mov    %r13d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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