#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 */
char *strpbrk(char *, char const *);
char *strtok(char *s, const char *ct) {
  static char *_strtok_next = NULL;
  if (s == NULL) {
    char *current_token = _strtok_next;
    char *token_end = strpbrk(current_token, ct);
    if (token_end == NULL) {
      _strtok_next = NULL;
      return (current_token);
    } else {
      *token_end = '\0';
      _strtok_next = token_end + 1;
      return (current_token);
    }
  } else {
    char *token_end = strpbrk(s, ct);
    if (token_end == NULL) {
      _strtok_next = NULL;
      return (s);
    } else {
      *token_end = '\0';
      _strtok_next = token_end + 1;
      return (s);
    }
  }
}


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)
jne    118d <strtok+0x7d>
mov    0x2efe(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116a <strtok+0x5a>
movq   $0x0,0x2ed3(%rip)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <strtok+0xcf>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2eb0(%rip)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <strtok+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strpbrk@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c1 <strtok+0xb1>
movq   $0x0,0x2e7c(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <strtok+0xcf>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e59(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok>:
push   %rbx
test   %rdi,%rdi
je     111b <strtok+0xb>
mov    %rdi,%rbx
jmp    1125 <strtok+0x15>
mov    0x2f0e(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strpbrk@plt>
test   %rax,%rax
je     1138 <strtok+0x28>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    113a <strtok+0x2a>
xor    %eax,%eax
mov    %rax,0x2eef(%rip)
mov    %rbx,%rax
pop    %rbx
ret

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

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