#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 const *, char const *);
int strspn(char *, char const *);
char *strtok(char *s, const char *ct) {
  const char *s1;
  char *s2;
  static char *savestring = NULL;
  if (s == NULL) {
    s = savestring;
    if (s == NULL) {
      return ((char *)NULL);
    }
  }
  s1 = s + strspn(s, ct);
  if (*s1 == '\0') {
    savestring = NULL;
    return ((char *)NULL);
  }
  s2 = strpbrk(s1, ct);
  if (s2) {
    *s2++ = '\0';
  }
  savestring = s2;
  return ((char *)s1);
}


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)
jne    1163 <strtok+0x43>
mov    0x2ef6(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115e <strtok+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <strtok+0xd1>
jmp    1163 <strtok+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b0 <strtok+0x90>
movq   $0x0,0x2e95(%rip)
movq   $0x0,-0x8(%rbp)
jmp    11f1 <strtok+0xd1>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11de <strtok+0xbe>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,0x2e4f(%rip)
mov    -0x20(%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     1187 <strtok+0x67>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     116d <strtok+0x4d>
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strpbrk@plt>
test   %rax,%rax
je     1173 <strtok+0x53>
mov    %rax,%rcx
add    $0x1,%rcx
movb   $0x0,(%rax)
jmp    1175 <strtok+0x55>
xor    %ecx,%ecx
xor    %ebx,%ebx
jmp    1175 <strtok+0x55>
xor    %ecx,%ecx
mov    %rcx,0x2ebc(%rip)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ebx,%ebx
jmp    117c <strtok+0x5c>

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

LLVM IR (-O2):
@strtok.savestring = internal unnamed_addr global i8* null
define i8* @strtok(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** @strtok.savestring
%6 = icmp eq i8* %5, null
br i1 %6, label %22, label %7
7: ; preds = %4, %2
%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 %19, label %14
14: ; preds = %7
%15 = tail call i8* @strpbrk(i8* %11, i8* %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %15
br label %19
19: ; preds = %14, %17, %7
%20 = phi i8* [ null, %7 ], [ %18, %17 ], [ null, %14 ]
%21 = phi i8* [ null, %7 ], [ %11, %17 ], [ %11, %14 ]
store i8* %20, i8** @strtok.savestring
br label %22
22: ; preds = %19, %4
%23 = phi i8* [ null, %4 ], [ %21, %19 ]
ret i8* %23
}