#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 strspn(char *, char const *);
char *strtok(char *restrict s, const char *restrict delim) {
  static char *line;
  if (s)
    line = s;
  if (!s && !line)
    return NULL;
  s = line + strspn(line, delim);
  if (*s == '\0')
    return line = NULL;
  line = s + strcspn(s, delim);
  if (*line != '\0')
    *line++ = '\0';
  else
    line = NULL;
  return s;
}


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     1146 <strtok+0x26>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ef2(%rip)
cmpq   $0x0,-0x10(%rbp)
jne    116c <strtok+0x4c>
cmpq   $0x0,0x2edf(%rip)
jne    116c <strtok+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    122a <strtok+0x10a>
mov    0x2ec5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2eba(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11bf <strtok+0x9f>
movq   $0x0,0x2e86(%rip)
movq   $0x0,-0x8(%rbp)
jmp    122a <strtok+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2e51(%rip)
mov    0x2e4a(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1217 <strtok+0xf7>
mov    0x2e37(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e29(%rip)
movb   $0x0,(%rax)
jmp    1222 <strtok+0x102>
movq   $0x0,0x2e16(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%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.line = 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 %8, label %10
8: ; preds = %2
%9 = load i8*, i8** %4
store i8* %9, i8** @strtok.line
br label %10
10: ; preds = %8, %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i8*, i8** @strtok.line
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13
store i8* null, i8** %3
br label %46
17: ; preds = %13, %10
%18 = load i8*, i8** @strtok.line
%19 = load i8*, i8** @strtok.line
%20 = load i8*, i8** %5
%21 = call i32 @strspn(i8* %19, i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %17
store i8* null, i8** @strtok.line
store i8* null, i8** %3
br label %46
29: ; preds = %17
%30 = load i8*, i8** %4
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i32 @strcspn(i8* %31, i8* %32)
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
store i8* %35, i8** @strtok.line
%36 = load i8*, i8** @strtok.line
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i8*, i8** @strtok.line
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** @strtok.line
store i8 0, i8* %41
br label %44
43: ; preds = %29
store i8* null, i8** @strtok.line
br label %44
44: ; preds = %43, %40
%45 = load i8*, i8** %4
store i8* %45, i8** %3
br label %46
46: ; preds = %44, %28, %16
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@strtok.line = 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.line
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %2, %4
%8 = phi i8* [ %5, %4 ], [ %0, %2 ]
%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.line
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.line
store i8 0, i8* %18
br label %24
23: ; preds = %15
store i8* null, i8** @strtok.line
br label %24
24: ; preds = %21, %23, %4, %14
%25 = phi i8* [ null, %14 ], [ null, %4 ], [ %11, %23 ], [ %11, %21 ]
ret i8* %25
}