#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 EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ putchar(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ sysfsgpio_read();
int /*<<< orphan*/ sysfsgpio_reset(int, char);
int /*<<< orphan*/ sysfsgpio_write(int, int, char);
void process_remote_protocol(void) {
  int c;
  while (1) {
    c = getchar();
    if (c == EOF || c == 'Q')
      break;
    else if (c == 'b' || c == 'B')
      continue;
    else if (c >= 'r' && c <= 'r' + 2) {
      char d = c - 'r';
      sysfsgpio_reset(!!(d & 2), (d & 1));
    } else if (c >= '0' && c <= '0' + 7) {
      char d = c - '0';
      sysfsgpio_write(!!(d & 4), !!(d & 2), (d & 1));
    } else if (c == 'R')
      putchar(sysfsgpio_read());
    else
      do {
        fprintf(stderr, "Unknown command '%c' received", c);
        fputc('\n', stderr);
      } while (0);
  }
}


x86 assembly (clang, -O0):
<process_remote_protocol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
je     119e <process_remote_protocol+0x2e>
cmpl   $0x51,-0x4(%rbp)
jne    11a3 <process_remote_protocol+0x33>
jmp    12cb <process_remote_protocol+0x15b>
cmpl   $0x62,-0x4(%rbp)
je     11b7 <process_remote_protocol+0x47>
cmpl   $0x42,-0x4(%rbp)
jne    11bc <process_remote_protocol+0x4c>
jmp    1178 <process_remote_protocol+0x8>
cmpl   $0x72,-0x4(%rbp)
jl     1203 <process_remote_protocol+0x93>
cmpl   $0x74,-0x4(%rbp)
jg     1203 <process_remote_protocol+0x93>
mov    -0x4(%rbp),%eax
sub    $0x72,%eax
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
movsbl -0x5(%rbp),%eax
and    $0x1,%eax
movsbl %al,%esi
call   1090 <sysfsgpio_reset@plt>
jmp    12bc <process_remote_protocol+0x14c>
cmpl   $0x30,-0x4(%rbp)
jl     1260 <process_remote_protocol+0xf0>
cmpl   $0x37,-0x4(%rbp)
jg     1260 <process_remote_protocol+0xf0>
mov    -0x4(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x6(%rbp)
movsbl -0x6(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
movsbl -0x6(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
movsbl -0x6(%rbp),%eax
and    $0x1,%eax
movsbl %al,%edx
call   1040 <sysfsgpio_write@plt>
jmp    12b7 <process_remote_protocol+0x147>
cmpl   $0x52,-0x4(%rbp)
jne    127d <process_remote_protocol+0x10d>
mov    $0x0,%al
call   1050 <sysfsgpio_read@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    12b2 <process_remote_protocol+0x142>
jmp    1282 <process_remote_protocol+0x112>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xd6b(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
jmp    12b2 <process_remote_protocol+0x142>
jmp    12b7 <process_remote_protocol+0x147>
jmp    12bc <process_remote_protocol+0x14c>
jmp    12c1 <process_remote_protocol+0x151>
jmp    12c6 <process_remote_protocol+0x156>
jmp    1178 <process_remote_protocol+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_remote_protocol>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x51,%eax
je     1254 <process_remote_protocol+0xe4>
mov    0x2e5c(%rip),%rbx
cmp    (%rbx),%eax
je     1254 <process_remote_protocol+0xe4>
mov    0x2e3d(%rip),%r15
lea    0xe5e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ecx
and    $0xffffffdf,%ecx
cmp    $0x42,%ecx
je     1240 <process_remote_protocol+0xd0>
lea    -0x72(%rax),%ecx
cmp    $0x2,%ecx
ja     11e0 <process_remote_protocol+0x70>
lea    0x2(%rax),%edi
shr    %edi
and    $0x1,%edi
and    $0x1,%eax
mov    %eax,%esi
call   1090 <sysfsgpio_reset@plt>
jmp    1240 <process_remote_protocol+0xd0>
nopw   0x0(%rax,%rax,1)
mov    %eax,%ecx
and    $0xfffffff8,%ecx
cmp    $0x30,%ecx
jne    1205 <process_remote_protocol+0x95>
mov    %eax,%edi
shr    $0x2,%edi
and    $0x1,%edi
mov    %eax,%esi
shr    %esi
and    $0x1,%esi
and    $0x1,%eax
mov    %eax,%edx
call   1040 <sysfsgpio_write@plt>
jmp    1240 <process_remote_protocol+0xd0>
cmp    $0x52,%eax
jne    121a <process_remote_protocol+0xaa>
xor    %eax,%eax
call   1050 <sysfsgpio_read@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1240 <process_remote_protocol+0xd0>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1080 <fprintf@plt>
mov    (%r15),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x51,%eax
je     1254 <process_remote_protocol+0xe4>
cmp    (%rbx),%eax
jne    11b0 <process_remote_protocol+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Unknown command '%c' received\00"
define void @process_remote_protocol() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
br label %4
4: ; preds = %0, %19, %89
%5 = call i32 (...) @getchar()
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 81
br i1 %11, label %12, label %13
12: ; preds = %9, %4
br label %90
13: ; preds = %9
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 98
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 66
br i1 %18, label %19, label %20
19: ; preds = %16, %13
br label %4
20: ; preds = %16
%21 = load i32, i32* %1
%22 = icmp sge i32 %21, 114
br i1 %22, label %23, label %42
23: ; preds = %20
%24 = load i32, i32* %1
%25 = icmp sle i32 %24, 116
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = load i32, i32* %1
%28 = sub nsw i32 %27, 114
%29 = trunc i32 %28 to i8
store i8 %29, i8* %2
%30 = load i8, i8* %2
%31 = sext i8 %30 to i32
%32 = and i32 %31, 2
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
%37 = load i8, i8* %2
%38 = sext i8 %37 to i32
%39 = and i32 %38, 1
%40 = trunc i32 %39 to i8
%41 = call i32 @sysfsgpio_reset(i32 %36, i8 signext %40)
br label %87
42: ; preds = %23, %20
%43 = load i32, i32* %1
%44 = icmp sge i32 %43, 48
br i1 %44, label %45, label %71
45: ; preds = %42
%46 = load i32, i32* %1
%47 = icmp sle i32 %46, 55
br i1 %47, label %48, label %71
48: ; preds = %45
%49 = load i32, i32* %1
%50 = sub nsw i32 %49, 48
%51 = trunc i32 %50 to i8
store i8 %51, i8* %3
%52 = load i8, i8* %3
%53 = sext i8 %52 to i32
%54 = and i32 %53, 4
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
%57 = xor i1 %56, true
%58 = zext i1 %57 to i32
%59 = load i8, i8* %3
%60 = sext i8 %59 to i32
%61 = and i32 %60, 2
%62 = icmp ne i32 %61, 0
%63 = xor i1 %62, true
%64 = xor i1 %63, true
%65 = zext i1 %64 to i32
%66 = load i8, i8* %3
%67 = sext i8 %66 to i32
%68 = and i32 %67, 1
%69 = trunc i32 %68 to i8
%70 = call i32 @sysfsgpio_write(i32 %58, i32 %65, i8 signext %69)
br label %86
71: ; preds = %45, %42
%72 = load i32, i32* %1
%73 = icmp eq i32 %72, 82
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = call i32 (...) @sysfsgpio_read()
%76 = call i32 @putchar(i32 %75)
br label %85
77: ; preds = %71
br label %78
78: ; preds = %77
%79 = load i32, i32* @stderr
%80 = load i32, i32* %1
%81 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %80)
%82 = load i32, i32* @stderr
%83 = call i32 @fputc(i8 signext 10, i32 %82)
br label %84
84: ; preds = %78
br label %85
85: ; preds = %84, %74
br label %86
86: ; preds = %85, %48
br label %87
87: ; preds = %86, %26
br label %88
88: ; preds = %87
br label %89
89: ; preds = %88
br label %4
90: ; preds = %12
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Unknown command '%c' received\00"
define void @process_remote_protocol() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
%4 = icmp eq i32 %1, 81
%5 = or i1 %4, %3
br i1 %5, label %47, label %6
6: ; preds = %0, %41
%7 = phi i32 [ %42, %41 ], [ %1, %0 ]
%8 = and i32 %7, -33
%9 = icmp eq i32 %8, 66
br i1 %9, label %41, label %10
10: ; preds = %6
%11 = add i32 %7, -114
%12 = icmp ult i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = add nuw nsw i32 %7, 2
%15 = lshr i32 %14, 1
%16 = and i32 %15, 1
%17 = trunc i32 %7 to i8
%18 = and i8 %17, 1
%19 = tail call i32 @sysfsgpio_reset(i32 %16, i8 signext %18)
br label %41
20: ; preds = %10
%21 = and i32 %7, -8
%22 = icmp eq i32 %21, 48
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = lshr i32 %7, 2
%25 = and i32 %24, 1
%26 = lshr i32 %7, 1
%27 = and i32 %26, 1
%28 = trunc i32 %7 to i8
%29 = and i8 %28, 1
%30 = tail call i32 @sysfsgpio_write(i32 %25, i32 %27, i8 signext %29)
br label %41
31: ; preds = %20
%32 = icmp eq i32 %7, 82
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = tail call i32 (...) @sysfsgpio_read()
%35 = tail call i32 @putchar(i32 %34)
br label %41
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7)
%39 = load i32, i32* @stderr
%40 = tail call i32 @fputc(i8 signext 10, i32 %39)
br label %41
41: ; preds = %13, %33, %36, %23, %6
%42 = tail call i32 (...) @getchar()
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
%45 = icmp eq i32 %42, 81
%46 = or i1 %45, %44
br i1 %46, label %47, label %6
47: ; preds = %41, %0
ret void
}