#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('5');
  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    $0x35,%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     11d3 <main+0xa3>
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    119a <main+0x6a>
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    $0x35,%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>
nopl   0x0(%rax,%rax,1)
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    1190 <main+0x60>
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 53)
%10 = call i32 @serial_put_char(i8 signext 13)
%11 = call i32 @serial_put_char(i8 signext 10)
br label %12
12: ; preds = %16, %0
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 113
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = call signext i8 (...) @serial_get_char()
store i8 %17, i8* %2
%18 = load i8, i8* %2
%19 = call i32 @serial_put_char(i8 signext %18)
%20 = call i32 @serial_put_char(i8 signext 13)
%21 = call i32 @serial_put_char(i8 signext 10)
br label %12
22: ; preds = %12
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 53)
%8 = tail call i32 @serial_put_char(i8 signext 13)
%9 = tail call i32 @serial_put_char(i8 signext 10)
br label %10
10: ; preds = %0, %10
%11 = tail call signext i8 (...) @serial_get_char()
%12 = tail call i32 @serial_put_char(i8 signext %11)
%13 = tail call i32 @serial_put_char(i8 signext 13)
%14 = tail call i32 @serial_put_char(i8 signext 10)
%15 = icmp eq i8 %11, 113
br i1 %15, label %16, label %10
16: ; preds = %10
ret i32 0
}