#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 *strtokm(char *s1, const char *delims) {
  static char *last = NULL;
  char *endp;
  if (!s1)
    s1 = last;
  if (!s1 || *s1 == 0)
    return last = NULL;
  endp = strpbrk(s1, delims);
  if (endp) {
    *endp = '\0';
    last = endp + 1;
  } else
    last = NULL;
  return s1;
}


x86 assembly (clang, -O0):
<strtokm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1136 <strtokm+0x26>
mov    0x2efe(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1151 <strtokm+0x41>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1169 <strtokm+0x59>
movq   $0x0,0x2ed4(%rip)
movq   $0x0,-0x8(%rbp)
jmp    11b3 <strtokm+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strpbrk@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <strtokm+0x90>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e95(%rip)
jmp    11ab <strtokm+0x9b>
movq   $0x0,0x2e85(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtokm>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1120 <strtokm+0x10>
mov    0x2f10(%rip),%rbx
test   %rbx,%rbx
je     1140 <strtokm+0x30>
cmpb   $0x0,(%rbx)
je     1140 <strtokm+0x30>
mov    %rbx,%rdi
call   1030 <strpbrk@plt>
test   %rax,%rax
je     1146 <strtokm+0x36>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    1148 <strtokm+0x38>
xor    %eax,%eax
xor    %ebx,%ebx
jmp    1148 <strtokm+0x38>
xor    %eax,%eax
mov    %rax,0x2ee1(%rip)
mov    %rbx,%rax
pop    %rbx
ret

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

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