#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 const *);
int str_split(char *src, const char *delim, char **dst) {
  char *next;
  int count = 0;
  next = strtok(src, delim);
  while (next != NULL) {
    *dst++ = next;
    ++count;
    next = strtok(NULL, delim);
  }
  return count;
}


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,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117c <str_split+0x6c>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    113c <str_split+0x2c>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_split>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1147 <str_split+0x37>
nopw   0x0(%rax,%rax,1)
mov    %rax,(%r14,%rbx,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <str_split+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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