#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 */
scalar_t__ isdigit(char);
int /*<<< orphan*/ isxdigit(char);
int /*<<< orphan*/ tolower(char);
int twiddler_escape_sequence(char *s, int *len) {
  int res = 0;
  *len = 0;
  if (isdigit(*s)) {
    while (isdigit(*s)) {
      res *= 8;
      res += *s - '0';
      s++;
      (*len)++;
      if (*len == 3)
        return res;
    }
    return res;
  }
  *len = 1;
  switch (*s) {
  case 'n':
    return '\n';
  case 'r':
    return '\r';
  case 'e':
    return '\e';
  case 't':
    return '\t';
  case 'a':
    return '\a';
  case 'b':
    return '\b';
  default:
    return *s;
  case 'x':
    (*len)++;
    s++;
    if (isdigit(*s))
      res = *s - '0';
    else
      res = tolower(*s) - 'a' + 10;
    s++;
    if (isxdigit(*s)) {
      (*len)++;
      res *= 16;
      if (isdigit(*s))
        res += *s - '0';
      else
        res += tolower(*s) - 'a' + 10;
    }
    return res;
  }
}


x86 assembly (clang, -O0):
<twiddler_escape_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11da <twiddler_escape_sequence+0xaa>
jmp    116c <twiddler_escape_sequence+0x3c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11cf <twiddler_escape_sequence+0x9f>
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x3,(%rax)
jne    11ca <twiddler_escape_sequence+0x9a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
jmp    116c <twiddler_escape_sequence+0x3c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x17,%eax
ja     1259 <twiddler_escape_sequence+0x129>
mov    -0x28(%rbp),%rax
lea    0xdf8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
movl   $0xd,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
movl   $0x1b,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
movl   $0x9,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
movl   $0x7,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
movl   $0x8,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <twiddler_escape_sequence+0x20f>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12a7 <twiddler_escape_sequence+0x177>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
jmp    12bc <twiddler_escape_sequence+0x18c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
je     1339 <twiddler_escape_sequence+0x209>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     131c <twiddler_escape_sequence+0x1ec>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1334 <twiddler_escape_sequence+0x204>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
sub    $0x61,%eax
add    $0xa,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1339 <twiddler_escape_sequence+0x209>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twiddler_escape_sequence>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
movl   $0x0,(%rsi)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1193 <twiddler_escape_sequence+0x63>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     118a <twiddler_escape_sequence+0x5a>
movsbl (%rbx),%eax
lea    (%rax,%r14,8),%r14d
add    $0xffffffd0,%r14d
add    $0x1,%rbx
mov    (%r15),%eax
add    $0x1,%eax
mov    %eax,(%r15)
cmp    $0x3,%eax
jne    1160 <twiddler_escape_sequence+0x30>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
movl   $0x1,(%r15)
movsbl (%rbx),%eax
lea    -0x61(%rax),%ecx
cmp    $0x17,%ecx
ja     11cb <twiddler_escape_sequence+0x9b>
mov    $0xa,%r14d
lea    0xe4e(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x7,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
mov    $0x8,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
mov    %eax,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
mov    $0x1b,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
mov    $0xd,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
mov    $0x9,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
movl   $0x2,(%r15)
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
movsbl 0x1(%rbx),%r14d
test   %rax,%rax
je     1208 <twiddler_escape_sequence+0xd8>
add    $0xffffffd0,%r14d
jmp    1217 <twiddler_escape_sequence+0xe7>
mov    %r14d,%edi
call   1040 <tolower@plt>
mov    %eax,%r14d
add    $0xffffffa9,%r14d
movsbl 0x2(%rbx),%edi
call   1050 <isxdigit@plt>
test   %eax,%eax
je     118a <twiddler_escape_sequence+0x5a>
addl   $0x1,(%r15)
shl    $0x4,%r14d
movsbl 0x2(%rbx),%edi
call   1030 <isdigit@plt>
movsbl 0x2(%rbx),%edi
test   %rax,%rax
je     124e <twiddler_escape_sequence+0x11e>
add    %edi,%r14d
add    $0xffffffd0,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>
call   1040 <tolower@plt>
add    %eax,%r14d
add    $0xffffffa9,%r14d
jmp    118a <twiddler_escape_sequence+0x5a>

LLVM IR (-O0):
define i32 @twiddler_escape_sequence(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%7 = load i32*, i32** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = call i64 @isdigit(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %40
12: ; preds = %2
br label %13
13: ; preds = %37, %12
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = call i64 @isdigit(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = load i32, i32* %6
%20 = mul nsw i32 %19, 8
store i32 %20, i32* %6
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
%25 = load i32, i32* %6
%26 = add nsw i32 %25, %24
store i32 %26, i32* %6
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 3
br i1 %34, label %35, label %37
35: ; preds = %18
%36 = load i32, i32* %6
store i32 %36, i32* %3
br label %111
37: ; preds = %18
br label %13
38: ; preds = %13
%39 = load i32, i32* %6
store i32 %39, i32* %3
br label %111
40: ; preds = %2
%41 = load i32*, i32** %5
store i32 1, i32* %41
%42 = load i8*, i8** %4
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
switch i32 %44, label %51 [
i32 110, label %45
i32 114, label %46
i32 101, label %47
i32 116, label %48
i32 97, label %49
i32 98, label %50
i32 120, label %55
]
45: ; preds = %40
store i32 10, i32* %3
br label %111
46: ; preds = %40
store i32 13, i32* %3
br label %111
47: ; preds = %40
store i32 27, i32* %3
br label %111
48: ; preds = %40
store i32 9, i32* %3
br label %111
49: ; preds = %40
store i32 7, i32* %3
br label %111
50: ; preds = %40
store i32 8, i32* %3
br label %111
51: ; preds = %40
%52 = load i8*, i8** %4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
store i32 %54, i32* %3
br label %111
55: ; preds = %40
%56 = load i32*, i32** %5
%57 = load i32, i32* %56
%58 = add nsw i32 %57, 1
store i32 %58, i32* %56
%59 = load i8*, i8** %4
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %4
%61 = load i8*, i8** %4
%62 = load i8, i8* %61
%63 = call i64 @isdigit(i8 signext %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %55
%66 = load i8*, i8** %4
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = sub nsw i32 %68, 48
store i32 %69, i32* %6
br label %76
70: ; preds = %55
%71 = load i8*, i8** %4
%72 = load i8, i8* %71
%73 = call i32 @tolower(i8 signext %72)
%74 = sub nsw i32 %73, 97
%75 = add nsw i32 %74, 10
store i32 %75, i32* %6
br label %76
76: ; preds = %70, %65
%77 = load i8*, i8** %4
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %4
%79 = load i8*, i8** %4
%80 = load i8, i8* %79
%81 = call i32 @isxdigit(i8 signext %80)
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %109
83: ; preds = %76
%84 = load i32*, i32** %5
%85 = load i32, i32* %84
%86 = add nsw i32 %85, 1
store i32 %86, i32* %84
%87 = load i32, i32* %6
%88 = mul nsw i32 %87, 16
store i32 %88, i32* %6
%89 = load i8*, i8** %4
%90 = load i8, i8* %89
%91 = call i64 @isdigit(i8 signext %90)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %100
93: ; preds = %83
%94 = load i8*, i8** %4
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = sub nsw i32 %96, 48
%98 = load i32, i32* %6
%99 = add nsw i32 %98, %97
store i32 %99, i32* %6
br label %108
100: ; preds = %83
%101 = load i8*, i8** %4
%102 = load i8, i8* %101
%103 = call i32 @tolower(i8 signext %102)
%104 = sub nsw i32 %103, 97
%105 = add nsw i32 %104, 10
%106 = load i32, i32* %6
%107 = add nsw i32 %106, %105
store i32 %107, i32* %6
br label %108
108: ; preds = %100, %93
br label %109
109: ; preds = %108, %76
%110 = load i32, i32* %6
store i32 %110, i32* %3
br label %111
111: ; preds = %109, %51, %50, %49, %48, %47, %46, %45, %38, %35
%112 = load i32, i32* %3
ret i32 %112
}

LLVM IR (-O2):
define i32 @twiddler_escape_sequence(i8* nocapture %0, i32* nocapture %1) {
store i32 0, i32* %1
%3 = load i8, i8* %0
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %2, %12
%7 = phi i8* [ %18, %12 ], [ %0, %2 ]
%8 = phi i32 [ %17, %12 ], [ 0, %2 ]
%9 = load i8, i8* %7
%10 = tail call i64 @isdigit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %65, label %12
12: ; preds = %6
%13 = shl nsw i32 %8, 3
%14 = load i8, i8* %7
%15 = sext i8 %14 to i32
%16 = add i32 %13, -48
%17 = add i32 %16, %15
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
%21 = icmp eq i32 %20, 3
br i1 %21, label %65, label %6
22: ; preds = %2
store i32 1, i32* %1
%23 = load i8, i8* %0
%24 = sext i8 %23 to i32
switch i32 %24, label %30 [
i32 110, label %65
i32 114, label %25
i32 101, label %26
i32 116, label %27
i32 97, label %28
i32 98, label %29
i32 120, label %31
]
25: ; preds = %22
br label %65
26: ; preds = %22
br label %65
27: ; preds = %22
br label %65
28: ; preds = %22
br label %65
29: ; preds = %22
br label %65
30: ; preds = %22
br label %65
31: ; preds = %22
store i32 2, i32* %1
%32 = getelementptr inbounds i8, i8* %0, i64 1
%33 = load i8, i8* %32
%34 = tail call i64 @isdigit(i8 signext %33)
%35 = icmp eq i64 %34, 0
%36 = load i8, i8* %32
br i1 %35, label %40, label %37
37: ; preds = %31
%38 = sext i8 %36 to i32
%39 = add nsw i32 %38, -48
br label %43
40: ; preds = %31
%41 = tail call i32 @tolower(i8 signext %36)
%42 = add nsw i32 %41, -87
br label %43
43: ; preds = %40, %37
%44 = phi i32 [ %39, %37 ], [ %42, %40 ]
%45 = getelementptr inbounds i8, i8* %0, i64 2
%46 = load i8, i8* %45
%47 = tail call i32 @isxdigit(i8 signext %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %65, label %49
49: ; preds = %43
%50 = load i32, i32* %1
%51 = add nsw i32 %50, 1
store i32 %51, i32* %1
%52 = shl nsw i32 %44, 4
%53 = load i8, i8* %45
%54 = tail call i64 @isdigit(i8 signext %53)
%55 = icmp eq i64 %54, 0
%56 = load i8, i8* %45
br i1 %55, label %61, label %57
57: ; preds = %49
%58 = sext i8 %56 to i32
%59 = add i32 %52, -48
%60 = add i32 %59, %58
br label %65
61: ; preds = %49
%62 = tail call i32 @tolower(i8 signext %56)
%63 = add i32 %52, -87
%64 = add i32 %63, %62
br label %65
65: ; preds = %6, %12, %43, %61, %57, %22, %30, %29, %28, %27, %26, %25
%66 = phi i32 [ %24, %30 ], [ 8, %29 ], [ 7, %28 ], [ 9, %27 ], [ 27, %26 ], [ 13, %25 ], [ 10, %22 ], [ %60, %57 ], [ %64, %61 ], [ %44, %43 ], [ %8, %6 ], [ %17, %12 ]
ret i32 %66
}