#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 */
scalar_t__ isinstr(char, char *);
char *parser_strtok(char *s, char *delim) {
  static char *pstr = NULL;
  static char *p = NULL;
  if (s != NULL) {
    pstr = s;
  } else {
    pstr = p;
  }
  while (isinstr(*pstr, delim))
    pstr++;
  if (*pstr == '\0')
    return NULL;
  p = pstr;
  while (!isinstr(*p, delim))
    p++;
  *p = '\0';
  p++;
  return (char *)pstr;
}


x86 assembly (clang, -O0):
<parser_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113b <parser_strtok+0x2b>
mov    -0x10(%rbp),%rax
mov    %rax,0x2efa(%rip)
jmp    1149 <parser_strtok+0x39>
mov    0x2ef6(%rip),%rax
mov    %rax,0x2ee7(%rip)
jmp    114e <parser_strtok+0x3e>
mov    0x2edb(%rip),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <isinstr@plt>
cmp    $0x0,%rax
je     1184 <parser_strtok+0x74>
mov    0x2ebc(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2eb1(%rip)
jmp    114e <parser_strtok+0x3e>
mov    0x2ea5(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a4 <parser_strtok+0x94>
movq   $0x0,-0x8(%rbp)
jmp    121b <parser_strtok+0x10b>
mov    0x2e85(%rip),%rax
mov    %rax,0x2e86(%rip)
mov    0x2e7f(%rip),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1030 <isinstr@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11dd <parser_strtok+0xcd>
jmp    11f4 <parser_strtok+0xe4>
mov    0x2e54(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e49(%rip)
jmp    11b2 <parser_strtok+0xa2>
mov    0x2e3d(%rip),%rax
movb   $0x0,(%rax)
mov    0x2e33(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e28(%rip)
mov    0x2e19(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parser_strtok>:
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
jne    1120 <parser_strtok+0x10>
mov    0x2f18(%rip),%rdi
mov    %rdi,0x2f09(%rip)
movsbl (%rdi),%edi
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rsi
call   1030 <isinstr@plt>
test   %rax,%rax
je     1155 <parser_strtok+0x45>
mov    0x2eec(%rip),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x2ee1(%rip)
movsbl 0x1(%rax),%edi
jmp    1130 <parser_strtok+0x20>
mov    0x2ed4(%rip),%rcx
mov    (%rcx),%al
test   %al,%al
je     11b3 <parser_strtok+0xa3>
mov    %rcx,0x2ecf(%rip)
movsbl %al,%edi
nopl   0x0(%rax)
mov    %rbx,%rsi
call   1030 <isinstr@plt>
test   %rax,%rax
jne    1195 <parser_strtok+0x85>
mov    0x2eb4(%rip),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x2ea9(%rip)
movsbl 0x1(%rax),%edi
jmp    1170 <parser_strtok+0x60>
mov    0x2e9c(%rip),%rax
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,0x2e8e(%rip)
mov    0x2e7f(%rip),%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@parser_strtok.pstr = internal global i8* null
@parser_strtok.p = internal global i8* null
define i8* @parser_strtok(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i8*, i8** %4
store i8* %9, i8** @parser_strtok.pstr
br label %12
10: ; preds = %2
%11 = load i8*, i8** @parser_strtok.p
store i8* %11, i8** @parser_strtok.pstr
br label %12
12: ; preds = %10, %8
br label %13
13: ; preds = %19, %12
%14 = load i8*, i8** @parser_strtok.pstr
%15 = load i8, i8* %14
%16 = load i8*, i8** %5
%17 = call i64 @isinstr(i8 signext %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i8*, i8** @parser_strtok.pstr
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** @parser_strtok.pstr
br label %13
22: ; preds = %13
%23 = load i8*, i8** @parser_strtok.pstr
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i8* null, i8** %3
br label %45
28: ; preds = %22
%29 = load i8*, i8** @parser_strtok.pstr
store i8* %29, i8** @parser_strtok.p
br label %30
30: ; preds = %37, %28
%31 = load i8*, i8** @parser_strtok.p
%32 = load i8, i8* %31
%33 = load i8*, i8** %5
%34 = call i64 @isinstr(i8 signext %32, i8* %33)
%35 = icmp ne i64 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i8*, i8** @parser_strtok.p
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** @parser_strtok.p
br label %30
40: ; preds = %30
%41 = load i8*, i8** @parser_strtok.p
store i8 0, i8* %41
%42 = load i8*, i8** @parser_strtok.p
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** @parser_strtok.p
%44 = load i8*, i8** @parser_strtok.pstr
store i8* %44, i8** %3
br label %45
45: ; preds = %40, %27
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@parser_strtok.pstr = internal unnamed_addr global i8* null
@parser_strtok.p = internal unnamed_addr global i8* null
define i8* @parser_strtok(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = load i8*, i8** @parser_strtok.p
%5 = select i1 %3, i8* %4, i8* %0
store i8* %5, i8** @parser_strtok.pstr
%6 = load i8, i8* %5
%7 = tail call i64 @isinstr(i8 signext %6, i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %2, %9
%10 = load i8*, i8** @parser_strtok.pstr
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %11, i8** @parser_strtok.pstr
%12 = load i8, i8* %11
%13 = tail call i64 @isinstr(i8 signext %12, i8* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %9
15: ; preds = %9, %2
%16 = load i8*, i8** @parser_strtok.pstr
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %15
store i8* %16, i8** @parser_strtok.p
%20 = tail call i64 @isinstr(i8 signext %17, i8* %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19, %22
%23 = load i8*, i8** @parser_strtok.p
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** @parser_strtok.p
%25 = load i8, i8* %24
%26 = tail call i64 @isinstr(i8 signext %25, i8* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %22, label %28
28: ; preds = %22, %19
%29 = load i8*, i8** @parser_strtok.p
store i8 0, i8* %29
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** @parser_strtok.p
%31 = load i8*, i8** @parser_strtok.pstr
br label %32
32: ; preds = %15, %28
%33 = phi i8* [ %31, %28 ], [ null, %15 ]
ret i8* %33
}