// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: sendout(unsigned int, unsigned char, int)
void sendout(unsigned port, unsigned char val, int eom_flag)
{
unsigned long written;
int flag;
static long x = 0;

   // Ssend data to the receiver.
   // We queue up data until end of message to reduce per-packet overhead.
   // If eom_flag == FLUSH_COM then send buffered chars without adding a new one
   // If eom_flag == 0, add char to buffer (sends buffer if full)
   // If eom_flag != 0, add char to buffer and send buffer

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

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

   if(com[port].process_com == 0) return;
   if(com[port].com_error & XMIT_ERR) return;
   if(just_read && (port == RCVR_PORT)) return;
   if(no_send && (port == RCVR_PORT)) return;
   if(sim_file) return;  // don't send anything out if reading a simulation file

   if(FAKE_ACRON_RCVR && (rcvr_type == ACRON_RCVR) && (port == RCVR_PORT)) {  // simulate echo by sticking char in rcv buffer
      com[port].rcv_buffer[com[port].next_rcv_byte] = val;
      ++com[port].rcv_byte_count;
      return;
   }

   if((zoom_screen == 'O') && (port == monitor_port)) {  // echo data to "terminal" monitor screen
      echo_term(port, (unsigned) val, monitor_hex, 1);
   }

   // we buffer up output chars until buffer full or end of message flag seen
   if(eom_flag == FLUSH_COM) {  // just send buffered chars
      if(x == 0) return;   // nothing to flush
   }
   else com[port].xmit_buffer[x++] = val;  // add char to send buffer

   if((x < (long) XMIT_BUF_SIZE) && (eom_flag == ADD_CHAR)) return;

   update_pwm();   // if doing pwm temperature control

   if(1 || (com[port].com_port != 0) || (com[port].usb_port != 0)) {   // zork COM port in use: send bytes via serial port
      flag = write(com[port].com_fd, com[port].xmit_buffer, x);
if((eom_flag == EOM) || (eom_flag == FLUSH_COM)) {
   fsync(com[port].com_fd);
}
      if(flag == x) written = 1;
      else          written = 0;
   }

   x = 0;

   if((flag == 0) || (written != 1)) {
      if(com_error_exit) {
         error_exit(3, "Serial transmit error");
      }
      else {
         com[port].com_error |= XMIT_ERR;
         ++com_errors;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movl %esi, %r14d
cmpl $0xa, %edi
sete %cl
movq 0x1f6e79(%rip), %rax    # 0x2028d0
cmpq $0x400, %rax            # imm = 0x400
sete %dl
andb %cl, %dl
movl 0x21d4c8(%rip), %ecx    # 0x228f30
testl %ecx, %ecx
sete %sil
testb %sil, %dl
jne 0xbaca
testl %ecx, %ecx
sete %cl
cmpl $0xa, %edi
sete %dl
cmpq $0x800000, %rax         # imm = 0x800000
sete %al
andb %dl, %al
testb %cl, %al
jne 0xbaca
movl %edi, %eax
imulq $0x2260, %rax, %rax     # imm = 0x2260
leaq 0x2ec843(%rip), %r15    # 0x2f82e0
cmpl $0x0, 0x8(%rax,%r15)
js 0xbaca
addq %rax, %r15
cmpl $0x0, 0x2234(%r15)
je 0xbaca
testb $0x2, 0x2251(%r15)
jne 0xbaca
cmpl $0xa, %edi
jne 0xbad5
cmpb $0x0, 0x315550(%rip)    # 0x321018
je 0xbad5
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xa, %edi
sete %al
cmpb $0x0, 0x315537(%rip)    # 0x321019
setne %cl
testb %cl, %al
jne 0xbaca
cmpq $0x0, 0x21c8cf(%rip)    # 0x2283c0
jne 0xbaca
cmpb $0x4f, 0x2eacae(%rip)   # 0x2f67a8
jne 0xbb16
cmpl %edi, 0x2ec7ce(%rip)    # 0x2f82d0
jne 0xbb16
movzbl %r14b, %esi
movl 0x21c936(%rip), %edx    # 0x228444
pushq $0x1
popq %rcx
callq 0xaad9
cmpl $0x2, %ebx
jne 0xbb27
cmpq $0x0, 0x31e425(%rip)    # 0x329f48
jne 0xbb57
jmp 0xbaca
movq 0x31e41a(%rip), %rax    # 0x329f48
leaq 0x1(%rax), %rcx
movq %rcx, 0x31e40f(%rip)    # 0x329f48
movb %r14b, 0x220(%r15,%rax)
cmpq $0xfff, %rax            # imm = 0xFFF
setl %al
testl %ebx, %ebx
sete %cl
testb %al, %cl
jne 0xbaca
callq 0xc067d
movl 0x8(%r15), %edi
leaq 0x220(%r15), %rsi
movq 0x31e3da(%rip), %rdx    # 0x329f48
callq 0x90f0
movq %rax, %r14
decl %ebx
cmpl $0x1, %ebx
ja 0xbb86
movl 0x8(%r15), %edi
callq 0x92f0
movq 0x31e3bb(%rip), %rax    # 0x329f48
andq $0x0, 0x31e3b3(%rip)    # 0x329f48
testl %r14d, %r14d
je 0xbba6
movslq %r14d, %rcx
cmpq %rax, %rcx
je 0xbaca
cmpb $0x0, 0x1f9686(%rip)    # 0x205233
je 0xbbc8
leaq 0xe7f5e(%rip), %rsi     # 0xf3b14
pushq $0x3
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb290
orb $0x2, 0x2251(%r15)
incl 0x31543e(%rip)          # 0x321014
jmp 0xbaca