#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 */
char serial_get_char();
int /*<<< orphan*/ serial_init();
int /*<<< orphan*/ serial_put_char(char);
int main(void) {
  char rcvChar = 0;
  serial_init();
  serial_put_char('s');
  serial_put_char('t');
  serial_put_char('a');
  serial_put_char('r');
  serial_put_char('t');
  serial_put_char('\r');
  serial_put_char('\n');
  while (rcvChar != 'q') {
    rcvChar = serial_get_char();
    serial_put_char(rcvChar);
    serial_put_char('\r');
    serial_put_char('\n');
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
mov    $0x0,%al
call   1050 <serial_init@plt>
mov    $0x73,%edi
call   1030 <serial_put_char@plt>
mov    $0x74,%edi
call   1030 <serial_put_char@plt>
mov    $0x61,%edi
call   1030 <serial_put_char@plt>
mov    $0x72,%edi
call   1030 <serial_put_char@plt>
mov    $0x74,%edi
call   1030 <serial_put_char@plt>
mov    $0xd,%edi
call   1030 <serial_put_char@plt>
mov    $0xa,%edi
call   1030 <serial_put_char@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
je     11c9 <main+0x99>
mov    $0x0,%al
call   1040 <serial_get_char@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <serial_put_char@plt>
mov    $0xd,%edi
call   1030 <serial_put_char@plt>
mov    $0xa,%edi
call   1030 <serial_put_char@plt>
jmp    1190 <main+0x60>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <serial_init@plt>
mov    $0x73,%edi
call   1030 <serial_put_char@plt>
mov    $0x74,%edi
call   1030 <serial_put_char@plt>
mov    $0x61,%edi
call   1030 <serial_put_char@plt>
mov    $0x72,%edi
call   1030 <serial_put_char@plt>
mov    $0x74,%edi
call   1030 <serial_put_char@plt>
mov    $0xd,%edi
call   1030 <serial_put_char@plt>
mov    $0xa,%edi
call   1030 <serial_put_char@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <serial_get_char@plt>
movsbl %al,%ebx
mov    %ebx,%edi
call   1030 <serial_put_char@plt>
mov    $0xd,%edi
call   1030 <serial_put_char@plt>
mov    $0xa,%edi
call   1030 <serial_put_char@plt>
cmp    $0x71,%bl
jne    1180 <main+0x50>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
store i8 0, i8* %2
%3 = call i32 (...) @serial_init()
%4 = call i32 @serial_put_char(i8 signext 115)
%5 = call i32 @serial_put_char(i8 signext 116)
%6 = call i32 @serial_put_char(i8 signext 97)
%7 = call i32 @serial_put_char(i8 signext 114)
%8 = call i32 @serial_put_char(i8 signext 116)
%9 = call i32 @serial_put_char(i8 signext 13)
%10 = call i32 @serial_put_char(i8 signext 10)
br label %11
11: ; preds = %15, %0
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 113
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = call signext i8 (...) @serial_get_char()
store i8 %16, i8* %2
%17 = load i8, i8* %2
%18 = call i32 @serial_put_char(i8 signext %17)
%19 = call i32 @serial_put_char(i8 signext 13)
%20 = call i32 @serial_put_char(i8 signext 10)
br label %11
21: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @serial_init()
%2 = tail call i32 @serial_put_char(i8 signext 115)
%3 = tail call i32 @serial_put_char(i8 signext 116)
%4 = tail call i32 @serial_put_char(i8 signext 97)
%5 = tail call i32 @serial_put_char(i8 signext 114)
%6 = tail call i32 @serial_put_char(i8 signext 116)
%7 = tail call i32 @serial_put_char(i8 signext 13)
%8 = tail call i32 @serial_put_char(i8 signext 10)
br label %9
9: ; preds = %0, %9
%10 = tail call signext i8 (...) @serial_get_char()
%11 = tail call i32 @serial_put_char(i8 signext %10)
%12 = tail call i32 @serial_put_char(i8 signext 13)
%13 = tail call i32 @serial_put_char(i8 signext 10)
%14 = icmp eq i8 %10, 113
br i1 %14, label %15, label %9
15: ; preds = %9
ret i32 0
}