#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*/ TCOOFF;
int /*<<< orphan*/ TCOON;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int serialReadRaw(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int tcflow(int, int /*<<< orphan*/);
void serialReadChar(int fd, char *c) {
  while (serialReadRaw(fd, c, 1) != 1)
    ;
  if (*c == 0x11) {
    if (tcflow(fd, TCOON) == -1) {
      fprintf(stderr, "Could not restart flow: %s\n", strerror(errno));
    }
    serialReadChar(fd, c);
  } else if (*c == 0x13) {
    if (tcflow(fd, TCOOFF) == -1) {
      fprintf(stderr, "Could not stop flow: %s\n", strerror(errno));
    }
    serialReadChar(fd, c);
  }
}


x86 assembly (clang, -O0):
<serialReadChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1050 <serialReadRaw@plt>
cmp    $0x1,%eax
je     117e <serialReadChar+0x2e>
jmp    115f <serialReadChar+0xf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x11,%eax
jne    11e5 <serialReadChar+0x95>
mov    -0x4(%rbp),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflow@plt>
cmp    $0xffffffff,%eax
jne    11d4 <serialReadChar+0x84>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe31(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <serialReadChar@plt>
jmp    124c <serialReadChar+0xfc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x13,%eax
jne    1247 <serialReadChar+0xf7>
mov    -0x4(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflow@plt>
cmp    $0xffffffff,%eax
jne    123b <serialReadChar+0xeb>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xde6(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <serialReadChar@plt>
jmp    124c <serialReadChar+0xfc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialReadChar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e91(%rip),%r12
lea    0xea2(%rip),%r13
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <serialReadRaw@plt>
cmp    $0x1,%eax
jne    1160 <serialReadChar+0x20>
movzbl (%r14),%eax
cmp    $0x13,%al
je     11a0 <serialReadChar+0x60>
cmp    $0x11,%al
jne    11e7 <serialReadChar+0xa7>
mov    (%r12),%esi
mov    %ebp,%edi
call   1050 <tcflow@plt>
mov    %r13,%rbx
cmp    $0xffffffff,%eax
jne    1160 <serialReadChar+0x20>
jmp    11bc <serialReadChar+0x7c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <tcflow@plt>
lea    0xe65(%rip),%rbx
cmp    $0xffffffff,%eax
jne    1160 <serialReadChar+0x20>
mov    0x2e15(%rip),%rax
mov    (%rax),%r15d
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
jmp    1160 <serialReadChar+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@TCOON = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Could not restart flow: %s\0A\00"
@errno = global i32 0
@TCOOFF = global i32 0
@.str.1 = [25 x i8] c"Could not stop flow: %s\0A\00"
define void @serialReadChar(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
br label %5
5: ; preds = %10, %2
%6 = load i32, i32* %3
%7 = load i8*, i8** %4
%8 = call i32 @serialReadRaw(i32 %6, i8* %7, i32 1)
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %5
br label %5
11: ; preds = %5
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 17
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i32, i32* %3
%18 = load i32, i32* @TCOON
%19 = call i32 @tcflow(i32 %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %16
%27 = load i32, i32* %3
%28 = load i8*, i8** %4
br label %48
29: ; preds = %11
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 19
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = load i32, i32* %3
%36 = load i32, i32* @TCOOFF
%37 = call i32 @tcflow(i32 %35, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %39, %34
%45 = load i32, i32* %3
%46 = load i8*, i8** %4
br label %47
47: ; preds = %44, %29
br label %48
48: ; preds = %47, %26
ret void
}

LLVM IR (-O2):
@TCOON = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Could not restart flow: %s\0A\00"
@errno = global i32 0
@TCOOFF = global i32 0
@.str.1 = [25 x i8] c"Could not stop flow: %s\0A\00"
define void @serialReadChar(i32 %0, i8* %1) {
br label %3
3: ; preds = %6, %2
%4 = tail call i32 @serialReadRaw(i32 %0, i8* %1, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %7, label %6
6: ; preds = %3, %13, %19, %9
br label %3
7: ; preds = %3
%8 = load i8, i8* %1
switch i8 %8, label %23 [
i8 17, label %9
i8 19, label %19
]
9: ; preds = %7
%10 = load i32, i32* @TCOON
%11 = tail call i32 @tcflow(i32 %0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %6
13: ; preds = %9, %19
%14 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %19 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %9 ]
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* %14, i8* %17)
br label %6
19: ; preds = %7
%20 = load i32, i32* @TCOOFF
%21 = tail call i32 @tcflow(i32 %0, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %13, label %6
23: ; preds = %7
ret void
}