#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*/ B19200;
int /*<<< orphan*/ bzero(unsigned char *, int);
int init_uart(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int uart_read(int, unsigned char *, int /*<<< orphan*/, int, int);
int main(int argc, char *argv[]) {
  unsigned char read_buf[16];
  int uart_fd;
  int uart_rcv_len;
  int i;
  uart_fd = init_uart((B19200));
  while (1) {
    bzero(read_buf, 8);
    uart_rcv_len = uart_read(uart_fd, read_buf, 0, 10000, 8);
    if (uart_rcv_len > 0) {
      for (i = 0; i < uart_rcv_len; i++) {
        printf("0X%02X ", *(unsigned char *)(read_buf + i));
      }
      printf("\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1050 <init_uart@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1060 <bzero@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
mov    $0x2710,%ecx
mov    $0x8,%r8d
call   1030 <uart_read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11e1 <main+0xa1>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11d3 <main+0x93>
movslq -0x2c(%rbp),%rax
movzbl -0x20(%rbp,%rax,1),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a2 <main+0x62>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1167 <main+0x27>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1060 <init_uart@plt>
mov    %eax,%r14d
mov    %rsp,%r15
lea    0xe89(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x8,%esi
call   1070 <bzero@plt>
mov    %r14d,%edi
mov    %r15,%rsi
xor    %edx,%edx
mov    $0x2710,%ecx
mov    $0x8,%r8d
call   1040 <uart_read@plt>
test   %eax,%eax
jle    1180 <main+0x30>
mov    %eax,%ebx
xor    %ebp,%ebp
nopl   (%rax)
movzbl (%rsp,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11b0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1180 <main+0x30>

LLVM IR (-O0):
@B19200 = global i32 0
@.str = [8 x i8] c"0X%02X \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @B19200
%11 = call i32 @init_uart(i32 %10)
store i32 %11, i32* %7
br label %12
12: ; preds = %2, %38
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i32 8)
%15 = load i32, i32* %7
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%17 = call i32 @uart_read(i32 %15, i8* %16, i32 0, i32 10000, i32 8)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %12
store i32 0, i32* %9
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %25
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %21
36: ; preds = %21
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %12
br label %12
}

LLVM IR (-O2):
@B19200 = global i32 0
@.str = [8 x i8] c"0X%02X \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @B19200
%6 = tail call i32 @init_uart(i32 %5)
br label %7
7: ; preds = %23, %2
%8 = call i32 @bzero(i8* %4, i32 8)
%9 = call i32 @uart_read(i32 %6, i8* %4, i32 0, i32 10000, i32 8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %19, %13 ]
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = call i32 @putchar(i32 10)
br label %23
23: ; preds = %21, %7
br label %7
}