#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int read(int, char **, int);
int /*<<< orphan*/ sleep(int);
int main() {
  int fd;
  char data[256];
  int count, i;
  fd = open("/dev/cbc/uart0", O_RDONLY);
  while (1) {
    count = read(fd, &data, 256);
    if (count > 0)
      printf("Got count=%d\n", count);
    for (i = 0; count > 0 && i < count; i++) {
      putchar(data[count]);
    }
    sleep(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jle    11b3 <main+0x63>
mov    -0x114(%rbp),%esi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x118(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x114(%rbp)
mov    %al,-0x119(%rbp)
jle    11e7 <main+0x97>
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
setl   %al
mov    %al,-0x119(%rbp)
mov    -0x119(%rbp),%al
test   $0x1,%al
jne    11fa <main+0xaa>
jmp    1222 <main+0xd2>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%edi
ff
call   1030 <putchar@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    11bd <main+0x6d>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    117a <main+0x2a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r12d
mov    %rsp,%r14
lea    0xe8c(%rip),%r15
jmp    119a <main+0x4a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1190 <main+0x40>
mov    %eax,%r13d
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r13d,%eax
mov    (%rsp,%rax,1),%bl
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %bl,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %r13d,%ebp
jl     11d0 <main+0x80>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/cbc/uart0\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"Got count=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
br label %8
8: ; preds = %0, %36
%9 = load i32, i32* %2
%10 = bitcast [256 x i8]* %3 to i8**
%11 = call i32 @read(i32 %9, i8** %10, i32 256)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %8
store i32 0, i32* %5
br label %18
18: ; preds = %33, %17
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br label %25
25: ; preds = %21, %18
%26 = phi i1 [ false, %18 ], [ %24, %21 ]
br i1 %26, label %27, label %36
27: ; preds = %25
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @putchar(i8 signext %31)
br label %33
33: ; preds = %27
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %18
36: ; preds = %25
%37 = call i32 @sleep(i32 1)
br label %8
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/cbc/uart0\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"Got count=%d\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = bitcast [256 x i8]* %1 to i8**
br label %6
6: ; preds = %19, %0
%7 = call i32 @read(i32 %4, i8** %5, i32 256)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%11 = zext i32 %7 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
br label %14
14: ; preds = %9, %14
%15 = phi i32 [ 0, %9 ], [ %17, %14 ]
%16 = tail call i32 @putchar(i8 signext %13)
%17 = add nuw nsw i32 %15, 1
%18 = icmp slt i32 %17, %7
br i1 %18, label %14, label %19
19: ; preds = %14, %6
%20 = tail call i32 @sleep(i32 1)
br label %6
}