char *expect_strtok(s, term)
char *s, *term;
{
  static char *str = "";
  int escape_flag = 0;
  char *result;
  if (s)
    str = s;
  if (*str)
    result = str;
  else
    result = (char *)0;
  while (*str) {
    if (escape_flag) {
      escape_flag = 0;
      ++str;
      continue;
    }
    if (*str == '\\') {
      ++str;
      escape_flag = 1;
      continue;
    }
    if (strchr(term, *str) == (char *)0) {
      ++str;
      continue;
    }
    *str++ = '\0';
    break;
  }
  return (result);
}


x86 assembly (clang, -O0):
<expect_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     113d <expect_strtok+0x2d>
mov    -0x8(%rbp),%rax
mov    %rax,0x2eeb(%rip)
mov    0x2ee4(%rip),%rax
cmpb   $0x0,(%rax)
je     115d <expect_strtok+0x4d>
mov    0x2ed4(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <expect_strtok+0x55>
movq   $0x0,-0x20(%rbp)
jmp    116a <expect_strtok+0x5a>
mov    0x2eb7(%rip),%rax
cmpb   $0x0,(%rax)
je     121f <expect_strtok+0x10f>
cmpl   $0x0,-0x14(%rbp)
je     11a2 <expect_strtok+0x92>
movl   $0x0,-0x14(%rbp)
mov    0x2e96(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e8b(%rip)
jmp    116a <expect_strtok+0x5a>
mov    0x2e7f(%rip),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11d3 <expect_strtok+0xc3>
mov    0x2e6c(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e61(%rip)
movl   $0x1,-0x14(%rbp)
jmp    116a <expect_strtok+0x5a>
mov    -0x10(%rbp),%rdi
mov    0x2e4a(%rip),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1207 <expect_strtok+0xf7>
mov    0x2e31(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e26(%rip)
jmp    116a <expect_strtok+0x5a>
mov    0x2e1a(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e0c(%rip)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect_strtok>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1129 <expect_strtok+0x19>
mov    %rdi,%r15
mov    %rdi,0x2f01(%rip)
jmp    1130 <expect_strtok+0x20>
mov    0x2ef8(%rip),%r15
mov    (%r15),%al
test   %al,%al
je     117e <expect_strtok+0x6e>
lea    0x1(%r15),%rbx
mov    $0x1,%cl
jmp    1154 <expect_strtok+0x44>
nop
xor    %ecx,%ecx
mov    %rbx,0x2edf(%rip)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1181 <expect_strtok+0x71>
test   $0x1,%cl
mov    $0x1,%cl
je     1142 <expect_strtok+0x32>
cmp    $0x5c,%al
je     1140 <expect_strtok+0x30>
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
mov    $0x1,%cl
test   %rax,%rax
je     1142 <expect_strtok+0x32>
mov    %rbx,0x2eb0(%rip)
movb   $0x0,-0x1(%rbx)
jmp    1181 <expect_strtok+0x71>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@expect_strtok.str = internal unnamed_addr global i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
@.str = [1 x i8] zeroinitializer
define i8* @expect_strtok(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i8*, i8** @expect_strtok.str
br label %7
6: ; preds = %2
store i8* %0, i8** @expect_strtok.str
br label %7
7: ; preds = %4, %6
%8 = phi i8* [ %5, %4 ], [ %0, %6 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %7, %15
%12 = phi i8 [ %18, %15 ], [ %9, %7 ]
%13 = phi i1 [ %16, %15 ], [ true, %7 ]
%14 = phi i8* [ %17, %15 ], [ %8, %7 ]
br i1 %13, label %20, label %15
15: ; preds = %22, %20, %11
%16 = phi i1 [ true, %11 ], [ false, %20 ], [ true, %22 ]
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %17, i8** @expect_strtok.str
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %28, label %11
20: ; preds = %11
%21 = icmp eq i8 %12, 92
br i1 %21, label %15, label %22
22: ; preds = %20
%23 = sext i8 %12 to i32
%24 = tail call i8* @strchr(i8* dereferenceable(1) %1, i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %15, label %26
26: ; preds = %22
%27 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %27, i8** @expect_strtok.str
store i8 0, i8* %14
br label %28
28: ; preds = %15, %7, %26
%29 = phi i8* [ null, %7 ], [ %8, %26 ], [ %8, %15 ]
ret i8* %29
}