#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*/ strcspn(char *, char const *);
int /*<<< orphan*/ strspn(char *, char const *);
char *strtok(char *s1, const char *s2) {
  static char *saves1 = "";
  char *s0;
  if (s1 == 0)
    s1 = saves1;
  if (*(s1 += strspn(s1, s2)) == 0)
    s0 = 0;
  else {
    s0 = s1;
    if (*(s1 += strcspn(s1, s2)) != 0)
      *s1++ = 0;
  }
  return (saves1 = s1, s0);
}


x86 assembly (clang, -O0):
<strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1146 <strtok+0x26>
mov    0x2eee(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
mov    %rax,%rdx
add    %rcx,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1180 <strtok+0x60>
movq   $0x0,-0x18(%rbp)
jmp    11cc <strtok+0xac>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
mov    %rax,%rdx
add    %rcx,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c7 <strtok+0xa7>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
jmp    11cc <strtok+0xac>
mov    -0x8(%rbp),%rax
mov    %rax,0x2e59(%rip)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1137 <strtok+0x17>
mov    0x2ef9(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
cltq
lea    (%rbx,%rax,1),%r15
cmpb   $0x0,(%rbx,%rax,1)
je     1170 <strtok+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
movslq %eax,%rcx
lea    (%r15,%rcx,1),%rax
cmpb   $0x0,(%r15,%rcx,1)
je     1176 <strtok+0x56>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    1176 <strtok+0x56>
mov    %r15,%rax
xor    %r15d,%r15d
mov    %rax,0x2eb3(%rip)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@strtok.saves1 = internal unnamed_addr global i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
@.str = [1 x i8] zeroinitializer
define i8* @strtok(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
%4 = load i8*, i8** @strtok.saves1
%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
%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 0, i8* %14
br label %19
19: ; preds = %2, %11, %17
%20 = phi i8* [ %18, %17 ], [ %14, %11 ], [ %8, %2 ]
%21 = phi i8* [ %8, %17 ], [ %8, %11 ], [ null, %2 ]
store i8* %20, i8** @strtok.saves1
ret i8* %21
}