#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 strcspn(char *, char const *);
int /*<<< orphan*/ strspn(char *, char const *);
char *strtok(char *restrict s, const char *restrict sep) {
  static char *p;
  if (!s && !(s = p)) {
    return NULL;
  }
  s += strspn(s, sep);
  if (!*s) {
    return p = 0;
  }
  p = s + strcspn(s, sep);
  if (*p) {
    *p++ = 0;
  } else {
    p = 0;
  }
  return s;
}


x86 assembly (clang, -O0):
<strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <strtok+0x3d>
mov    0x2ef6(%rip),%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    115d <strtok+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    1207 <strtok+0xe7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
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
cmpb   $0x0,(%rax)
jne    119f <strtok+0x7f>
movq   $0x0,0x2ea6(%rip)
movq   $0x0,-0x8(%rbp)
jmp    1207 <strtok+0xe7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2e71(%rip)
mov    0x2e6a(%rip),%rax
cmpb   $0x0,(%rax)
je     11f4 <strtok+0xd4>
mov    0x2e5a(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e4c(%rip)
movb   $0x0,(%rax)
jmp    11ff <strtok+0xdf>
movq   $0x0,0x2e39(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%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    113b <strtok+0x1b>
mov    0x2f02(%rip),%rbx
test   %rbx,%rbx
je     1182 <strtok+0x62>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     1177 <strtok+0x57>
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     1186 <strtok+0x66>
add    %rbx,%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x2ec6(%rip)
movb   $0x0,(%rax)
jmp    1191 <strtok+0x71>
movq   $0x0,0x2eb6(%rip)
xor    %ebx,%ebx
jmp    1191 <strtok+0x71>
movq   $0x0,0x2ea7(%rip)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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