#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*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
void tokenize(char *usrc, char **tokens, int *ntokens, int max_tokens) {
  int i;
  static char src[1024];
  strncpy(src, usrc, 1024);
  for (i = 1, tokens[0] = strtok(src, " :\n");
       i < max_tokens && (tokens[i] = strtok(NULL, " ,\n")); i++)
    ;
  *ntokens = i;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2efe(%rip),%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
movl   $0x1,-0x20(%rbp)
lea    0x2ee6(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    11a7 <tokenize+0x87>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe78(%rip),%rsi
call   1040 <strtok@plt>
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b7 <tokenize+0x97>
jmp    11ca <tokenize+0xaa>
jmp    11bc <tokenize+0x9c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <tokenize+0x50>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rsi
lea    0x2f02(%rip),%r15
mov    %r15,%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    0xeae(%rip),%rsi
mov    %r15,%rdi
call   1040 <strtok@plt>
mov    %rax,0x0(%r13)
mov    $0x1,%ebp
cmp    $0x2,%r12d
jl     119f <tokenize+0x7f>
mov    %r12d,%ebx
mov    $0x1,%ebp
lea    0xe8c(%rip),%r15
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,0x0(%r13,%rbp,8)
test   %rax,%rax
je     119f <tokenize+0x7f>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <tokenize+0x60>
mov    %ebx,%ebp
mov    %ebp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tokenize.src = internal global [1024 x i8] zeroinitializer
@.str = [4 x i8] c" :\0A\00"
@.str.1 = [4 x i8] c" ,\0A\00"
define void @tokenize(i8* %0, i8** %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @tokenize.src, i64 0, i64 0), i8* %10, i32 1024)
store i32 1, i32* %9
%12 = call i8* @strtok(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @tokenize.src, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 0
store i8* %12, i8** %14
br label %15
15: ; preds = %29, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8**, i8*** %6
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
%25 = icmp ne i8* %20, null
br label %26
26: ; preds = %19, %15
%27 = phi i1 [ false, %15 ], [ %25, %19 ]
br i1 %27, label %28, label %32
28: ; preds = %26
br label %29
29: ; preds = %28
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %15
32: ; preds = %26
%33 = load i32, i32* %9
%34 = load i32*, i32** %7
store i32 %33, i32* %34
ret void
}

LLVM IR (-O2):
@tokenize.src = internal global [1024 x i8] zeroinitializer
@.str = [4 x i8] c" :\0A\00"
@.str.1 = [4 x i8] c" ,\0A\00"
define void @tokenize(i8* %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2, i32 %3) {
%5 = tail call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @tokenize.src, i64 0, i64 0), i8* %0, i32 1024)
%6 = tail call i8* @strtok(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @tokenize.src, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = icmp sgt i32 %3, 1
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = zext i32 %3 to i64
br label %10
10: ; preds = %8, %15
%11 = phi i64 [ 1, %8 ], [ %16, %15 ]
%12 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 %11
store i8* %12, i8** %13
%14 = icmp eq i8* %12, null
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %20, label %10
18: ; preds = %10
%19 = trunc i64 %11 to i32
br label %20
20: ; preds = %15, %18, %4
%21 = phi i32 [ 1, %4 ], [ %19, %18 ], [ %3, %15 ]
store i32 %21, i32* %2
ret void
}