#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 */
char *strpbrk(char *, char const *);
int strspn(char *, char const *);
char *strtok(char *s, const char *ct) {
  static char *___strtok;
  char *i, *j, *k;
  i = (!s) ? ___strtok : s;
  if (!i)
    return (NULL);
  j = i + strspn(i, ct);
  if (!*j)
    return (NULL);
  if (!(k = strpbrk(j, ct)))
    ___strtok = 0;
  else {
    *k = '\0';
    ___strtok = ++k;
  }
  return (j);
}


x86 assembly (clang, -O0):
<strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114b <strtok+0x2b>
mov    0x2ef6(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1153 <strtok+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1173 <strtok+0x53>
movq   $0x0,-0x8(%rbp)
jmp    11ff <strtok+0xdf>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11b2 <strtok+0x92>
movq   $0x0,-0x8(%rbp)
jmp    11ff <strtok+0xdf>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11dd <strtok+0xbd>
movq   $0x0,0x2e60(%rip)
jmp    11f7 <strtok+0xd7>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,0x2e41(%rip)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1136 <strtok+0x16>
mov    0x2f02(%rip),%rbx
test   %rbx,%rbx
je     116a <strtok+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     116a <strtok+0x4a>
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strpbrk@plt>
test   %rax,%rax
je     116e <strtok+0x4e>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    1170 <strtok+0x50>
xor    %ebx,%ebx
jmp    1177 <strtok+0x57>
xor    %eax,%eax
mov    %rax,0x2ec1(%rip)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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