#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 fail(char *, int);
void *getreg(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ report(int);
void recv_char(int ch) {
  unsigned x;
  char r;
  report(ch);
  while (!((x = getreg(((0x9c000000) + 5))) & (0x01)))
    ;
  if ((x & ((0x10) | (0x08) | (0x04) | (0x02))) && !(x & (0x80)))
    printf("LSR7 (0x%02x) ERR @ recv_char\n", x);
  ((!(x & (0x80))) ? 1 : fail("?", 126));
  printf("expected %02x, read %02x\n", ch, r = getreg(((0x9c000000) + 0)));
  ((r == ch) ? 1 : fail("?", 129));
}


x86 assembly (clang, -O0):
<recv_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <report@plt>
mov    $0x9c000005,%edi
call   1050 <getreg@plt>
mov    %eax,-0x8(%rbp)
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1178 <recv_char+0x38>
jmp    117d <recv_char+0x3d>
jmp    1153 <recv_char+0x13>
mov    -0x8(%rbp),%eax
and    $0x1e,%eax
cmp    $0x0,%eax
je     11ae <recv_char+0x6e>
mov    -0x8(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11ae <recv_char+0x6e>
mov    -0x8(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11c4 <recv_char+0x84>
jmp    11d5 <recv_char+0x95>
lea    0xe54(%rip),%rdi
mov    $0x7e,%esi
call   1030 <fail@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x9c000000,%edi
call   1050 <getreg@plt>
mov    -0x10(%rbp),%esi
mov    %al,-0x9(%rbp)
movsbl %al,%edx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    120e <recv_char+0xce>
jmp    121f <recv_char+0xdf>
lea    0xe0a(%rip),%rdi
mov    $0x81,%esi
call   1030 <fail@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_char>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1060 <report@plt>
nopw   0x0(%rax,%rax,1)
mov    $0x9c000005,%edi
call   1050 <getreg@plt>
mov    %rax,%rbx
test   $0x1,%bl
je     1150 <recv_char+0x10>
test   $0x1e,%bl
je     1180 <recv_char+0x40>
mov    %ebx,%eax
and    $0x80,%eax
jne    1180 <recv_char+0x40>
lea    0xe89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x80,%bl
je     1196 <recv_char+0x56>
lea    0xe93(%rip),%rdi
mov    $0x7e,%esi
call   1030 <fail@plt>
mov    $0x9c000000,%edi
call   1050 <getreg@plt>
movsbl %al,%ebx
lea    0xe77(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%ebx
jne    11c0 <recv_char+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe58(%rip),%rdi
mov    $0x81,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fail@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"LSR7 (0x%02x) ERR @ recv_char\0A\00"
@.str.1 = [2 x i8] c"?\00"
@.str.2 = [26 x i8] c"expected %02x, read %02x\0A\00"
define void @recv_char(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @report(i32 %5)
br label %7
7: ; preds = %13, %1
%8 = call i8* @getreg(i32 -1677721595)
%9 = ptrtoint i8* %8 to i32
store i32 %9, i32* %3
%10 = and i32 %9, 1
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %14
13: ; preds = %7
br label %7
14: ; preds = %7
%15 = load i32, i32* %3
%16 = and i32 %15, 30
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %3
%20 = and i32 %19, 128
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %3
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %18, %14
%26 = load i32, i32* %3
%27 = and i32 %26, 128
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25
br label %32
30: ; preds = %25
%31 = call i32 @fail(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 126)
br label %32
32: ; preds = %30, %29
%33 = phi i32 [ 1, %29 ], [ %31, %30 ]
%34 = load i32, i32* %2
%35 = call i8* @getreg(i32 -1677721600)
%36 = ptrtoint i8* %35 to i8
store i8 %36, i8* %4
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %37)
%39 = load i8, i8* %4
%40 = sext i8 %39 to i32
%41 = load i32, i32* %2
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %32
br label %46
44: ; preds = %32
%45 = call i32 @fail(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %46
46: ; preds = %44, %43
%47 = phi i32 [ 1, %43 ], [ %45, %44 ]
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"LSR7 (0x%02x) ERR @ recv_char\0A\00"
@.str.1 = [2 x i8] c"?\00"
@.str.2 = [26 x i8] c"expected %02x, read %02x\0A\00"
define void @recv_char(i32 %0) {
%2 = tail call i32 @report(i32 %0)
br label %3
3: ; preds = %3, %1
%4 = tail call i8* @getreg(i32 -1677721595)
%5 = ptrtoint i8* %4 to i64
%6 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = ptrtoint i8* %4 to i64
%10 = trunc i64 %9 to i32
%11 = and i32 %10, 30
%12 = icmp ne i32 %11, 0
%13 = and i32 %10, 128
%14 = icmp eq i32 %13, 0
%15 = and i1 %12, %14
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %18
18: ; preds = %16, %8
br i1 %14, label %21, label %19
19: ; preds = %18
%20 = tail call i32 @fail(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 126)
br label %21
21: ; preds = %18, %19
%22 = tail call i8* @getreg(i32 -1677721600)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i32
%25 = shl i32 %24, 24
%26 = ashr exact i32 %25, 24
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %26)
%28 = icmp eq i32 %26, %0
br i1 %28, label %31, label %29
29: ; preds = %21
%30 = tail call i32 @fail(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %31
31: ; preds = %21, %29
ret void
}