#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ convertBackspace(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void serial_to_stdout(int fd) {
  char buf[4096] = {0};
  int size;
  size = read(fd, buf, sizeof(buf));
  if (size < 0)
    return;
  convertBackspace(buf, size);
  write(STDOUT_FILENO, buf, size);
}


x86 assembly (clang, -O0):
<serial_to_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
jge    118d <serial_to_stdout+0x4d>
jmp    11ba <serial_to_stdout+0x7a>
lea    -0x1010(%rbp),%rdi
mov    -0x1014(%rbp),%esi
call   1060 <convertBackspace@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x1014(%rbp),%edx
call   1030 <write@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_to_stdout>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    $0x1000,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1193 <serial_to_stdout+0x53>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <convertBackspace@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
define void @serial_to_stdout(i32 %0) {
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [4096 x i8]* %3 to i8*
%6 = load i32, i32* %2
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 4096)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
br label %20
12: ; preds = %1
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @convertBackspace(i8* %13, i32 %14)
%16 = load i32, i32* @STDOUT_FILENO
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @write(i32 %16, i8* %17, i32 %18)
br label %20
20: ; preds = %12, %11
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
define void @serial_to_stdout(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 4096)
%5 = icmp slt i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = call i32 @convertBackspace(i8* %3, i32 %4)
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @write(i32 %8, i8* %3, i32 %4)
br label %10
10: ; preds = %1, %6
ret void
}