#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 */
scalar_t__ UART1_Data_Ready();
int /*<<< orphan*/ UART1_Init(int);
int /*<<< orphan*/ UART1_Read_Text(char *, char *, int);
scalar_t__ UART1_Tx_Idle();
int /*<<< orphan*/ UART1_Write_Text(char *);
void main() {
  char buffer[10];
  UART1_Init(9600);
  UART1_Write_Text("mikroC UART TEST\n");
  while (1) {
    if (UART1_Data_Ready()) {
      UART1_Read_Text(buffer, "\n", 255);
      if (UART1_Tx_Idle()) {
        UART1_Write_Text(buffer);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x2580,%edi
call   1040 <UART1_Init@plt>
lea    0xe97(%rip),%rdi
call   1050 <UART1_Write_Text@plt>
mov    $0x0,%al
call   1070 <UART1_Data_Ready@plt>
cmp    $0x0,%rax
je     11b3 <main+0x63>
lea    -0xa(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0xff,%edx
call   1060 <UART1_Read_Text@plt>
mov    $0x0,%al
call   1030 <UART1_Tx_Idle@plt>
cmp    $0x0,%rax
je     11ae <main+0x5e>
lea    -0xa(%rbp),%rdi
call   1050 <UART1_Write_Text@plt>
jmp    11b3 <main+0x63>
jmp    116e <main+0x1e>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x2580,%edi
call   1040 <UART1_Init@plt>
lea    0xe98(%rip),%rdi
call   1050 <UART1_Write_Text@plt>
lea    0xe9c(%rip),%r14
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <UART1_Data_Ready@plt>
test   %rax,%rax
je     1180 <main+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1060 <UART1_Read_Text@plt>
xor    %eax,%eax
call   1030 <UART1_Tx_Idle@plt>
test   %rax,%rax
je     1180 <main+0x30>
mov    %rbx,%rdi
call   1050 <UART1_Write_Text@plt>
jmp    1180 <main+0x30>

LLVM IR (-O0):
@.str = [18 x i8] c"mikroC UART TEST\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca [10 x i8]
%2 = call i32 @UART1_Init(i32 9600)
%3 = call i32 @UART1_Write_Text(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %0, %16
%5 = call i64 (...) @UART1_Data_Ready()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%9 = call i32 @UART1_Read_Text(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 255)
%10 = call i64 (...) @UART1_Tx_Idle()
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%14 = call i32 @UART1_Write_Text(i8* %13)
br label %15
15: ; preds = %12, %7
br label %16
16: ; preds = %15, %4
br label %4
}

LLVM IR (-O2):
@.str = [18 x i8] c"mikroC UART TEST\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @UART1_Init(i32 9600)
%4 = tail call i32 @UART1_Write_Text(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %12, %0
%6 = call i64 (...) @UART1_Data_Ready()
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = call i32 @UART1_Read_Text(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 255)
%10 = call i64 (...) @UART1_Tx_Idle()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8, %13, %5
br label %5
13: ; preds = %8
%14 = call i32 @UART1_Write_Text(i8* %2)
br label %12
}