#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 str_split(char dst[][512], char *str, const char *spl) {
  int n = 0;
  char *result = NULL;
  result = strtok(str, spl);
  while (result != NULL) {
    strcpy(dst[n++], result);
    result = strtok(NULL, spl);
  }
  return n;
}


x86 assembly (clang, -O0):
<str_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1196 <str_split+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltq
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1154 <str_split+0x34>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_split>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <strtok@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1165 <str_split+0x45>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x200,%rbx
add    $0x1,%r15d
test   %rax,%rax
jne    1140 <str_split+0x20>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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