// File: /workspace/github_cpp_makefile_star2_O1/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 0x20cbf4(%rip), %rax    # 0x2188d0
cmpq $0x400, %rax            # imm = 0x400
sete %dl
andb %cl, %dl
movl 0x233243(%rip), %ecx    # 0x23ef30
testl %ecx, %ecx
sete %sil
testb %sil, %dl
jne 0xbd4f
testl %ecx, %ecx
sete %cl
cmpl $0xa, %edi
sete %dl
cmpq $0x800000, %rax         # imm = 0x800000
sete %al
andb %dl, %al
testb %cl, %al
jne 0xbd4f
movl %edi, %eax
imulq $0x2260, %rax, %rax     # imm = 0x2260
leaq 0x3025be(%rip), %r15    # 0x30e2e0
cmpl $0x0, 0x8(%rax,%r15)
js 0xbd4f
addq %rax, %r15
cmpl $0x0, 0x2234(%r15)
je 0xbd4f
testb $0x2, 0x2251(%r15)
jne 0xbd4f
cmpl $0xa, %edi
jne 0xbd5a
cmpb $0x0, 0x32b2cb(%rip)    # 0x337018
je 0xbd5a
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xa, %edi
sete %al
cmpb $0x0, 0x32b2b2(%rip)    # 0x337019
setne %cl
testb %cl, %al
jne 0xbd4f
cmpq $0x0, 0x23264a(%rip)    # 0x23e3c0
jne 0xbd4f
cmpb $0x4f, 0x300a29(%rip)   # 0x30c7a8
jne 0xbd9d
cmpl %edi, 0x302549(%rip)    # 0x30e2d0
jne 0xbd9d
movzbl %r14b, %esi
movl 0x2326b1(%rip), %edx    # 0x23e444
movl $0x1, %ecx
callq 0xac26
cmpl $0x2, %ebx
jne 0xbdae
cmpq $0x0, 0x33419e(%rip)    # 0x33ff48
jne 0xbdc8
jmp 0xbd4f
movq 0x334193(%rip), %rax    # 0x33ff48
leaq 0x1(%rax), %rcx
movq %rcx, 0x334188(%rip)    # 0x33ff48
movb %r14b, 0x220(%r15,%rax)
testl %ebx, %ebx
jne 0xbddd
cmpq $0x1000, 0x334171(%rip) # imm = 0x1000
jl 0xbd4f
callq 0xd1865
movl 0x8(%r15), %edi
leaq 0x220(%r15), %rsi
movq 0x334154(%rip), %rdx    # 0x33ff48
callq 0x90f0
movq %rax, %r14
decl %ebx
cmpl $0x1, %ebx
ja 0xbe0c
movl 0x8(%r15), %edi
callq 0x9300
movq 0x334135(%rip), %rax    # 0x33ff48
movq $0x0, 0x33412a(%rip) # 0x33ff48
testl %r14d, %r14d
je 0xbe2f
movslq %r14d, %rcx
cmpq %rax, %rcx
je 0xbd4f
cmpb $0x0, 0x20f3fd(%rip)    # 0x21b233
je 0xbe53
leaq 0xfdc75(%rip), %rsi     # 0x109ab4
movl $0x3, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb425
orb $0x2, 0x2251(%r15)
incl 0x32b1b3(%rip)          # 0x337014
jmp 0xbd4f