#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
char *strpbrk(char *, char const *);
size_t strspn(char *, char const *);
char *strtok(char *__restrict s1, const char *__restrict s2) {
  static char *__restrict strtok_s1 = NULL;
  size_t sub;
  char *sb;
  char *tok;
  assert(s2 != NULL);
  if (s1 == NULL) {
    s1 = strtok_s1;
    if (s1 == NULL) {
      return NULL;
    }
  }
  sub = strspn(s1, s2);
  if (sub == 0) {
    return NULL;
  }
  tok = s1 + sub;
  sb = strpbrk(tok, s2);
  if (sb == NULL) {
    strtok_s1 = NULL;
    return tok;
  } else {
    *sb = '\0';
    strtok_s1 = sb + 1;
    return tok;
  }
}


x86 assembly (clang, -O0):
<strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1185 <strtok+0x55>
mov    0x2edc(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <strtok+0x50>
movq   $0x0,-0x8(%rbp)
jmp    120c <strtok+0xdc>
jmp    1185 <strtok+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ae <strtok+0x7e>
movq   $0x0,-0x8(%rbp)
jmp    120c <strtok+0xdc>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ee <strtok+0xbe>
movq   $0x0,0x2e5f(%rip)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120c <strtok+0xdc>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e3c(%rip)
mov    -0x30(%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
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
test   %rbx,%rbx
jne    1159 <strtok+0x29>
mov    0x2eec(%rip),%rbx
test   %rbx,%rbx
je     1185 <strtok+0x55>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
test   %rax,%rax
je     1185 <strtok+0x55>
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strpbrk@plt>
test   %rax,%rax
je     1189 <strtok+0x59>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    118b <strtok+0x5b>
xor    %ebx,%ebx
jmp    1192 <strtok+0x62>
xor    %eax,%eax
mov    %rax,0x2eae(%rip)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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