#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*/ *strchr(char const *, char);
char *strtok(char *str, const char *delimiters) {
  static char *next_start;
  if (str != NULL)
    next_start = str;
  if (!*next_start)
    return NULL;
  while (*next_start && strchr(delimiters, *next_start) != NULL)
    ++next_start;
  if (!*next_start)
    return NULL;
  size_t length = 0;
  while (*next_start && !strchr(delimiters, *next_start)) {
    ++next_start;
    ++length;
  }
  if (!*next_start)
    return NULL;
  char *token = next_start;
  ++next_start;
  *token = '\0';
  return token - length;
}


x86 assembly (clang, -O0):
<strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <strtok+0x26>
mov    -0x10(%rbp),%rax
mov    %rax,0x2efa(%rip)
mov    0x2ef3(%rip),%rax
cmpb   $0x0,(%rax)
jne    1153 <strtok+0x43>
movq   $0x0,-0x8(%rbp)
jmp    1295 <strtok+0x185>
jmp    1158 <strtok+0x48>
mov    0x2ed1(%rip),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     118d <strtok+0x7d>
mov    -0x18(%rbp),%rdi
mov    0x2eb5(%rip),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    119d <strtok+0x8d>
jmp    11b4 <strtok+0xa4>
mov    0x2e8c(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e81(%rip)
jmp    1158 <strtok+0x48>
mov    0x2e75(%rip),%rax
cmpb   $0x0,(%rax)
jne    11d1 <strtok+0xc1>
movq   $0x0,-0x8(%rbp)
jmp    1295 <strtok+0x185>
movq   $0x0,-0x20(%rbp)
mov    0x2e50(%rip),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2a(%rbp)
je     1210 <strtok+0x100>
mov    -0x18(%rbp),%rdi
mov    0x2e34(%rip),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1220 <strtok+0x110>
jmp    1243 <strtok+0x133>
mov    0x2e09(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2dfe(%rip)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d9 <strtok+0xc9>
mov    0x2de6(%rip),%rax
cmpb   $0x0,(%rax)
jne    1260 <strtok+0x150>
movq   $0x0,-0x8(%rbp)
jmp    1295 <strtok+0x185>
mov    0x2dc9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dbe(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2db3(%rip)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
sub    -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
test   %rdi,%rdi
je     1126 <strtok+0x16>
mov    %rdi,0x2f0c(%rip)
jmp    112d <strtok+0x1d>
mov    0x2f03(%rip),%rdi
mov    (%rdi),%al
xor    %r14d,%r14d
test   %al,%al
je     116a <strtok+0x5a>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
mov    0x2ede(%rip),%rcx
test   %rax,%rax
je     1173 <strtok+0x63>
lea    0x1(%rcx),%rax
mov    %rax,0x2ece(%rip)
movzbl 0x1(%rcx),%eax
test   %al,%al
jne    1140 <strtok+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%rcx),%al
xor    %r14d,%r14d
test   %al,%al
je     116a <strtok+0x5a>
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
mov    0x2e9e(%rip),%rcx
test   %rax,%rax
jne    11b0 <strtok+0xa0>
lea    0x1(%rcx),%rax
mov    %rax,0x2e8e(%rip)
movzbl 0x1(%rcx),%eax
add    $0xffffffffffffffff,%rbx
test   %al,%al
jne    1180 <strtok+0x70>
jmp    116a <strtok+0x5a>
cmpb   $0x0,(%rcx)
je     11cb <strtok+0xbb>
lea    0x1(%rcx),%rax
mov    %rax,0x2e70(%rip)
movb   $0x0,(%rcx)
add    %rcx,%rbx
mov    %rbx,%r14
jmp    116a <strtok+0x5a>
xor    %r14d,%r14d
jmp    116a <strtok+0x5a>

LLVM IR (-O0):
@strtok.next_start = internal global i8* null
define i8* @strtok(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %4
store i8* %11, i8** @strtok.next_start
br label %12
12: ; preds = %10, %2
%13 = load i8*, i8** @strtok.next_start
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %12
store i8* null, i8** %3
br label %73
17: ; preds = %12
br label %18
18: ; preds = %31, %17
%19 = load i8*, i8** @strtok.next_start
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i8*, i8** @strtok.next_start
%26 = load i8, i8* %25
%27 = call i32* @strchr(i8* %24, i8 signext %26)
%28 = icmp ne i32* %27, null
br label %29
29: ; preds = %23, %18
%30 = phi i1 [ false, %18 ], [ %28, %23 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i8*, i8** @strtok.next_start
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** @strtok.next_start
br label %18
34: ; preds = %29
%35 = load i8*, i8** @strtok.next_start
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %34
store i8* null, i8** %3
br label %73
39: ; preds = %34
store i64 0, i64* %6
br label %40
40: ; preds = %54, %39
%41 = load i8*, i8** @strtok.next_start
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i8*, i8** @strtok.next_start
%48 = load i8, i8* %47
%49 = call i32* @strchr(i8* %46, i8 signext %48)
%50 = icmp ne i32* %49, null
%51 = xor i1 %50, true
br label %52
52: ; preds = %45, %40
%53 = phi i1 [ false, %40 ], [ %51, %45 ]
br i1 %53, label %54, label %59
54: ; preds = %52
%55 = load i8*, i8** @strtok.next_start
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** @strtok.next_start
%57 = load i64, i64* %6
%58 = add i64 %57, 1
store i64 %58, i64* %6
br label %40
59: ; preds = %52
%60 = load i8*, i8** @strtok.next_start
%61 = load i8, i8* %60
%62 = icmp ne i8 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %59
store i8* null, i8** %3
br label %73
64: ; preds = %59
%65 = load i8*, i8** @strtok.next_start
store i8* %65, i8** %7
%66 = load i8*, i8** @strtok.next_start
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** @strtok.next_start
%68 = load i8*, i8** %7
store i8 0, i8* %68
%69 = load i8*, i8** %7
%70 = load i64, i64* %6
%71 = sub i64 0, %70
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8* %72, i8** %3
br label %73
73: ; preds = %64, %63, %38, %16
%74 = load i8*, i8** %3
ret i8* %74
}

LLVM IR (-O2):
@strtok.next_start = internal unnamed_addr global i8* null
define i8* @strtok(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i8*, i8** @strtok.next_start
br label %7
6: ; preds = %2
store i8* %0, i8** @strtok.next_start
br label %7
7: ; preds = %4, %6
%8 = phi i8* [ %5, %4 ], [ %0, %6 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %41, label %11
11: ; preds = %7, %16
%12 = phi i8 [ %18, %16 ], [ %9, %7 ]
%13 = tail call i32* @strchr(i8* %1, i8 signext %12)
%14 = icmp eq i32* %13, null
%15 = load i8*, i8** @strtok.next_start
br i1 %14, label %20, label %16
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %17, i8** @strtok.next_start
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %41, label %11
20: ; preds = %11
%21 = load i8, i8* %15
%22 = icmp eq i8 %21, 0
br i1 %22, label %41, label %23
23: ; preds = %20, %29
%24 = phi i8 [ %32, %29 ], [ %21, %20 ]
%25 = phi i64 [ %31, %29 ], [ 0, %20 ]
%26 = tail call i32* @strchr(i8* %1, i8 signext %24)
%27 = icmp eq i32* %26, null
%28 = load i8*, i8** @strtok.next_start
br i1 %27, label %29, label %34
29: ; preds = %23
%30 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %30, i8** @strtok.next_start
%31 = add i64 %25, 1
%32 = load i8, i8* %30
%33 = icmp eq i8 %32, 0
br i1 %33, label %41, label %23
34: ; preds = %23
%35 = load i8, i8* %28
%36 = icmp eq i8 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %38, i8** @strtok.next_start
store i8 0, i8* %28
%39 = sub i64 0, %25
%40 = getelementptr inbounds i8, i8* %28, i64 %39
br label %41
41: ; preds = %16, %29, %37, %34, %20, %7
%42 = phi i8* [ null, %7 ], [ null, %20 ], [ %40, %37 ], [ null, %34 ], [ null, %29 ], [ null, %16 ]
ret i8* %42
}