#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 strtoken(char *str, char *separator, char *tokens[]) {
  int i = 0;
  tokens[0] = strtok(str, separator);
  while (tokens[i]) {
    i++;
    tokens[i] = strtok(NULL, separator);
  }
  return i;
}


x86 assembly (clang, -O0):
<strtoken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     117f <strtoken+0x6f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1142 <strtoken+0x32>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoken>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
call   1030 <strtok@plt>
mov    %rax,(%r14)
xor    %r12d,%r12d
test   %rax,%rax
je     114b <strtoken+0x3b>
xchg   %ax,%ax
mov    %r12,%rbx
add    $0x1,%r12
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
mov    %rax,0x8(%r14,%rbx,8)
test   %rax,%rax
jne    1130 <strtoken+0x20>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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