#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*/ assert(int);
int InputUnescape(int in, unsigned char *state) {
  assert((*state < 3) && (*state >= 0));
  if (in == -1)
    return -1;
  int ret = in;
  if (*state == 0) {
    if (in == 27) {
      *state = 1;
      ret = -1;
    }
  } else if (*state == 1) {
    if (in == '[') {
      *state = 2;
      ret = -1;
    } else {
      *state = 0;
    }
  } else if (*state == 2) {
    ret = in << 8;
    *state = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<InputUnescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x3,%ecx
mov    %al,-0x15(%rbp)
jge    1144 <InputUnescape+0x34>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
setge  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1167 <InputUnescape+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <InputUnescape+0xf3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    119a <InputUnescape+0x8a>
cmpl   $0x1b,-0x8(%rbp)
jne    1195 <InputUnescape+0x85>
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
movl   $0xffffffff,-0x14(%rbp)
jmp    11fd <InputUnescape+0xed>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
jne    11d3 <InputUnescape+0xc3>
cmpl   $0x5b,-0x8(%rbp)
jne    11c7 <InputUnescape+0xb7>
mov    -0x10(%rbp),%rax
movb   $0x2,(%rax)
movl   $0xffffffff,-0x14(%rbp)
jmp    11ce <InputUnescape+0xbe>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11f8 <InputUnescape+0xe8>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2,%eax
jne    11f3 <InputUnescape+0xe3>
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11f8 <InputUnescape+0xe8>
jmp    11fd <InputUnescape+0xed>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InputUnescape>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
cmpb   $0x3,(%rsi)
setb   %dil
call   1030 <assert@plt>
cmp    $0xffffffff,%ebx
je     1149 <InputUnescape+0x39>
mov    (%r14),%al
cmp    $0x2,%al
je     1150 <InputUnescape+0x40>
cmp    $0x1,%al
je     1157 <InputUnescape+0x47>
test   %al,%al
jne    116a <InputUnescape+0x5a>
cmp    $0x1b,%ebx
jne    116a <InputUnescape+0x5a>
mov    $0xffffffff,%ebx
mov    $0x1,%al
jmp    1167 <InputUnescape+0x57>
mov    $0xffffffff,%ebx
jmp    116a <InputUnescape+0x5a>
shl    $0x8,%ebx
xor    %eax,%eax
jmp    1167 <InputUnescape+0x57>
cmp    $0x5b,%ebx
sete   %al
mov    $0xffffffff,%ecx
cmove  %ecx,%ebx
add    %al,%al
mov    %al,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @InputUnescape(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp sge i32 %14, 0
br label %16
16: ; preds = %11, %2
%17 = phi i1 [ false, %2 ], [ %15, %11 ]
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -1, i32* %3
br label %61
23: ; preds = %16
%24 = load i32, i32* %4
store i32 %24, i32* %6
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 27
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i8*, i8** %5
store i8 1, i8* %33
store i32 -1, i32* %6
br label %34
34: ; preds = %32, %29
br label %59
35: ; preds = %23
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %48
40: ; preds = %35
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 91
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i8*, i8** %5
store i8 2, i8* %44
store i32 -1, i32* %6
br label %47
45: ; preds = %40
%46 = load i8*, i8** %5
store i8 0, i8* %46
br label %47
47: ; preds = %45, %43
br label %58
48: ; preds = %35
%49 = load i8*, i8** %5
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp eq i32 %51, 2
br i1 %52, label %53, label %57
53: ; preds = %48
%54 = load i32, i32* %4
%55 = shl i32 %54, 8
store i32 %55, i32* %6
%56 = load i8*, i8** %5
store i8 0, i8* %56
br label %57
57: ; preds = %53, %48
br label %58
58: ; preds = %57, %47
br label %59
59: ; preds = %58, %34
%60 = load i32, i32* %6
store i32 %60, i32* %3
br label %61
61: ; preds = %59, %22
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
define i32 @InputUnescape(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp ult i8 %3, 3
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp eq i32 %0, -1
br i1 %7, label %21, label %8
8: ; preds = %2
%9 = load i8, i8* %1
switch i8 %9, label %21 [
i8 0, label %10
i8 1, label %12
i8 2, label %16
]
10: ; preds = %8
%11 = icmp eq i32 %0, 27
br i1 %11, label %18, label %21
12: ; preds = %8
%13 = icmp eq i32 %0, 91
%14 = select i1 %13, i8 2, i8 0
%15 = select i1 %13, i32 -1, i32 %0
br label %18
16: ; preds = %8
%17 = shl i32 %0, 8
br label %18
18: ; preds = %12, %10, %16
%19 = phi i8 [ 0, %16 ], [ 1, %10 ], [ %14, %12 ]
%20 = phi i32 [ %17, %16 ], [ -1, %10 ], [ %15, %12 ]
store i8 %19, i8* %1
br label %21
21: ; preds = %18, %10, %8, %2
%22 = phi i32 [ -1, %2 ], [ %0, %10 ], [ %0, %8 ], [ %20, %18 ]
ret i32 %22
}