#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 atoi(char *);
char *strtok(char *, char *);
int split_string(char *str, int *tree) {
  int i = 0;
  char *pch;
  pch = strtok(str, " ");
  while (pch != NULL) {
    tree[i] = atoi(pch);
    pch = strtok(NULL, " ");
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<split_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xebe(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118e <split_string+0x6e>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe89(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <split_string+0x2b>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xed1(%rip),%rsi
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     116f <split_string+0x4f>
lea    0xebe(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14,%rbx,4)
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <split_string+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @split_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
br label %9
9: ; preds = %12, %2
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i8*, i8** %6
%14 = call i32 @atoi(i8* %13)
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %14, i32* %18
%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
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %9
22: ; preds = %9
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @split_string(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %11, %5 ], [ 0, %2 ]
%7 = phi i8* [ %10, %5 ], [ %3, %2 ]
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i32, i32* %1, i64 %6
store i32 %8, i32* %9
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = add nuw i64 %6, 1
%12 = icmp eq i8* %10, null
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = trunc i64 %11 to i32
br label %15
15: ; preds = %13, %2
%16 = phi i32 [ 0, %2 ], [ %14, %13 ]
ret i32 %16
}