#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 *estrtok(char *haystack, const char *needle) {
  static char *saved;
  char *result;
  result = saved = haystack ?: saved;
  if (saved) {
    saved = strpbrk(saved, needle);
    if (saved)
      *saved++ = 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<estrtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     113f <estrtok+0x2f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    114a <estrtok+0x3a>
mov    0x2eea(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,0x2edb(%rip)
mov    %rax,-0x18(%rbp)
cmpq   $0x0,0x2ecf(%rip)
je     11a9 <estrtok+0x99>
mov    0x2ec2(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strpbrk@plt>
mov    %rax,0x2eb2(%rip)
cmpq   $0x0,0x2eaa(%rip)
je     11a4 <estrtok+0x94>
mov    0x2e9d(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e8f(%rip)
movb   $0x0,(%rax)
jmp    11a9 <estrtok+0x99>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<estrtok>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1120 <estrtok+0x10>
mov    0x2f10(%rip),%rbx
mov    %rbx,0x2f09(%rip)
test   %rbx,%rbx
je     1151 <estrtok+0x41>
mov    %rbx,%rdi
call   1030 <strpbrk@plt>
mov    %rax,0x2ef5(%rip)
test   %rax,%rax
je     1151 <estrtok+0x41>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2ee2(%rip)
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@estrtok.saved = internal global i8* null
define i8* @estrtok(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 ne i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
br label %11
9: ; preds = %2
%10 = load i8*, i8** @estrtok.saved
br label %11
11: ; preds = %9, %8
%12 = phi i8* [ %6, %8 ], [ %10, %9 ]
store i8* %12, i8** @estrtok.saved
store i8* %12, i8** %5
%13 = load i8*, i8** @estrtok.saved
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i8*, i8** @estrtok.saved
%17 = load i8*, i8** %4
%18 = call i8* @strpbrk(i8* %16, i8* %17)
store i8* %18, i8** @estrtok.saved
%19 = load i8*, i8** @estrtok.saved
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8*, i8** @estrtok.saved
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** @estrtok.saved
store i8 0, i8* %22
br label %24
24: ; preds = %21, %15
br label %25
25: ; preds = %24, %11
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@estrtok.saved = internal unnamed_addr global i8* null
define i8* @estrtok(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
%4 = load i8*, i8** @estrtok.saved
%5 = select i1 %3, i8* %4, i8* %0
store i8* %5, i8** @estrtok.saved
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i8* @strpbrk(i8* %5, i8* %1)
store i8* %8, i8** @estrtok.saved
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8* %11, i8** @estrtok.saved
store i8 0, i8* %8
br label %12
12: ; preds = %7, %10, %2
ret i8* %5
}