#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 strlen(char const *);
char *strstr(char *, char const *);
char *strmctok(char *origstr, const char *mc_delim) {
  static char *tok;
  static char *next;
  char *m;
  if (mc_delim == NULL)
    return NULL;
  tok = (origstr) ? origstr : next;
  if (tok == NULL)
    return NULL;
  m = strstr(tok, mc_delim);
  if (m) {
    next = m + strlen(mc_delim);
    *m = '\0';
  } else
    next = NULL;
  return tok;
}


x86 assembly (clang, -O0):
<strmctok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1148 <strmctok+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11f6 <strmctok+0xd6>
cmpq   $0x0,-0x10(%rbp)
je     1160 <strmctok+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    116b <strmctok+0x4b>
mov    0x2ed9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,0x2ec2(%rip)
cmpq   $0x0,0x2eba(%rip)
jne    1191 <strmctok+0x71>
movq   $0x0,-0x8(%rbp)
jmp    11f6 <strmctok+0xd6>
mov    0x2ea0(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e0 <strmctok+0xc0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2e6c(%rip)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11eb <strmctok+0xcb>
movq   $0x0,0x2e55(%rip)
mov    0x2e46(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmctok>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     117c <strmctok+0x5c>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    113c <strmctok+0x1c>
mov    0x2f04(%rip),%rbx
mov    %rbx,0x2ef5(%rip)
test   %rbx,%rbx
je     117c <strmctok+0x5c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1180 <strmctok+0x60>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %r15,%rax
mov    %rax,0x2ed1(%rip)
movb   $0x0,(%r15)
mov    0x2ebe(%rip),%rbx
jmp    118b <strmctok+0x6b>
xor    %ebx,%ebx
jmp    118b <strmctok+0x6b>
movq   $0x0,0x2eb5(%rip)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@strmctok.tok = internal global i8* null
@strmctok.next = internal global i8* null
define i8* @strmctok(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** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %38
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i8*, i8** %4
br label %17
15: ; preds = %10
%16 = load i8*, i8** @strmctok.next
br label %17
17: ; preds = %15, %13
%18 = phi i8* [ %14, %13 ], [ %16, %15 ]
store i8* %18, i8** @strmctok.tok
%19 = load i8*, i8** @strmctok.tok
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
store i8* null, i8** %3
br label %38
22: ; preds = %17
%23 = load i8*, i8** @strmctok.tok
%24 = load i8*, i8** %5
%25 = call i8* @strstr(i8* %23, i8* %24)
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %35
28: ; preds = %22
%29 = load i8*, i8** %6
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8* %33, i8** @strmctok.next
%34 = load i8*, i8** %6
store i8 0, i8* %34
br label %36
35: ; preds = %22
store i8* null, i8** @strmctok.next
br label %36
36: ; preds = %35, %28
%37 = load i8*, i8** @strmctok.tok
store i8* %37, i8** %3
br label %38
38: ; preds = %36, %21, %9
%39 = load i8*, i8** %3
ret i8* %39
}

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