#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*/ isspace(char const);
scalar_t__ strlen(char const *);
char *my_strtok(const char *string) {
  static const char *s;
  static enum {
    TOKEN_STATE_WORD_START,
    TOKEN_STATE_WORD,
    TOKEN_STATE_QUOTED_STING
  } token_state;
  static char token_buffer[512];
  static char *d;
  if (string) {
    s = string;
    token_state = TOKEN_STATE_WORD_START;
  }
  if (*s == 0) {
    return 0;
  }
  while (*s) {
    switch (token_state) {
    case TOKEN_STATE_WORD_START:
      if ((*s) == '"') {
        token_state = TOKEN_STATE_QUOTED_STING;
        d = token_buffer;
      } else if (!isspace(*s)) {
        token_state = TOKEN_STATE_WORD;
        d = token_buffer;
        *d++ = *s;
      }
      break;
    case TOKEN_STATE_WORD:
      if (isspace(*s)) {
        goto return_token;
      } else {
        *d++ = *s;
      }
      break;
    case TOKEN_STATE_QUOTED_STING:
      if (*s == '"') {
        goto return_token;
      } else {
        *d++ = *s;
      }
      break;
    }
    s++;
  }
return_token:
  *d = 0;
  if (strlen(s) > 0) {
    s++;
  }
  token_state = TOKEN_STATE_WORD_START;
  return token_buffer;
}


