// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heather.cpp
// Function: check_incoming_data(unsigned int)
int check_incoming_data(unsigned port)
{
int flag;

   // return true if we have a serial port byte available to read
   if(port >= NUM_COM_PORTS) return 0;

   if((port == RCVR_PORT) && (rcvr_type == NO_RCVR) && (enable_terminal == 0)) { // alternate ready/not ready each check
      return(++com_tick & 0x01);
   }
if((port == RCVR_PORT) && (rcvr_type == TIDE_RCVR) && (enable_terminal == 0)) {
   return (++com_tick & 0x01);
}

   if((port == RCVR_PORT) && sim_file) {  // using a simulation file
      return sim_kbd_check();
   }

   if(com[port].com_fd < 0) return 0;

   if(com[port].com_error & RCV_ERR) {
//printf("com port %d avail err:%02X\n", port, com[port].com_error);
      return -100; // !!!! return 0;
   }
   if(com[port].next_rcv_byte < com[port].rcv_byte_count) return 2000|com[port].next_rcv_byte;  // we have already read and buffered the char

   com[port].rcv_byte_count = 0;
   com[port].next_rcv_byte = 0;

   if(1 || (com[port].com_port != 0) || (com[port].usb_port != 0)) {  // zork COM port in use: read bytes from serial port
      flag = read(com[port].com_fd, &com[port].rcv_buffer[0], RCV_BUF_SIZE);
      if(flag < 0) {  // !!!! error or no serial data available - we should check errno()
         com[port].rcv_byte_count = 0;
         return 0;
      }
      else {
         com[port].rcv_byte_count = flag;
         if(com[port].rcv_byte_count == 0) return FALSE;  // no serial port data is available
      }
   }

   return (0x8000 | com[port].rcv_byte_count);
}

// Assembly:
xorl %eax, %eax
cmpl $0x12, %edi
jbe 0xb9cb
retq
cmpl $0xa, %edi
sete %dl
movq 0x20cef8(%rip), %rcx    # 0x2188d0
cmpq $0x400, %rcx            # imm = 0x400
sete %sil
andb %dl, %sil
movl 0x233544(%rip), %edx    # 0x23ef30
testl %edx, %edx
sete %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
je 0xba1b
testl %edx, %edx
sete %dl
cmpl $0xa, %edi
sete %sil
cmpq $0x800000, %rcx         # imm = 0x800000
sete %cl
andb %sil, %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0xba2d
movl 0x3344db(%rip), %eax    # 0x33fefc
incl %eax
movl %eax, 0x3344d3(%rip)    # 0x33fefc
andl $0x1, %eax
retq
cmpl $0xa, %edi
jne 0xba83
cmpq $0x0, 0x232986(%rip)    # 0x23e3c0
je 0xba83
cmpb $0x0, 0x20f7f1(%rip)    # 0x21b234
movl $0x0, %eax
jne 0xb9ca
movl 0x3344ac(%rip), %eax    # 0x33fefc
movl %eax, %ecx
incl %ecx
movslq %ecx, %rcx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
negl %ecx
addl %eax, %ecx
incl %ecx
movl %ecx, 0x334482(%rip)    # 0x33fefc
xorl %eax, %eax
cmpl $0x3, %ecx
setge %al
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movl %edi, %ecx
imulq $0x2260, %rcx, %rcx     # imm = 0x2260
leaq 0x302847(%rip), %rbx    # 0x30e2e0
movl 0x8(%rcx,%rbx), %edi
testl %edi, %edi
js 0xbb0a
addq %rcx, %rbx
movl $0xffffff9c, %eax       # imm = 0xFFFFFF9C
testb $0x1, 0x2251(%rbx)
jne 0xbb0a
movl 0x2224(%rbx), %eax
cmpl 0x2220(%rbx), %eax
jge 0xbac7
orl $0x7d0, %eax            # imm = 0x7D0
jmp 0xbb0a
movq $0x0, 0x2220(%rbx)
leaq 0x1220(%rbx), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x9570
movq %rax, %rcx
testl %ecx, %ecx
js 0xbafe
movl %ecx, 0x2220(%rbx)
movl %ecx, %eax
orl $0x8000, %eax           # imm = 0x8000
testl %ecx, %ecx
cmovel %ecx, %eax
jmp 0xbb0a
movl $0x0, 0x2220(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq