#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 *p, const char *tok) {
  static char *t;
  char *r;
  int n;
  if (p)
    t = p;
  r = t + strspn(t, tok);
  if (!(n = strcspn(r, tok)))
    return (0);
  t = r + n;
  if (*t)
    *t++ = 0;
  return (r);
}


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)
mov    0x2eeb(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ee0(%rip),%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),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    1197 <strtok+0x77>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <strtok+0xb9>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,0x2e8f(%rip)
mov    0x2e88(%rip),%rax
cmpb   $0x0,(%rax)
je     11d1 <strtok+0xb1>
mov    0x2e78(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e6a(%rip)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1139 <strtok+0x19>
mov    %rdi,%r15
mov    %rdi,0x2f01(%rip)
jmp    1140 <strtok+0x20>
mov    0x2ef8(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
test   %eax,%eax
je     1184 <strtok+0x64>
movslq %eax,%rcx
lea    (%rbx,%rcx,1),%rax
mov    %rax,0x2eca(%rip)
cmpb   $0x0,(%rbx,%rcx,1)
je     1186 <strtok+0x66>
lea    0x1(%rax),%rcx
mov    %rcx,0x2eb9(%rip)
movb   $0x0,(%rax)
jmp    1186 <strtok+0x66>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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