#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 Serial_read_byte_blocking();
int recv_byte_unescape() {
  int val;
  val = Serial_read_byte_blocking();
  if (val == 0x55)
    return 0x100;
  else if (val == 0xAA) {
    int second_char = Serial_read_byte_blocking();
    if (second_char == -1)
      return -1;
    else if (second_char == 0x01)
      return 0x55;
    else if (second_char == 0x02)
      return 0xAA;
    else
      return -1;
  } else
    return val;
}


x86 assembly (clang, -O0):
<recv_byte_unescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <Serial_read_byte_blocking@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x55,-0x8(%rbp)
jne    1138 <recv_byte_unescape+0x28>
movl   $0x100,-0x4(%rbp)
jmp    11a3 <recv_byte_unescape+0x93>
cmpl   $0xaa,-0x8(%rbp)
jne    119d <recv_byte_unescape+0x8d>
mov    $0x0,%al
call   1030 <Serial_read_byte_blocking@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1165 <recv_byte_unescape+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <recv_byte_unescape+0x93>
cmpl   $0x1,-0xc(%rbp)
jne    117b <recv_byte_unescape+0x6b>
movl   $0x55,-0x4(%rbp)
jmp    11a3 <recv_byte_unescape+0x93>
cmpl   $0x2,-0xc(%rbp)
jne    1191 <recv_byte_unescape+0x81>
movl   $0xaa,-0x4(%rbp)
jmp    11a3 <recv_byte_unescape+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <recv_byte_unescape+0x93>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_byte_unescape>:
push   %rax
xor    %eax,%eax
call   1030 <Serial_read_byte_blocking@plt>
cmp    $0x55,%eax
je     1148 <recv_byte_unescape+0x38>
cmp    $0xaa,%eax
jne    1146 <recv_byte_unescape+0x36>
xor    %eax,%eax
call   1030 <Serial_read_byte_blocking@plt>
cmp    $0x1,%eax
mov    $0x55,%ecx
mov    $0xffffffff,%edx
cmove  %ecx,%edx
cmp    $0x2,%eax
mov    $0xaa,%eax
cmovne %edx,%eax
pop    %rcx
ret
mov    $0x100,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @recv_byte_unescape() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @Serial_read_byte_blocking()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 85
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 256, i32* %1
br label %27
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 170
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = call i32 (...) @Serial_read_byte_blocking()
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %1
br label %27
16: ; preds = %11
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 85, i32* %1
br label %27
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 170, i32* %1
br label %27
24: ; preds = %20
store i32 -1, i32* %1
br label %27
25: ; preds = %8
%26 = load i32, i32* %2
store i32 %26, i32* %1
br label %27
27: ; preds = %25, %24, %23, %19, %15, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
define i32 @recv_byte_unescape() {
%1 = tail call i32 (...) @Serial_read_byte_blocking()
switch i32 %1, label %8 [
i32 85, label %9
i32 170, label %2
]
2: ; preds = %0
%3 = tail call i32 (...) @Serial_read_byte_blocking()
%4 = icmp eq i32 %3, 1
%5 = select i1 %4, i32 85, i32 -1
%6 = icmp eq i32 %3, 2
%7 = select i1 %6, i32 170, i32 %5
br label %9
8: ; preds = %0
br label %9
9: ; preds = %2, %0, %8
%10 = phi i32 [ %1, %8 ], [ 256, %0 ], [ %7, %2 ]
ret i32 %10
}