#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 *s, const char *delim) {
  static char *strtok_pos;
  char *tmp = 0;
  if (s == 0)
    s = strtok_pos;
  s += strspn(s, delim);
  if (*s) {
    tmp = s;
    s += strcspn(s, delim);
    if (*s)
      *s++ = 0;
  }
  strtok_pos = s;
  return tmp;
}


x86 assembly (clang, -O0):
<strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114e <strtok+0x2e>
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
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c1 <strtok+0xa1>
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
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bc <strtok+0x9c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
jmp    11c1 <strtok+0xa1>
mov    -0x8(%rbp),%rax
mov    %rax,0x2e6c(%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    0x2f01(%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,0x2ebb(%rip)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@strtok.strtok_pos = 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.strtok_pos
%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 = %11, %17, %2
%20 = phi i8* [ %18, %17 ], [ %14, %11 ], [ %8, %2 ]
%21 = phi i8* [ %8, %17 ], [ %8, %11 ], [ null, %2 ]
store i8* %20, i8** @strtok.strtok_pos
ret i8* %21
}