#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 */
size_t strcspn(char const *, char *);
scalar_t__ strncmp(char const *, char *, int);
size_t find_token_end(const char *s) {
  size_t l;
  char sep;
  if (strncmp(s, "::=", 3) == 0) {
    l = 3;
  } else if (*s == '\'' || *s == '\"') {
    sep = *s;
    l = 1;
    while (*(s + l) != sep)
      l += (*(s + l) == '\\') ? 2 : 1;
    if (*(s + l) != '\0')
      l++;
  } else if (*s == '|') {
    l = 1;
  } else if (*s == '<') {
    l = strcspn(s, ">");
    if (*(s + l) != '\0')
      l++;
  } else {
    l = strcspn(s, "< \t\n");
  }
  return l;
}


x86 assembly (clang, -O0):
<find_token_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec9(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1158 <find_token_end+0x38>
movq   $0x3,-0x10(%rbp)
jmp    127c <find_token_end+0x15c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
je     1178 <find_token_end+0x58>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11f2 <find_token_end+0xd2>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movq   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     11cc <find_token_end+0xac>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x5c,%edx
cmove  %ecx,%eax
cltq
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1189 <find_token_end+0x69>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ed <find_token_end+0xcd>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1277 <find_token_end+0x157>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7c,%eax
jne    120f <find_token_end+0xef>
movq   $0x1,-0x10(%rbp)
jmp    1272 <find_token_end+0x152>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    1259 <find_token_end+0x139>
mov    -0x8(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1254 <find_token_end+0x134>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    126d <find_token_end+0x14d>
mov    -0x8(%rbp),%rdi
lea    0xda2(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x10(%rbp)
jmp    1272 <find_token_end+0x152>
jmp    1277 <find_token_end+0x157>
jmp    127c <find_token_end+0x15c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_token_end>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1182 <find_token_end+0x62>
mov    (%rbx),%cl
cmp    $0x3b,%cl
jg     1189 <find_token_end+0x69>
cmp    $0x22,%cl
je     114b <find_token_end+0x2b>
cmp    $0x27,%cl
jne    119a <find_token_end+0x7a>
mov    0x1(%rbx),%dl
mov    $0x1,%eax
cmp    %cl,%dl
je     117d <find_token_end+0x5d>
mov    $0x1,%eax
nopl   0x0(%rax)
xor    %esi,%esi
cmp    $0x5c,%dl
sete   %sil
lea    (%rsi,%rax,1),%rdx
add    %rsi,%rax
add    $0x1,%rax
movzbl 0x1(%rbx,%rdx,1),%edx
cmp    %cl,%dl
jne    1160 <find_token_end+0x40>
cmp    $0x1,%cl
jmp    11bd <find_token_end+0x9d>
mov    $0x3,%eax
pop    %rbx
ret
cmp    $0x3c,%cl
je     11aa <find_token_end+0x8a>
mov    $0x1,%eax
cmp    $0x7c,%cl
jne    119a <find_token_end+0x7a>
pop    %rbx
ret
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <strcspn@plt>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
cmpb   $0x1,(%rbx,%rax,1)
sbb    $0xffffffffffffffff,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"::=\00"
@.str.1 = [2 x i8] c">\00"
@.str.2 = [5 x i8] c"< \09\0A\00"
define i64 @find_token_end(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 3, i64* %3
br label %84
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 39
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 34
br i1 %18, label %19, label %54
19: ; preds = %14, %9
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
store i8 %21, i8* %4
store i64 1, i64* %3
br label %22
22: ; preds = %31, %19
%23 = load i8*, i8** %2
%24 = load i64, i64* %3
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %43
31: ; preds = %22
%32 = load i8*, i8** %2
%33 = load i64, i64* %3
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 92
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 2, i32 1
%40 = sext i32 %39 to i64
%41 = load i64, i64* %3
%42 = add i64 %41, %40
store i64 %42, i64* %3
br label %22
43: ; preds = %22
%44 = load i8*, i8** %2
%45 = load i64, i64* %3
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = load i64, i64* %3
%52 = add i64 %51, 1
store i64 %52, i64* %3
br label %53
53: ; preds = %50, %43
br label %83
54: ; preds = %14
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 124
br i1 %58, label %59, label %60
59: ; preds = %54
store i64 1, i64* %3
br label %82
60: ; preds = %54
%61 = load i8*, i8** %2
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 60
br i1 %64, label %65, label %78
65: ; preds = %60
%66 = load i8*, i8** %2
%67 = call i64 @strcspn(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i64 %67, i64* %3
%68 = load i8*, i8** %2
%69 = load i64, i64* %3
%70 = getelementptr inbounds i8, i8* %68, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %65
%75 = load i64, i64* %3
%76 = add i64 %75, 1
store i64 %76, i64* %3
br label %77
77: ; preds = %74, %65
br label %81
78: ; preds = %60
%79 = load i8*, i8** %2
%80 = call i64 @strcspn(i8* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i64 %80, i64* %3
br label %81
81: ; preds = %78, %77
br label %82
82: ; preds = %81, %59
br label %83
83: ; preds = %82, %53
br label %84
84: ; preds = %83, %8
%85 = load i64, i64* %3
ret i64 %85
}

LLVM IR (-O2):
@.str = [4 x i8] c"::=\00"
@.str.1 = [2 x i8] c">\00"
@.str.2 = [5 x i8] c"< \09\0A\00"
define i64 @find_token_end(i8* %0) {
%2 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%3 = icmp eq i64 %2, 0
br i1 %3, label %33, label %4
4: ; preds = %1
%5 = load i8, i8* %0
switch i8 %5, label %31 [
i8 39, label %6
i8 34, label %6
i8 124, label %33
i8 60, label %24
]
6: ; preds = %4, %4
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, %5
br i1 %9, label %19, label %10
10: ; preds = %6, %10
%11 = phi i8 [ %17, %10 ], [ %8, %6 ]
%12 = phi i64 [ %15, %10 ], [ 1, %6 ]
%13 = icmp eq i8 %11, 92
%14 = select i1 %13, i64 2, i64 1
%15 = add i64 %14, %12
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, %5
br i1 %18, label %19, label %10
19: ; preds = %10, %6
%20 = phi i64 [ 1, %6 ], [ %15, %10 ]
%21 = icmp ne i8 %5, 0
%22 = zext i1 %21 to i64
%23 = add i64 %20, %22
br label %33
24: ; preds = %4
%25 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
%29 = zext i1 %28 to i64
%30 = add i64 %25, %29
br label %33
31: ; preds = %4
%32 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %24, %19, %4, %1, %31
%34 = phi i64 [ %32, %31 ], [ 3, %1 ], [ %23, %19 ], [ 1, %4 ], [ %30, %24 ]
ret i64 %34
}