char const *pbjson_find_end_primitive(char const *start, char const *end) {
  for (; start < end; ++start) {
    switch (*start) {
    case ' ':
    case '\t':
    case '\r':
    case '\n':
    case ',':
    case '}':
    case ']':
      return start - 1;
    case '\0':
      return start;
    default:
      break;
    }
  }
  return start;
}


x86 assembly (clang, -O0):
<pbjson_find_end_primitive>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d3 <pbjson_find_end_primitive+0xd3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11ab <pbjson_find_end_primitive+0xab>
jmp    1131 <pbjson_find_end_primitive+0x31>
mov    -0x1c(%rbp),%eax
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     119a <pbjson_find_end_primitive+0x9a>
jmp    1145 <pbjson_find_end_primitive+0x45>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     119a <pbjson_find_end_primitive+0x9a>
jmp    1156 <pbjson_find_end_primitive+0x56>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
je     119a <pbjson_find_end_primitive+0x9a>
jmp    1167 <pbjson_find_end_primitive+0x67>
mov    -0x1c(%rbp),%eax
sub    $0x2c,%eax
je     119a <pbjson_find_end_primitive+0x9a>
jmp    1178 <pbjson_find_end_primitive+0x78>
mov    -0x1c(%rbp),%eax
sub    $0x5d,%eax
je     119a <pbjson_find_end_primitive+0x9a>
jmp    1189 <pbjson_find_end_primitive+0x89>
mov    -0x1c(%rbp),%eax
sub    $0x7d,%eax
jne    11b8 <pbjson_find_end_primitive+0xb8>
jmp    119a <pbjson_find_end_primitive+0x9a>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    11db <pbjson_find_end_primitive+0xdb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11db <pbjson_find_end_primitive+0xdb>
jmp    11bd <pbjson_find_end_primitive+0xbd>
jmp    11c2 <pbjson_find_end_primitive+0xc2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    110c <pbjson_find_end_primitive+0xc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbjson_find_end_primitive>:
mov    %rdi,%rax
cmp    %rsi,%rdi
jae    1142 <pbjson_find_end_primitive+0x42>
mov    %rsi,%rcx
sub    %rax,%rcx
movabs $0x100100002600,%rdx
movsbl (%rax),%edi
cmp    $0x2c,%edi
ja     112b <pbjson_find_end_primitive+0x2b>
bt     %rdi,%rdx
jb     1143 <pbjson_find_end_primitive+0x43>
test   %rdi,%rdi
je     1142 <pbjson_find_end_primitive+0x42>
cmp    $0x7d,%edi
je     1143 <pbjson_find_end_primitive+0x43>
cmp    $0x5d,%edi
je     1143 <pbjson_find_end_primitive+0x43>
add    $0x1,%rax
add    $0xffffffffffffffff,%rcx
jne    1118 <pbjson_find_end_primitive+0x18>
mov    %rsi,%rax
ret
add    $0xffffffffffffffff,%rax
ret

LLVM IR (-O0):
define i8* @pbjson_find_end_primitive(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %6
6: ; preds = %21, %2
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = icmp ult i8* %7, %8
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %19 [
i32 32, label %14
i32 9, label %14
i32 13, label %14
i32 10, label %14
i32 44, label %14
i32 125, label %14
i32 93, label %14
i32 0, label %17
]
14: ; preds = %10, %10, %10, %10, %10, %10, %10
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %3
br label %26
17: ; preds = %10
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %26
19: ; preds = %10
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
br label %6
24: ; preds = %6
%25 = load i8*, i8** %4
store i8* %25, i8** %3
br label %26
26: ; preds = %24, %17, %14
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
define i8* @pbjson_find_end_primitive(i8* %0, i8* readnone %1) {
%3 = icmp ult i8* %0, %1
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = getelementptr i8, i8* %0, i64 %7
br label %9
9: ; preds = %4, %15
%10 = phi i8* [ %16, %15 ], [ %0, %4 ]
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %15 [
i32 32, label %13
i32 9, label %13
i32 13, label %13
i32 10, label %13
i32 44, label %13
i32 125, label %13
i32 93, label %13
i32 0, label %18
]
13: ; preds = %9, %9, %9, %9, %9, %9, %9
%14 = getelementptr inbounds i8, i8* %10, i64 -1
br label %18
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = icmp eq i8* %16, %8
br i1 %17, label %18, label %9
18: ; preds = %9, %15, %2, %13
%19 = phi i8* [ %14, %13 ], [ %0, %2 ], [ %10, %9 ], [ %8, %15 ]
ret i8* %19
}