// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: config_tcpip_device(unsigned int, char*)
int config_tcpip_device(unsigned port, char *arg)
{
int i;

   // setup to use a com device using a com device name.
   // Returns 0 if successful,  non-zero if error.

   if(arg == 0) return 1;
   if(port >= NUM_COM_PORTS) return 2;

   if(arg[0]) {  // TCP/IP addr given
      com[port].com_port = com[port].usb_port = 0;
      com[port].user_disabled_com = 0;
      com[port].process_com = 1;
      strncpy(com[port].IP_addr, &arg[0], sizeof(com[port].IP_addr)-1);
      com[port].IP_addr[sizeof(com[port].IP_addr)-1] = 0;

      for(i=strlen(com[port].IP_addr)-1; i>=0; i++) {  // trim trailing scuzz
         if     (com[port].IP_addr[i] == 0x0A) com[port].IP_addr[i] = 0;
         else if(com[port].IP_addr[i] == 0x0D) com[port].IP_addr[i] = 0;
         else if(com[port].IP_addr[i] == ' ')  com[port].IP_addr[i] = 0;
         else if(com[port].IP_addr[i] == '\t') com[port].IP_addr[i] = 0;
         else if(com[port].IP_addr[i]) break;
      }
   }
   else if(com[port].IP_addr[0]) {  // use old IP address
   }
   else {  // !!!!!! use a default IP addr
   }

   com[port].IP_addr[sizeof(com[port].IP_addr)-1] = 0;
   if(com[port].IP_addr[0] == 0) return 3;
   com[port].user_set_ip = 2;

   if(com[port].com_running && com[port].IP_addr[0]) {  // use TCPIP port
      com[port].com_port = com[port].usb_port = 0;
      com[port].user_disabled_com = 0;
      com[port].process_com = 1;
      init_com(port, 15);
   }

   com[port].last_com_time = this_msec - com[port].com_timeout;

   return 0;
}

// Assembly:
testq %rsi, %rsi
je 0x4929e
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
cmpl $0x12, %edi
jbe 0x492a2
pushq $0x2
jmp 0x493bd
pushq $0x1
popq %rax
retq
cmpb $0x0, (%rsi)
movl %ebx, %r15d
je 0x4933f
imulq $0x2260, %r15, %r12     # imm = 0x2260
leaq 0x2af024(%rip), %r13    # 0x2f82e0
andq $0x0, (%r13,%r12)
andl $0x0, 0x2228(%r13,%r12)
movl $0x1, 0x2234(%r13,%r12)
movl $0x10d, %eax            # imm = 0x10D
leaq (%r12,%rax), %r14
addq %r13, %r14
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
callq 0x9170
movb $0x0, 0x20d(%r13,%r12)
movq %r14, %rdi
callq 0x9120
decl %eax
addq %r13, %r12
movl $0x10d, %ecx            # imm = 0x10D
addq %rcx, %r12
addq %rax, %r12
movabsq $0x100002600, %rcx      # imm = 0x100002600
testl %eax, %eax
js 0x4933f
movzbl (%r12), %edx
cmpq $0x20, %rdx
ja 0x4933f
btq %rdx, %rcx
jae 0x4933a
movb $0x0, (%r12)
incq %r12
jmp 0x4931b
testq %rdx, %rdx
je 0x49335
imulq $0x2260, %r15, %rax     # imm = 0x2260
leaq 0x2aef93(%rip), %r14    # 0x2f82e0
movb $0x0, 0x20d(%r14,%rax)
cmpb $0x0, 0x10d(%r14,%rax)
je 0x493bb
addq %rax, %r14
movl $0x2, 0x225c(%r14)
cmpl $0x0, 0x2230(%r14)
je 0x4939a
andq $0x0, (%r14)
andl $0x0, 0x2228(%r14)
movl $0x1, 0x2234(%r14)
pushq $0xf
popq %rsi
movl %ebx, %edi
callq 0xb30a
leaq 0x2ae3c7(%rip), %rax    # 0x2f7768
movsd (%rax), %xmm0
subsd 0x2238(%r14), %xmm0
movsd %xmm0, 0x2248(%r14)
xorl %eax, %eax
jmp 0x493be
pushq $0x3
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq