#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*/ is_hex_digit(char const);
int get_escape_len(const char *s, int len) {
  switch (*s) {
  case 'u':
    return len < 6 ? -2
           : is_hex_digit(s[1]) && is_hex_digit(s[2]) && is_hex_digit(s[3]) &&
                   is_hex_digit(s[4])
               ? 5
               : -1;
  case '"':
  case '\\':
  case '/':
  case 'b':
  case 'f':
  case 'n':
  case 'r':
  case 't':
    return len < 2 ? -2 : 1;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<get_escape_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x53,%eax
ja     120c <get_escape_len+0xfc>
mov    -0x20(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x6,-0x14(%rbp)
jge    1163 <get_escape_len+0x53>
mov    $0xfffffffe,%eax
mov    %eax,-0x24(%rbp)
jmp    11e6 <get_escape_len+0xd6>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <is_hex_digit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     11d0 <get_escape_len+0xc0>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <is_hex_digit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     11d0 <get_escape_len+0xc0>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <is_hex_digit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     11d0 <get_escape_len+0xc0>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%edi
call   1030 <is_hex_digit@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%dl
mov    $0xffffffff,%eax
mov    $0x5,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1213 <get_escape_len+0x103>
mov    -0x14(%rbp),%edx
mov    $0x1,%eax
mov    $0xfffffffe,%ecx
cmp    $0x2,%edx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1213 <get_escape_len+0x103>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_escape_len>:
push   %rbx
movsbl (%rdi),%eax
add    $0xffffffde,%eax
cmp    $0x53,%eax
ja     118f <get_escape_len+0x7f>
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    $0xffffffff,%eax
jmp    *%rdx
xor    %eax,%eax
cmp    $0x2,%esi
setge  %al
lea    (%rax,%rax,2),%eax
add    $0xfffffffe,%eax
pop    %rbx
ret
mov    $0xfffffffe,%eax
cmp    $0x6,%esi
jl     113f <get_escape_len+0x2f>
mov    %rdi,%rbx
movsbl 0x1(%rdi),%edi
call   1030 <is_hex_digit@plt>
test   %eax,%eax
je     118f <get_escape_len+0x7f>
movsbl 0x2(%rbx),%edi
call   1030 <is_hex_digit@plt>
test   %eax,%eax
je     118f <get_escape_len+0x7f>
movsbl 0x3(%rbx),%edi
call   1030 <is_hex_digit@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     113f <get_escape_len+0x2f>
movsbl 0x4(%rbx),%edi
call   1030 <is_hex_digit@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
or     $0x5,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_escape_len(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %48 [
i32 117, label %9
i32 34, label %43
i32 92, label %43
i32 47, label %43
i32 98, label %43
i32 102, label %43
i32 110, label %43
i32 114, label %43
i32 116, label %43
]
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 6
br i1 %11, label %12, label %13
12: ; preds = %9
br label %41
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = call i32 @is_hex_digit(i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 2
%22 = load i8, i8* %21
%23 = call i32 @is_hex_digit(i8 signext %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 3
%28 = load i8, i8* %27
%29 = call i32 @is_hex_digit(i8 signext %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 4
%34 = load i8, i8* %33
%35 = call i32 @is_hex_digit(i8 signext %34)
%36 = icmp ne i32 %35, 0
br label %37
37: ; preds = %31, %25, %19, %13
%38 = phi i1 [ false, %25 ], [ false, %19 ], [ false, %13 ], [ %36, %31 ]
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 5, i32 -1
br label %41
41: ; preds = %37, %12
%42 = phi i32 [ -2, %12 ], [ %40, %37 ]
store i32 %42, i32* %3
br label %49
43: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%44 = load i32, i32* %5
%45 = icmp slt i32 %44, 2
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 -2, i32 1
store i32 %47, i32* %3
br label %49
48: ; preds = %2
store i32 -1, i32* %3
br label %49
49: ; preds = %48, %43, %41
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
define i32 @get_escape_len(i8* nocapture %0, i32 %1) {
%3 = load i8, i8* %0
%4 = sext i8 %3 to i32
switch i32 %4, label %31 [
i32 117, label %5
i32 34, label %28
i32 92, label %28
i32 47, label %28
i32 98, label %28
i32 102, label %28
i32 110, label %28
i32 114, label %28
i32 116, label %28
]
5: ; preds = %2
%6 = icmp slt i32 %1, 6
br i1 %6, label %31, label %7
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = tail call i32 @is_hex_digit(i8 signext %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = tail call i32 @is_hex_digit(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %0, i64 3
%19 = load i8, i8* %18
%20 = tail call i32 @is_hex_digit(i8 signext %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %0, i64 4
%24 = load i8, i8* %23
%25 = tail call i32 @is_hex_digit(i8 signext %24)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 -1, i32 5
br label %31
28: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%29 = icmp sgt i32 %1, 1
%30 = select i1 %29, i32 1, i32 -2
br label %31
31: ; preds = %2, %5, %22, %17, %12, %7, %28
%32 = phi i32 [ %30, %28 ], [ -2, %5 ], [ -1, %17 ], [ -1, %12 ], [ -1, %7 ], [ %27, %22 ], [ -1, %2 ]
ret i32 %32
}