x86 assembly (clang, -O0):
<my_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114c <my_strtok+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,0x2efe(%rip)
movl   $0x0,0x2efc(%rip)
mov    0x2eed(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116c <my_strtok+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    1325 <my_strtok+0x205>
jmp    1171 <my_strtok+0x51>
mov    0x2ec8(%rip),%rax
cmpb   $0x0,(%rax)
je     12d9 <my_strtok+0x1b9>
mov    0x2ec1(%rip),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11b9 <my_strtok+0x99>
jmp    1197 <my_strtok+0x77>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1243 <my_strtok+0x123>
jmp    11a8 <my_strtok+0x88>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1285 <my_strtok+0x165>
jmp    12c2 <my_strtok+0x1a2>
mov    0x2e80(%rip),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11e9 <my_strtok+0xc9>
movl   $0x2,0x2e72(%rip)
lea    0x2e73(%rip),%rax
mov    %rax,0x306c(%rip)
jmp    123e <my_strtok+0x11e>
mov    0x2e50(%rip),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    1239 <my_strtok+0x119>
movl   $0x1,0x2e3d(%rip)
lea    0x2e3e(%rip),%rax
mov    %rax,0x3037(%rip)
mov    0x2e20(%rip),%rax
mov    (%rax),%cl
mov    0x3027(%rip),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x3019(%rip)
mov    %cl,(%rax)
jmp    123e <my_strtok+0x11e>
jmp    12c2 <my_strtok+0x1a2>
mov    0x2df6(%rip),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
je     1260 <my_strtok+0x140>
jmp    12de <my_strtok+0x1be>
mov    0x2dd9(%rip),%rax
mov    (%rax),%cl
mov    0x2fe0(%rip),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x2fd2(%rip)
mov    %cl,(%rax)
jmp    12c2 <my_strtok+0x1a2>
mov    0x2db4(%rip),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    129d <my_strtok+0x17d>
jmp    12de <my_strtok+0x1be>
mov    0x2d9c(%rip),%rax
mov    (%rax),%cl
mov    0x2fa3(%rip),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x2f95(%rip)
mov    %cl,(%rax)
jmp    12c2 <my_strtok+0x1a2>
mov    0x2d77(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2d6c(%rip)
jmp    1171 <my_strtok+0x51>
jmp    12de <my_strtok+0x1be>
mov    0x2f6b(%rip),%rax
movb   $0x0,(%rax)
mov    0x2d51(%rip),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    1310 <my_strtok+0x1f0>
mov    0x2d3b(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2d30(%rip)
movl   $0x0,0x2d2e(%rip)
lea    0x2d2f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strtok>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     113d <my_strtok+0x1d>
mov    %rdi,0x2f0f(%rip)
movl   $0x0,0x2f0d(%rip)
jmp    1144 <my_strtok+0x24>
mov    0x2efc(%rip),%rdi
mov    (%rdi),%al
test   %al,%al
je     1226 <my_strtok+0x106>
lea    0x2efb(%rip),%r14
lea    0x2ef5(%rip),%r15
jmp    1196 <my_strtok+0x76>
xchg   %ax,%ax
cmp    $0x22,%al
je     122b <my_strtok+0x10b>
mov    0x30e1(%rip),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x30d6(%rip)
mov    %al,(%rcx)
lea    0x1(%rdi),%rbx
mov    %rbx,0x2eb9(%rip)
movzbl 0x1(%rdi),%eax
mov    %rbx,%rdi
test   %al,%al
je     122e <my_strtok+0x10e>
mov    0x2eac(%rip),%ecx
cmp    $0x2,%ecx
je     1160 <my_strtok+0x40>
cmp    $0x1,%ecx
je     11d0 <my_strtok+0xb0>
test   %ecx,%ecx
jne    117c <my_strtok+0x5c>
cmp    $0x22,%al
jne    11e8 <my_strtok+0xc8>
movl   $0x2,0x2e90(%rip)
mov    %r14,0x3091(%rip)
jmp    117c <my_strtok+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <isspace@plt>
mov    0x2e61(%rip),%rdi
test   %eax,%eax
jne    122b <my_strtok+0x10b>
movzbl (%rdi),%eax
jmp    1168 <my_strtok+0x48>
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     1200 <my_strtok+0xe0>
mov    0x2e45(%rip),%rdi
jmp    117c <my_strtok+0x5c>
movl   $0x1,0x2e3e(%rip)
mov    0x2e2f(%rip),%rdi
movzbl (%rdi),%eax
mov    %r15,0x3035(%rip)
mov    %al,0x2e2f(%rip)
jmp    117c <my_strtok+0x5c>
xor    %r14d,%r14d
jmp    125a <my_strtok+0x13a>
mov    %rdi,%rbx
mov    0x301b(%rip),%rax
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    1250 <my_strtok+0x130>
add    $0x1,%rbx
mov    %rbx,0x2df0(%rip)
movl   $0x0,0x2dee(%rip)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@my_strtok.s = internal global i8* null
@my_strtok.token_state = internal global i32 0
@my_strtok.token_buffer = internal global [512 x i8] zeroinitializer
@my_strtok.d = internal global i8* null
define i8* @my_strtok(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i8*, i8** %3
store i8* %7, i8** @my_strtok.s
store i32 0, i32* @my_strtok.token_state
br label %8
8: ; preds = %6, %1
%9 = load i8*, i8** @my_strtok.s
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
store i8* null, i8** %2
br label %76
14: ; preds = %8
br label %15
15: ; preds = %63, %14
%16 = load i8*, i8** @my_strtok.s
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %66
19: ; preds = %15
%20 = load i32, i32* @my_strtok.token_state
switch i32 %20, label %63 [
i32 0, label %21
i32 1, label %39
i32 2, label %51
]
21: ; preds = %19
%22 = load i8*, i8** @my_strtok.s
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 34
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 2, i32* @my_strtok.token_state
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 0), i8** @my_strtok.d
br label %38
27: ; preds = %21
%28 = load i8*, i8** @my_strtok.s
%29 = load i8, i8* %28
%30 = call i32 @isspace(i8 signext %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %27
store i32 1, i32* @my_strtok.token_state
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 0), i8** @my_strtok.d
%33 = load i8*, i8** @my_strtok.s
%34 = load i8, i8* %33
%35 = load i8*, i8** @my_strtok.d
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** @my_strtok.d
store i8 %34, i8* %35
br label %37
37: ; preds = %32, %27
br label %38
38: ; preds = %37, %26
br label %63
39: ; preds = %19
%40 = load i8*, i8** @my_strtok.s
%41 = load i8, i8* %40
%42 = call i32 @isspace(i8 signext %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
br label %67
45: ; preds = %39
%46 = load i8*, i8** @my_strtok.s
%47 = load i8, i8* %46
%48 = load i8*, i8** @my_strtok.d
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** @my_strtok.d
store i8 %47, i8* %48
br label %50
50: ; preds = %45
br label %63
51: ; preds = %19
%52 = load i8*, i8** @my_strtok.s
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 34
br i1 %55, label %56, label %57
56: ; preds = %51
br label %67
57: ; preds = %51
%58 = load i8*, i8** @my_strtok.s
%59 = load i8, i8* %58
%60 = load i8*, i8** @my_strtok.d
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** @my_strtok.d
store i8 %59, i8* %60
br label %62
62: ; preds = %57
br label %63
63: ; preds = %19, %62, %50, %38
%64 = load i8*, i8** @my_strtok.s
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** @my_strtok.s
br label %15
66: ; preds = %15
br label %67
67: ; preds = %66, %56, %44
%68 = load i8*, i8** @my_strtok.d
store i8 0, i8* %68
%69 = load i8*, i8** @my_strtok.s
%70 = call i64 @strlen(i8* %69)
%71 = icmp sgt i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = load i8*, i8** @my_strtok.s
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** @my_strtok.s
br label %75
75: ; preds = %72, %67
store i32 0, i32* @my_strtok.token_state
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 0), i8** %2
br label %76
76: ; preds = %75, %13
%77 = load i8*, i8** %2
ret i8* %77
}

LLVM IR (-O2):
@my_strtok.s = internal unnamed_addr global i8* null
@my_strtok.token_state = internal unnamed_addr global i32 0
@my_strtok.token_buffer = internal global [512 x i8] zeroinitializer
@my_strtok.d = internal unnamed_addr global i8* null
define i8* @my_strtok(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = load i8*, i8** @my_strtok.s
br label %6
5: ; preds = %1
store i8* %0, i8** @my_strtok.s
store i32 0, i32* @my_strtok.token_state
br label %6
6: ; preds = %3, %5
%7 = phi i8* [ %4, %3 ], [ %0, %5 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %51, label %10
10: ; preds = %6, %38
%11 = phi i8* [ %40, %38 ], [ %7, %6 ]
%12 = phi i8 [ %41, %38 ], [ %8, %6 ]
%13 = load i32, i32* @my_strtok.token_state
switch i32 %13, label %38 [
i32 0, label %14
i32 1, label %25
i32 2, label %33
]
14: ; preds = %10
%15 = icmp eq i8 %12, 34
br i1 %15, label %16, label %17
16: ; preds = %14
store i32 2, i32* @my_strtok.token_state
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 0), i8** @my_strtok.d
br label %38
17: ; preds = %14
%18 = tail call i32 @isspace(i8 signext %12)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = load i8*, i8** @my_strtok.s
br label %38
22: ; preds = %17
store i32 1, i32* @my_strtok.token_state
%23 = load i8*, i8** @my_strtok.s
%24 = load i8, i8* %23
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 1), i8** @my_strtok.d
store i8 %24, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 0)
br label %38
25: ; preds = %10
%26 = tail call i32 @isspace(i8 signext %12)
%27 = icmp eq i32 %26, 0
%28 = load i8*, i8** @my_strtok.s
br i1 %27, label %29, label %43
29: ; preds = %25
%30 = load i8, i8* %28
%31 = load i8*, i8** @my_strtok.d
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** @my_strtok.d
store i8 %30, i8* %31
br label %38
33: ; preds = %10
%34 = icmp eq i8 %12, 34
br i1 %34, label %43, label %35
35: ; preds = %33
%36 = load i8*, i8** @my_strtok.d
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** @my_strtok.d
store i8 %12, i8* %36
br label %38
38: ; preds = %20, %16, %22, %10, %35, %29
%39 = phi i8* [ %21, %20 ], [ %11, %16 ], [ %23, %22 ], [ %11, %10 ], [ %11, %35 ], [ %28, %29 ]
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** @my_strtok.s
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %10
43: ; preds = %33, %38, %25
%44 = phi i8* [ %28, %25 ], [ %40, %38 ], [ %11, %33 ]
%45 = load i8*, i8** @my_strtok.d
store i8 0, i8* %45
%46 = tail call i64 @strlen(i8* dereferenceable(1) %44)
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = getelementptr inbounds i8, i8* %44, i64 1
store i8* %49, i8** @my_strtok.s
br label %50
50: ; preds = %48, %43
store i32 0, i32* @my_strtok.token_state
br label %51
51: ; preds = %6, %50
%52 = phi i8* [ getelementptr inbounds ([512 x i8], [512 x i8]* @my_strtok.token_buffer, i64 0, i64 0), %50 ], [ null, %6 ]
ret i8* %52
}