#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*/ fprintf(int /*<<< orphan*/, char *);
int read(int, void *, int);
int /*<<< orphan*/ stderr;
void read_uart(int fd, char *payload, int length) {
  char *buf;
  int i;
  buf = payload;
  for (i = 0; i < length; i++) {
    if (read(fd, (void *)buf, 1) == -1) {
      fprintf(stderr, "READ ERROR!!!");
    }
    buf = buf++;
  }
}


x86 assembly (clang, -O0):
<read_uart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119d <read_uart+0x7d>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
jne    117c <read_uart+0x5c>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <read_uart+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_uart>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1177 <read_uart+0x57>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2ea6(%rip),%r12
lea    0xebf(%rip),%r15
jmp    1155 <read_uart+0x35>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebx
je     1177 <read_uart+0x57>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
jne    1150 <read_uart+0x30>
mov    (%r12),%edi
mov    %r15,%rsi
call   1040 <fprintf@plt>
jmp    1150 <read_uart+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"READ ERROR!!!\00"
define void @read_uart(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
store i32 0, i32* %8
br label %10
10: ; preds = %25, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i8*, i8** %7
%17 = call i32 @read(i32 %15, i8* %16, i32 1)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
store i8* %23, i8** %7
br label %25
25: ; preds = %22
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %10
28: ; preds = %10
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"READ ERROR!!!\00"
define void @read_uart(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %15
5: ; preds = %3, %12
%6 = phi i32 [ %13, %12 ], [ 0, %3 ]
%7 = tail call i32 @read(i32 %0, i8* %1, i32 1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %5
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, %2
br i1 %14, label %15, label %5
15: ; preds = %12, %3
ret void
}