#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__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, scalar_t__);
char *strtok(char *, char const *);
int tokenize(char **tokens, const char *src, const char *delimiters) {
  char src_copy[(1024)];
  char *token;
  int num_tokens;
  strncpy(src_copy, src, strlen(src) + 1);
  num_tokens = 0;
  token = strtok(src_copy, delimiters);
  while (token != NULL) {
    tokens[num_tokens] = token;
    num_tokens += 1;
    token = strtok(NULL, delimiters);
  }
  return num_tokens;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     11f0 <tokenize+0xc0>
mov    -0x428(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x42c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x428(%rbp)
jmp    11a4 <tokenize+0x74>
mov    -0x42c(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1197 <tokenize+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <tokenize+0x50>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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