#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 /*<<< orphan*/ skipNextComma(char **);
int /*<<< orphan*/ skipWhiteSpace(char **);
char *strsep(char **, char *);
char *nextTok(char **p_cur) {
  char *ret = NULL;
  skipWhiteSpace(p_cur);
  if (*p_cur == NULL) {
    ret = NULL;
  } else if (**p_cur == '"') {
    enum State { END, NORMAL, ESCAPE } state = NORMAL;
    (*p_cur)++;
    ret = *p_cur;
    while (state != END) {
      switch (state) {
      case NORMAL:
        switch (**p_cur) {
        case '\\':
          state = ESCAPE;
          break;
        case '"':
          state = END;
          break;
        case '\0':
          ret = NULL;
          goto exit;
        default:
          break;
        }
        break;
      case ESCAPE:
        state = NORMAL;
        break;
      default:
        break;
      }
      if (state == END) {
        **p_cur = '\0';
      }
      (*p_cur)++;
    }
    skipNextComma(p_cur);
  } else {
    ret = strsep(p_cur, ",");
  }
exit:
  return ret;
}


x86 assembly (clang, -O0):
<nextTok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skipWhiteSpace@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1168 <nextTok+0x38>
movq   $0x0,-0x10(%rbp)
jmp    1294 <nextTok+0x164>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    127b <nextTok+0x14b>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     126d <nextTok+0x13d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     11ca <nextTok+0x9a>
jmp    11b9 <nextTok+0x89>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     1235 <nextTok+0x105>
jmp    1241 <nextTok+0x111>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     121e <nextTok+0xee>
jmp    11e4 <nextTok+0xb4>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     1212 <nextTok+0xe2>
jmp    11f5 <nextTok+0xc5>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
jne    122b <nextTok+0xfb>
jmp    1206 <nextTok+0xd6>
movl   $0x2,-0x14(%rbp)
jmp    1230 <nextTok+0x100>
movl   $0x0,-0x14(%rbp)
jmp    1230 <nextTok+0x100>
movq   $0x0,-0x10(%rbp)
jmp    1299 <nextTok+0x169>
jmp    1230 <nextTok+0x100>
jmp    1246 <nextTok+0x116>
movl   $0x1,-0x14(%rbp)
jmp    1246 <nextTok+0x116>
jmp    1246 <nextTok+0x116>
cmpl   $0x0,-0x14(%rbp)
jne    125a <nextTok+0x12a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    119b <nextTok+0x6b>
mov    -0x8(%rbp),%rdi
call   1050 <skipNextComma@plt>
jmp    128f <nextTok+0x15f>
mov    -0x8(%rbp),%rdi
lea    0xd7a(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x10(%rbp)
jmp    1294 <nextTok+0x164>
jmp    1299 <nextTok+0x169>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextTok>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <skipWhiteSpace@plt>
mov    (%rbx),%r14
test   %r14,%r14
je     11b1 <nextTok+0x81>
cmpb   $0x22,(%r14)
jne    11b6 <nextTok+0x86>
add    $0x1,%r14
mov    $0x1,%ecx
mov    %r14,%rax
jmp    1169 <nextTok+0x39>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%ecx
add    $0x1,%rax
mov    %rax,(%rbx)
cmp    $0x1,%ecx
je     1180 <nextTok+0x50>
cmp    $0x2,%ecx
je     1160 <nextTok+0x30>
test   %ecx,%ecx
jne    11a0 <nextTok+0x70>
jmp    11cc <nextTok+0x9c>
nopl   0x0(%rax)
movsbl (%rax),%edx
cmp    $0x22,%edx
je     1198 <nextTok+0x68>
cmp    $0x5c,%edx
je     11a6 <nextTok+0x76>
mov    $0x1,%ecx
test   %edx,%edx
jne    11a0 <nextTok+0x70>
jmp    11b1 <nextTok+0x81>
movb   $0x0,(%rax)
mov    (%rbx),%rax
xor    %ecx,%ecx
add    $0x1,%rax
jmp    1169 <nextTok+0x39>
mov    $0x2,%ecx
add    $0x1,%rax
jmp    1169 <nextTok+0x39>
xor    %r14d,%r14d
jmp    11d4 <nextTok+0xa4>
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strsep@plt>
mov    %rbx,%rdi
call   1050 <skipNextComma@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i8* @nextTok(i8** %0) {
%2 = tail call i32 @skipWhiteSpace(i8** %0)
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %28, label %5
5: ; preds = %1
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 34
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %3, i64 1
br label %10
10: ; preds = %20, %8
%11 = phi i8* [ %9, %8 ], [ %23, %20 ]
%12 = phi i32 [ 1, %8 ], [ %22, %20 ]
store i8* %11, i8** %0
switch i32 %12, label %20 [
i32 0, label %24
i32 1, label %13
i32 2, label %17
]
13: ; preds = %10
%14 = load i8, i8* %11
%15 = sext i8 %14 to i32
switch i32 %15, label %20 [
i32 92, label %16
i32 34, label %18
i32 0, label %28
]
16: ; preds = %13
br label %20
17: ; preds = %10
br label %20
18: ; preds = %13
store i8 0, i8* %11
%19 = load i8*, i8** %0
br label %20
20: ; preds = %10, %16, %13, %17, %18
%21 = phi i8* [ %19, %18 ], [ %11, %10 ], [ %11, %16 ], [ %11, %13 ], [ %11, %17 ]
%22 = phi i32 [ 0, %18 ], [ %12, %10 ], [ 2, %16 ], [ 1, %13 ], [ 1, %17 ]
%23 = getelementptr inbounds i8, i8* %21, i64 1
br label %10
24: ; preds = %10
%25 = tail call i32 @skipNextComma(i8** %0)
br label %28
26: ; preds = %5
%27 = tail call i8* @strsep(i8** %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %13, %24, %26, %1
%29 = phi i8* [ %27, %26 ], [ null, %1 ], [ %9, %24 ], [ null, %13 ]
ret i8* %29
}