#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 */
scalar_t__ next_token(char **, char const **, int);
int tokenize(char *dest, const char *src, int sep) {
  int n_token;
  char *p;
  char const *q;
  if (src == NULL) {
    return 0;
  }
  if (dest == NULL) {
    return -1;
  }
  n_token = 0;
  p = dest;
  q = src;
  while (next_token(&p, &q, sep)) {
    n_token++;
  }
  return n_token;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113a <tokenize+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1196 <tokenize+0x86>
cmpq   $0x0,-0x10(%rbp)
jne    1151 <tokenize+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <tokenize+0x86>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <next_token@plt>
cmp    $0x0,%rax
je     1190 <tokenize+0x80>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1168 <tokenize+0x58>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     1157 <tokenize+0x47>
test   %rdi,%rdi
je     115b <tokenize+0x4b>
mov    %edx,%ebx
mov    %rdi,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    $0xffffffff,%ebp
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <next_token@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1140 <tokenize+0x30>
jmp    1160 <tokenize+0x50>
xor    %ebp,%ebp
jmp    1160 <tokenize+0x50>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @tokenize(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = icmp eq i8* %1, null
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = icmp eq i8* %0, null
br i1 %10, label %17, label %11
11: ; preds = %9
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %12
12: ; preds = %12, %11
%13 = phi i32 [ 0, %11 ], [ %16, %12 ]
%14 = call i64 @next_token(i8** %4, i8** %5, i32 %2)
%15 = icmp eq i64 %14, 0
%16 = add nuw nsw i32 %13, 1
br i1 %15, label %17, label %12
17: ; preds = %12, %9, %3
%18 = phi i32 [ 0, %3 ], [ -1, %9 ], [ %13, %12 ]
ret i32 %18
}