int handle_serialread(int fs, char *rx_buffer, int len_rx_buffer) {
  int rx_length;
  rx_length = read(fs, (void *)rx_buffer, len_rx_buffer);
  if (rx_length < 0) {
  } else if (rx_length == 0) {
    printf("%s: no data on read\n", __FUNCTION__);
  } else {
    rx_buffer[rx_length] = '\0';
  }
  return (rx_length);
}


x86 assembly (clang, -O0):
<handle_serialread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1155 <handle_serialread+0x35>
jmp    118a <handle_serialread+0x6a>
cmpl   $0x0,-0x18(%rbp)
jne    1179 <handle_serialread+0x59>
lea    0xe9a(%rip),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1185 <handle_serialread+0x65>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    118a <handle_serialread+0x6a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_serialread>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
xor    %eax,%eax
call   1040 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1154 <handle_serialread+0x34>
je     113f <handle_serialread+0x1f>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
jmp    1154 <handle_serialread+0x34>
lea    0xeba(%rip),%rdi
lea    0xec8(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s: no data on read\0A\00"
@__FUNCTION__.handle_serialread = [18 x i8] c"handle_serialread\00"
define i32 @handle_serialread(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %8, i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
br label %26
15: ; preds = %3
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.handle_serialread, i64 0, i64 0))
br label %25
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %20, %18
br label %26
26: ; preds = %25, %14
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s: no data on read\0A\00"
@__FUNCTION__.handle_serialread = [18 x i8] c"handle_serialread\00"
define i32 @handle_serialread(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %1, i32 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = icmp eq i32 %4, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.handle_serialread, i64 0, i64 0))
br label %13
10: ; preds = %6
%11 = zext i32 %4 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %8, %10, %3
ret i32 %4
}