#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_oct_digit(char);
int parse_hex(char **);
int parse_oct(char **);
char toupper(char);
int escape(char **input) {
  int rval = 0;
  if (**input != '\\') {
    rval = **input;
    goto exit;
  }
  (*input)++;
  switch (toupper(**input)) {
  case '\0':
    rval = '\\';
    break;
  case 'B':
    rval = '\b';
    break;
  case 'F':
    rval = '\f';
    break;
  case 'N':
    rval = '\n';
    break;
  case 'R':
    rval = '\r';
    break;
  case 'S':
    rval = ' ';
    break;
  case 'T':
    rval = '\t';
    break;
  case 'E':
    rval = '\033';
    break;
  case '^':
    (*input)++;
    rval = toupper(**input) - '@';
    break;
  case 'X':
    (*input)++;
    rval = parse_hex(input);
    (*input)--;
    break;
  default:
    if (!is_oct_digit(**input)) {
      rval = **input;
    } else {
      rval = parse_oct(input);
      (*input)--;
    }
    break;
  }
exit:
  (*input)++;
  return rval;
}


x86 assembly (clang, -O0):
<escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     1178 <escape+0x38>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    12c1 <escape+0x181>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5e,%eax
ja     1273 <escape+0x133>
mov    -0x18(%rbp),%rax
lea    0xe4e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x5c,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0x8,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0xc,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0xa,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0xd,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0x20,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0x9,-0xc(%rbp)
jmp    12bc <escape+0x17c>
movl   $0x1b,-0xc(%rbp)
jmp    12bc <escape+0x17c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
sub    $0x40,%eax
mov    %eax,-0xc(%rbp)
jmp    12bc <escape+0x17c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <parse_hex@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
jmp    12bc <escape+0x17c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1050 <is_oct_digit@plt>
cmp    $0x0,%eax
jne    129d <escape+0x15d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    12b7 <escape+0x177>
mov    -0x8(%rbp),%rdi
call   1040 <parse_oct@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
jmp    12bc <escape+0x17c>
jmp    12c1 <escape+0x181>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rcx
movsbl (%rcx),%eax
cmp    $0x5c,%eax
jne    11fd <escape+0xbd>
lea    0x1(%rcx),%rax
mov    %rax,(%rbx)
movsbl 0x1(%rcx),%edi
call   1030 <toupper@plt>
movsbl %al,%ecx
cmp    $0x5e,%ecx
ja     1187 <escape+0x47>
mov    $0x5c,%eax
lea    0xe89(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x8,%eax
jmp    11fd <escape+0xbd>
mov    (%rbx),%rax
movsbl (%rax),%edi
call   1050 <is_oct_digit@plt>
test   %eax,%eax
je     11f7 <escape+0xb7>
mov    %rbx,%rdi
call   1040 <parse_oct@plt>
jmp    11d6 <escape+0x96>
mov    $0x1b,%eax
jmp    11fd <escape+0xbd>
mov    $0xc,%eax
jmp    11fd <escape+0xbd>
mov    $0xa,%eax
jmp    11fd <escape+0xbd>
mov    $0xd,%eax
jmp    11fd <escape+0xbd>
mov    $0x20,%eax
jmp    11fd <escape+0xbd>
mov    $0x9,%eax
jmp    11fd <escape+0xbd>
addq   $0x1,(%rbx)
mov    %rbx,%rdi
call   1060 <parse_hex@plt>
addq   $0xffffffffffffffff,(%rbx)
jmp    11fd <escape+0xbd>
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
add    $0xffffffc0,%eax
jmp    11fd <escape+0xbd>
mov    (%rbx),%rax
movsbl (%rax),%eax
addq   $0x1,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define i32 @escape(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %3
%4 = load i8**, i8*** %2
%5 = load i8*, i8** %4
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 92
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i8**, i8*** %2
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
store i32 %13, i32* %3
br label %69
14: ; preds = %1
%15 = load i8**, i8*** %2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %15
%18 = load i8**, i8*** %2
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = call signext i8 @toupper(i8 signext %20)
%22 = sext i8 %21 to i32
switch i32 %22, label %50 [
i32 0, label %23
i32 66, label %24
i32 70, label %25
i32 78, label %26
i32 82, label %27
i32 83, label %28
i32 84, label %29
i32 69, label %30
i32 94, label %31
i32 88, label %41
]
23: ; preds = %14
store i32 92, i32* %3
br label %68
24: ; preds = %14
store i32 8, i32* %3
br label %68
25: ; preds = %14
store i32 12, i32* %3
br label %68
26: ; preds = %14
store i32 10, i32* %3
br label %68
27: ; preds = %14
store i32 13, i32* %3
br label %68
28: ; preds = %14
store i32 32, i32* %3
br label %68
29: ; preds = %14
store i32 9, i32* %3
br label %68
30: ; preds = %14
store i32 27, i32* %3
br label %68
31: ; preds = %14
%32 = load i8**, i8*** %2
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %32
%35 = load i8**, i8*** %2
%36 = load i8*, i8** %35
%37 = load i8, i8* %36
%38 = call signext i8 @toupper(i8 signext %37)
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 64
store i32 %40, i32* %3
br label %68
41: ; preds = %14
%42 = load i8**, i8*** %2
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %42
%45 = load i8**, i8*** %2
%46 = call i32 @parse_hex(i8** %45)
store i32 %46, i32* %3
%47 = load i8**, i8*** %2
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i32 -1
store i8* %49, i8** %47
br label %68
50: ; preds = %14
%51 = load i8**, i8*** %2
%52 = load i8*, i8** %51
%53 = load i8, i8* %52
%54 = call i32 @is_oct_digit(i8 signext %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %50
%57 = load i8**, i8*** %2
%58 = load i8*, i8** %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
store i32 %60, i32* %3
br label %67
61: ; preds = %50
%62 = load i8**, i8*** %2
%63 = call i32 @parse_oct(i8** %62)
store i32 %63, i32* %3
%64 = load i8**, i8*** %2
%65 = load i8*, i8** %64
%66 = getelementptr inbounds i8, i8* %65, i32 -1
store i8* %66, i8** %64
br label %67
67: ; preds = %61, %56
br label %68
68: ; preds = %67, %41, %31, %30, %29, %28, %27, %26, %25, %24, %23
br label %69
69: ; preds = %68, %9
%70 = load i8**, i8*** %2
%71 = load i8*, i8** %70
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %70
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
define i32 @escape(i8** %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 92
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = sext i8 %3 to i32
br label %45
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %2, i64 1
store i8* %8, i8** %0
%9 = load i8, i8* %8
%10 = tail call signext i8 @toupper(i8 signext %9)
%11 = sext i8 %10 to i32
switch i32 %11, label %32 [
i32 0, label %45
i32 66, label %12
i32 70, label %13
i32 78, label %14
i32 82, label %15
i32 83, label %16
i32 84, label %17
i32 69, label %18
i32 94, label %19
i32 88, label %26
]
12: ; preds = %7
br label %45
13: ; preds = %7
br label %45
14: ; preds = %7
br label %45
15: ; preds = %7
br label %45
16: ; preds = %7
br label %45
17: ; preds = %7
br label %45
18: ; preds = %7
br label %45
19: ; preds = %7
%20 = load i8*, i8** %0
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %0
%22 = load i8, i8* %21
%23 = tail call signext i8 @toupper(i8 signext %22)
%24 = sext i8 %23 to i32
%25 = add nsw i32 %24, -64
br label %45
26: ; preds = %7
%27 = load i8*, i8** %0
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %0
%29 = tail call i32 @parse_hex(i8** %0)
%30 = load i8*, i8** %0
%31 = getelementptr inbounds i8, i8* %30, i64 -1
store i8* %31, i8** %0
br label %45
32: ; preds = %7
%33 = load i8*, i8** %0
%34 = load i8, i8* %33
%35 = tail call i32 @is_oct_digit(i8 signext %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i8*, i8** %0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
br label %45
41: ; preds = %32
%42 = tail call i32 @parse_oct(i8** %0)
%43 = load i8*, i8** %0
%44 = getelementptr inbounds i8, i8* %43, i64 -1
store i8* %44, i8** %0
br label %45
45: ; preds = %7, %12, %13, %14, %15, %16, %17, %18, %19, %26, %41, %37, %5
%46 = phi i32 [ %6, %5 ], [ %42, %41 ], [ %40, %37 ], [ %29, %26 ], [ %25, %19 ], [ 27, %18 ], [ 9, %17 ], [ 32, %16 ], [ 13, %15 ], [ 10, %14 ], [ 12, %13 ], [ 8, %12 ], [ 92, %7 ]
%47 = load i8*, i8** %0
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %0
ret i32 %46
}