#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 *s, const char *delim) {
  static char *tok;
  if (s == NULL)
    s = tok;
  s += strspn(s, delim);
  if (*s == '\0')
    return NULL;
  tok = s + strcspn(s, delim);
  if (*tok != '\0')
    *(tok)++ = '\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    1146 <strtok+0x26>
mov    0x2ef6(%rip),%rax
mov    %rax,-0x10(%rbp)
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
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1180 <strtok+0x60>
movq   $0x0,-0x8(%rbp)
jmp    11db <strtok+0xbb>
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,0x2e90(%rip)
mov    0x2e89(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d3 <strtok+0xb3>
mov    0x2e76(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e68(%rip)
movb   $0x0,(%rax)
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    1136 <strtok+0x16>
mov    0x2f02(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     117b <strtok+0x5b>
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
movslq %eax,%rcx
lea    (%rbx,%rcx,1),%rax
mov    %rax,0x2ed3(%rip)
cmpb   $0x0,(%rbx,%rcx,1)
je     117d <strtok+0x5d>
lea    0x1(%rax),%rcx
mov    %rcx,0x2ec2(%rip)
movb   $0x0,(%rax)
jmp    117d <strtok+0x5d>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@strtok.tok = 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.tok
%5 = select i1 %3, i8* %4, i8* %0
%6 = tail call i32 @strspn(i8* %5, i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %2
%12 = tail call i32 @strcspn(i8* %8, i8* %1)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8* %14, i8** @strtok.tok
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %18, i8** @strtok.tok
store i8 0, i8* %14
br label %19
19: ; preds = %11, %17, %2
%20 = phi i8* [ null, %2 ], [ %8, %17 ], [ %8, %11 ]
ret i8* %20
}