char *StrTok(char *s, const char *delim) {
  static char *oldstr = ((void *)0);
  char *token = ((void *)0);
  if (s == ((void *)0)) {
    s = oldstr;
  }
  s += StrSpn(s, delim);
  if (*s == '\0') {
    oldstr = s;
    return ((void *)0);
  }
  token = s;
  s = StrPBrk(s, delim);
  if (s != ((void *)0)) {
    *s = '\0';
    oldstr = s + 1;
  } else {
    oldstr = StrChr(token, '\0');
  }
  return token;
}


x86 assembly (clang, -O0):
<StrTok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115e <StrTok+0x2e>
mov    0x2ee6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1030 <StrSpn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a5 <StrTok+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ea8(%rip)
movq   $0x0,-0x8(%rbp)
jmp    1206 <StrTok+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <StrPBrk@plt>
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e8 <StrTok+0xb8>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e5d(%rip)
jmp    11fe <StrTok+0xce>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1040 <StrChr@plt>
cltq
mov    %rax,0x2e42(%rip)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrTok>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1147 <StrTok+0x17>
mov    0x2ef9(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <StrSpn@plt>
cltq
lea    (%rbx,%rax,1),%r15
cmpb   $0x0,(%rbx,%rax,1)
je     117c <StrTok+0x4c>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <StrPBrk@plt>
test   %eax,%eax
je     1184 <StrTok+0x54>
cltq
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    1192 <StrTok+0x62>
mov    %r15,%rax
xor    %r15d,%r15d
jmp    1192 <StrTok+0x62>
mov    %r15,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <StrChr@plt>
cltq
mov    %rax,0x2ea7(%rip)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@StrTok.oldstr = internal global i8* null
define i8* @StrTok(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i8*, i8** @StrTok.oldstr
store i8* %10, i8** %4
br label %11
11: ; preds = %9, %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @StrSpn to i32 (i8*, i8*, ...)*)(i8* %12, i8* %13)
%15 = load i8*, i8** %4
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = load i8*, i8** %4
store i8* %23, i8** @StrTok.oldstr
store i8* null, i8** %3
br label %44
24: ; preds = %11
%25 = load i8*, i8** %4
store i8* %25, i8** %6
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @StrPBrk to i32 (i8*, i8*, ...)*)(i8* %26, i8* %27)
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %4
%31 = load i8*, i8** %4
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i8*, i8** %4
store i8 0, i8* %34
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** @StrTok.oldstr
br label %42
37: ; preds = %24
%38 = load i8*, i8** %6
%39 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @StrChr to i32 (i8*, i32, ...)*)(i8* %38, i32 0)
%40 = sext i32 %39 to i64
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** @StrTok.oldstr
br label %42
42: ; preds = %37, %33
%43 = load i8*, i8** %6
store i8* %43, i8** %3
br label %44
44: ; preds = %42, %22
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
@StrTok.oldstr = internal unnamed_addr global i8* null
define i8* @StrTok(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = load i8*, i8** @StrTok.oldstr
%5 = select i1 %3, i8* %4, i8* %0
%6 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @StrSpn to i32 (i8*, i8*, ...)*)(i8* %5, i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @StrPBrk to i32 (i8*, i8*, ...)*)(i8* %8, i8* %1)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i32 %12, 0
br i1 %15, label %18, label %16
16: ; preds = %11
store i8 0, i8* %14
%17 = getelementptr inbounds i8, i8* %14, i64 1
br label %22
18: ; preds = %11
%19 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @StrChr to i32 (i8*, i32, ...)*)(i8* %8, i32 0)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
br label %22
22: ; preds = %16, %18, %2
%23 = phi i8* [ %8, %2 ], [ %21, %18 ], [ %17, %16 ]
%24 = phi i8* [ null, %2 ], [ %8, %18 ], [ %8, %16 ]
store i8* %23, i8** @StrTok.oldstr
ret i8* %24
}