#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 *strtok(char *, char *);
int getArguments(char *str, char *arg[]) {
  char delimeter[] = " ";
  char *temp = NULL;
  int i = 0;
  temp = strtok(str, delimeter);
  while (temp != NULL) {
    arg[i++] = temp;
    temp = strtok(NULL, delimeter);
  }
  arg[i] = NULL;
  return i;
}


x86 assembly (clang, -O0):
<getArguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xed9(%rip),%ax
mov    %ax,-0x12(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1186 <getArguments+0x76>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
lea    -0x12(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    114b <getArguments+0x3b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getArguments>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movw   $0x20,0xe(%rsp)
lea    0xe(%rsp),%rsi
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1157 <getArguments+0x47>
lea    0xe(%rsp),%r15
nopl   0x0(%rax)
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
jne    1140 <getArguments+0x30>
mov    %ebx,%eax
movq   $0x0,(%r14,%rax,8)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @getArguments(i8* %0, i8** nocapture writeonly %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 %16, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %10, %7 ], [ 0, %2 ]
%9 = phi i8* [ %12, %7 ], [ %5, %2 ]
%10 = add nuw i64 %8, 1
%11 = getelementptr inbounds i8*, i8** %1, i64 %8
store i8* %9, i8** %11
%12 = call i8* @strtok(i8* null, i8* %4)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = trunc i64 %10 to i32
br label %16
16: ; preds = %14, %2
%17 = phi i32 [ 0, %2 ], [ %15, %14 ]
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
store i8* null, i8** %19
ret i32 %17
}