#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*/ strcpy(char *, char *);
char *strtok(char *, char const *);
int args_str_array(char *str, char **args) {
  const char s[2] = " ";
  char *token;
  int index = 0;
  int ii;
  token = strtok(str, s);
  while (token != NULL) {
    strcpy(args[index], token);
    index++;
    token = strtok(NULL, s);
  }
  return index;
}


x86 assembly (clang, -O0):
<args_str_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec9(%rip),%ax
mov    %ax,-0x12(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1192 <args_str_array+0x72>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x12(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1153 <args_str_array+0x33>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<args_str_array>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movw   $0x20,0xe(%rsp)
lea    0xe(%rsp),%rsi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     116f <args_str_array+0x4f>
lea    0xe(%rsp),%r15
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1150 <args_str_array+0x30>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @args_str_array(i8* %0, i8** nocapture %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 32, i16* %3
%5 = call i8* @strtok(i8* %0, i8* %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %13, %7 ], [ 0, %2 ]
%9 = phi i8* [ %14, %7 ], [ %5, %2 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %8
%11 = load i8*, i8** %10
%12 = tail call i32 @strcpy(i8* %11, i8* %9)
%13 = add nuw i64 %8, 1
%14 = call i8* @strtok(i8* null, i8* %4)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = trunc i64 %13 to i32
br label %18
18: ; preds = %16, %2
%19 = phi i32 [ 0, %2 ], [ %17, %16 ]
ret i32 %19
}