#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*/ SerialClose(unsigned int);
scalar_t__ SerialDataAvail(unsigned int);
int /*<<< orphan*/ SerialFlush(unsigned int);
int SerialGetchar(unsigned int);
unsigned int SerialOpen(int);
int /*<<< orphan*/ SerialPrintf(unsigned int, char *, ...);
int /*<<< orphan*/ SerialPuts(unsigned int, char *);
int main(int argc, char *argv[]) {
  unsigned int ser = SerialOpen(115200);
  int a = 0;
  SerialFlush(ser);
  SerialPuts(ser, "Serial communication using the Sensorian Shield.\r\n");
  SerialPrintf(ser, "You are using device number %d.\r\n", ser);
  SerialFlush(ser);
  while (1) {
    if (SerialDataAvail(ser)) {
      a = SerialGetchar(ser);
      SerialPrintf(ser, "You sent %c.\r\n", (char)(a));
      if (a == 'b')
        break;
    }
  }
  SerialPrintf(ser, "Closing serial port ...");
  SerialClose(ser);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1c200,%edi
call   1040 <SerialOpen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <SerialFlush@plt>
mov    -0x14(%rbp),%edi
lea    0xe54(%rip),%rsi
call   1090 <SerialPuts@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1050 <SerialPrintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <SerialFlush@plt>
mov    -0x14(%rbp),%edi
call   1030 <SerialDataAvail@plt>
cmp    $0x0,%rax
je     1215 <main+0xa5>
mov    -0x14(%rbp),%edi
call   1080 <SerialGetchar@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%eax
movsbl %al,%edx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1050 <SerialPrintf@plt>
cmpl   $0x62,-0x18(%rbp)
jne    1210 <main+0xa0>
jmp    121a <main+0xaa>
jmp    1215 <main+0xa5>
jmp    11cd <main+0x5d>
mov    -0x14(%rbp),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1050 <SerialPrintf@plt>
mov    -0x14(%rbp),%edi
call   1060 <SerialClose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1c200,%edi
call   1040 <SerialOpen@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <SerialFlush@plt>
lea    0xe72(%rip),%rsi
mov    %ebx,%edi
call   1090 <SerialPuts@plt>
lea    0xe97(%rip),%rsi
mov    %ebx,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <SerialPrintf@plt>
mov    %ebx,%edi
call   1070 <SerialFlush@plt>
lea    0xea0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
call   1030 <SerialDataAvail@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %ebx,%edi
call   1080 <SerialGetchar@plt>
mov    %eax,%ebp
movsbl %bpl,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <SerialPrintf@plt>
cmp    $0x62,%ebp
jne    11c0 <main+0x50>
lea    0xe73(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <SerialPrintf@plt>
mov    %ebx,%edi
call   1060 <SerialClose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Serial communication using the Sensorian Shield.\0D\0A\00"
@.str.1 = [34 x i8] c"You are using device number %d.\0D\0A\00"
@.str.2 = [15 x i8] c"You sent %c.\0D\0A\00"
@.str.3 = [24 x i8] c"Closing serial port ...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @SerialOpen(i32 115200)
store i32 %8, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %6
%10 = call i32 @SerialFlush(i32 %9)
%11 = load i32, i32* %6
%12 = call i32 @SerialPuts(i32 %11, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %6
%14 = load i32, i32* %6
%15 = call i32 (i32, i8*, ...) @SerialPrintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %6
%17 = call i32 @SerialFlush(i32 %16)
br label %18
18: ; preds = %2, %34
%19 = load i32, i32* %6
%20 = call i64 @SerialDataAvail(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i32, i32* %6
%24 = call i32 @SerialGetchar(i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = trunc i32 %26 to i8
%28 = sext i8 %27 to i32
%29 = call i32 (i32, i8*, ...) @SerialPrintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 98
br i1 %31, label %32, label %33
32: ; preds = %22
br label %35
33: ; preds = %22
br label %34
34: ; preds = %33, %18
br label %18
35: ; preds = %32
%36 = load i32, i32* %6
%37 = call i32 (i32, i8*, ...) @SerialPrintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %6
%39 = call i32 @SerialClose(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"Serial communication using the Sensorian Shield.\0D\0A\00"
@.str.1 = [34 x i8] c"You are using device number %d.\0D\0A\00"
@.str.2 = [15 x i8] c"You sent %c.\0D\0A\00"
@.str.3 = [24 x i8] c"Closing serial port ...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @SerialOpen(i32 115200)
%4 = tail call i32 @SerialFlush(i32 %3)
%5 = tail call i32 @SerialPuts(i32 %3, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i32, i8*, ...) @SerialPrintf(i32 %3, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%7 = tail call i32 @SerialFlush(i32 %3)
br label %8
8: ; preds = %17, %2
%9 = tail call i64 @SerialDataAvail(i32 %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = tail call i32 @SerialGetchar(i32 %3)
%13 = shl i32 %12, 24
%14 = ashr exact i32 %13, 24
%15 = tail call i32 (i32, i8*, ...) @SerialPrintf(i32 %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %12, 98
br i1 %16, label %18, label %17
17: ; preds = %11, %8
br label %8
18: ; preds = %11
%19 = tail call i32 (i32, i8*, ...) @SerialPrintf(i32 %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @SerialClose(i32 %3)
ret i32 0
}