#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 */
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int __builtin_ffs(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmpeq_epi8(int /*<<< orphan*/ const,
                                  int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_movemask_epi8(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_epi8(char);
int /*<<< orphan*/ _mm_set_epi8(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/, char,
                                char, char, char, char, char);
__attribute__((always_)) int escaped_index(char ch) {
  const __m128i ch_mask = _mm_set1_epi8(ch);
  const __m128i escapable =
      _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '<', '>', '&', '"', '\'', '/');
  return __builtin_ffs(_mm_movemask_epi8(_mm_cmpeq_epi8(ch_mask, escapable)));
}


x86 assembly (clang, -O0):
<escaped_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <_mm_set1_epi8@plt>
mov    %eax,-0x8(%rbp)
xor    %r9d,%r9d
mov    %r9d,%edi
mov    %r9d,%esi
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x3c,0x20(%rsp)
movl   $0x3e,0x28(%rsp)
movl   $0x26,0x30(%rsp)
movl   $0x22,0x38(%rsp)
movl   $0x27,0x40(%rsp)
movl   $0x2f,0x48(%rsp)
call   1040 <_mm_set_epi8@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <_mm_cmpeq_epi8@plt>
mov    %eax,%edi
call   1050 <_mm_movemask_epi8@plt>
mov    %eax,%edx
bsf    %edx,%eax
add    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escaped_index>:
push   %rbx
call   1030 <_mm_set1_epi8@plt>
mov    %eax,%ebx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x2f
push   $0x27
push   $0x22
push   $0x26
push   $0x3e
push   $0x3c
push   $0x0
push   $0x0
push   $0x0
push   $0x0
call   1040 <_mm_set_epi8@plt>
add    $0x50,%rsp
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <_mm_cmpeq_epi8@plt>
mov    %eax,%edi
call   1050 <_mm_movemask_epi8@plt>
bsf    %eax,%ecx
mov    $0xffffffff,%eax
cmovne %ecx,%eax
add    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @escaped_index(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = call i32 @_mm_set1_epi8(i8 signext %5)
store i32 %6, i32* %3
%7 = call i32 @_mm_set_epi8(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i8 signext 60, i8 signext 62, i8 signext 38, i8 signext 34, i8 signext 39, i8 signext 47)
store i32 %7, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32 @_mm_cmpeq_epi8(i32 %8, i32 %9)
%11 = call i32 @_mm_movemask_epi8(i32 %10)
%12 = call i32 @llvm.cttz.i32(i32 %11, i1 true)
%13 = add i32 %12, 1
%14 = icmp eq i32 %11, 0
%15 = select i1 %14, i32 0, i32 %13
ret i32 %15
}

LLVM IR (-O2):
define i32 @escaped_index(i8 signext %0) {
%2 = tail call i32 @_mm_set1_epi8(i8 signext %0)
%3 = tail call i32 @_mm_set_epi8(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i8 signext 60, i8 signext 62, i8 signext 38, i8 signext 34, i8 signext 39, i8 signext 47)
%4 = tail call i32 @_mm_cmpeq_epi8(i32 %2, i32 %3)
%5 = tail call i32 @_mm_movemask_epi8(i32 %4)
%6 = tail call i32 @llvm.cttz.i32(i32 %5, i1 true)
%7 = add nuw nsw i32 %6, 1
%8 = icmp eq i32 %5, 0
%9 = select i1 %8, i32 0, i32 %7
ret i32 %9
}