#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*/ printf(char *);
int read(int, void *, int);
unsigned int ReadUart(int devFilePtr, unsigned char *rxBuffer) {
  int tempRxLen = read(devFilePtr, (void *)rxBuffer, 256 - 1);
  if (tempRxLen < 0) {
    printf("Read Error \n");
  } else if (tempRxLen == 0) {
    printf("No Data Waiting \n");
  } else {
    rxBuffer[tempRxLen] = '\0';
  }
  return tempRxLen;
}


x86 assembly (clang, -O0):
<ReadUart>:
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    $0xff,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    115e <ReadUart+0x3e>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
jmp    118a <ReadUart+0x6a>
cmpl   $0x0,-0x14(%rbp)
jne    1179 <ReadUart+0x59>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <ReadUart+0x65>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    118a <ReadUart+0x6a>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadUart>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0xff,%edx
call   1040 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1142 <ReadUart+0x22>
je     114b <ReadUart+0x2b>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
jmp    1157 <ReadUart+0x37>
lea    0xec8(%rip),%rdi
jmp    1152 <ReadUart+0x32>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Read Error \0A\00"
@.str.1 = [18 x i8] c"No Data Waiting \0A\00"
define i32 @ReadUart(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = load i8*, i8** %4
%8 = call i32 @read(i32 %6, i8* %7, i32 255)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %24
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %23
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %18, %16
br label %24
24: ; preds = %23, %11
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@str = [17 x i8] c"No Data Waiting \00"
@str.2 = [12 x i8] c"Read Error \00"
define i32 @ReadUart(i32 %0, i8* nocapture %1) {
%3 = tail call i32 @read(i32 %0, i8* %1, i32 255)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
br label %14
7: ; preds = %2
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %14
11: ; preds = %7
%12 = zext i32 %3 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 0, i8* %13
br label %14
14: ; preds = %9, %11, %5
ret i32 %3
}