#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*/ close_serial(int);
int init_serial(char *, int);
int /*<<< orphan*/ printf(char *, char, char, int);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int dev, size;
  char data[1];
  dev = init_serial("/dev/ttyACM0", 115200);
  while (1) {
    size = read(dev, data, 1);
    printf("Data -> %x - %c -- Size %d\n", data[0], data[0], size);
    data[0] = 0;
    write(dev, data, 1);
  }
  close_serial(dev);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x1c200,%esi
call   1060 <init_serial@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0xd(%rbp),%dl
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%ecx
lea    0xe86(%rip),%rdi
movsbl %dl,%esi
movsbl %al,%edx
call   1040 <printf@plt>
movb   $0x0,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1163 <main+0x23>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
mov    $0x1c200,%esi
call   1060 <init_serial@plt>
mov    %eax,%ebx
lea    0xf(%rsp),%r14
lea    0xea5(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movsbl 0xf(%rsp),%edx
mov    %r15,%rdi
mov    %edx,%esi
mov    %eax,%ecx
call   1040 <printf@plt>
movb   $0x0,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.1 = [28 x i8] c"Data -> %x - %c -- Size %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x i8]
store i32 0, i32* %1
%5 = call i32 @init_serial(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 115200)
store i32 %5, i32* %2
br label %6
6: ; preds = %0, %6
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 1)
store i32 %9, i32* %3
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%11 = load i8, i8* %10
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%13 = load i8, i8* %12
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8 signext %11, i8 signext %13, i32 %14)
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
store i8 0, i8* %16
%17 = load i32, i32* %2
%18 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 1)
br label %6
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@.str.1 = [28 x i8] c"Data -> %x - %c -- Size %d\0A\00"
define i32 @main() {
%1 = alloca [1 x i8]
%2 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @init_serial(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 115200)
br label %4
4: ; preds = %4, %0
%5 = call i32 @read(i32 %3, i8* %2, i32 1)
%6 = load i8, i8* %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8 signext %6, i8 signext %6, i32 %5)
store i8 0, i8* %2
%8 = call i32 @write(i32 %3, i8* %2, i32 1)
br label %4
}