// File: /workspace/github_cpp_makefile_star2_O3/st0ne[P]XReflectorPlus/dxrfd.cpp
// Function: main
int main(int argc, char **argv)
{
   int rc = 0;
   struct sigaction act;
   inbound_type::iterator inbound_pos; 
   inbound *inbound_ptr;
   short int i;

   // R3ABM Patch
   if (argc != 2) /* 3 */
   {
      printf("Usage:  dxrfd <configFile>\n");
      printf("Example: dxrfd dxrfd.cfg\n");

      //printf("Usage:  dxrfd <configFile> <logFile>\n");
      //printf("Example: dxrfd dxrfd.cfg dxrfd.log\n");
      return 1;
   }

   // R3ABM Patch
   /*

   if (access(argv[2], F_OK) == 0)
   {
      printf("Log file %s exists, is dxrfd already running?, if not running, remove log file and restart\n", argv[2]);
      return 1;
   }
   */

   rc = regcomp(&preg,
        "^(([1-9][A-Z])|([A-Z][0-9])|([A-Z][A-Z][0-9]))[0-9A-Z]*[A-Z][ ]*[ A-RT-Z]$",
        REG_EXTENDED | REG_NOSUB);
   if (rc != REG_NOERROR)
   {
      traceit("The regular expression is NOT valid\n");
      return 1;
   }

   /* Open log file */
   // R3ABM Patch
   /*

   logfp = fopen(argv[2], "a");
   if (!logfp)
   {
      printf("Cant create log file %s, error=%d\n",
              argv[2],errno);
      return 1;
   }
   */

   tzset();

   /* line buffering only */
   // R3ABM Patch
   //setvbuf(logfp, (char *)NULL, _IOLBF, 0);

   act.sa_handler = sigCatch;
   sigemptyset(&act.sa_mask);
   act.sa_flags = SA_RESTART;
   if (sigaction(SIGTERM, &act, 0) != 0)
   {
      traceit("sigaction-TERM failed, error=%d\n", errno);
      return 1;
   }
   if (sigaction(SIGINT, &act, 0) != 0)
   {
      traceit("sigaction-INT failed, error=%d\n", errno);
      return 1;
   }

   do
   {
      /* process configuration file */
      rc = read_config(argv[1]);
      if (rc != 0)
      {
         traceit("Failed to process config file %s\n", argv[1]);
         break;
      }

    /* Open DB */
      rc = open_users(USERS);
      if (rc != 0)
      {
         traceit("Failed to open %s\n", USERS);
         break;
      }

      rc = open_blocks(BLOCKS);
      if (rc != 0)
      {
         traceit("Failed to open %s\n", BLOCKS);
         break;
      }

      /* get ready to accept incoming connections */
      rc = srv_open();
      if (rc != 0)
      {
         traceit("srv_open() failed\n");
         break;
      }

      /* get ready to accept shell commands from netcat */
      rc = cmd_open();
      if (rc != 0)
      {
         traceit("cmd_open() failed\n");
         break;
      }

      rc = ref_open();
      if (rc != 0)
      {
         traceit("ref_open() failed\n");
         break;
      }
  
      for (i = 0; i < 5; i++)
      {
         temp_x[i].s_addr = 0;
         memset(temp_x[i].hdr, 0, 56);

         temp_r[i].s_addr = 0;
         memset(temp_r[i].hdr, 0, 58);
      }

      traceit("dxrfd %s initialized...entering processing loop\n", VERSION);

      print_links_file();
      runit();
      traceit("Leaving processing loop...\n");

   } while (false);

   /* Close all handles */
   if (srv_sock != -1)
      close(srv_sock);

   if (cmd_sock != -1)
      close(cmd_sock);

   /* notify dvap, dvtool ... */
   if (ref_sock != -1)
   {
      refbuf[0] = 5;
      refbuf[1] = 0;
      refbuf[2] = 24;
      refbuf[3] = 0;
      refbuf[4] = 0;
      for (inbound_pos = inbound_list.begin(); inbound_pos != inbound_list.end(); inbound_pos++)
      {
         inbound_ptr = (inbound *)inbound_pos->second;
         sendto(ref_sock,(char *)refbuf,5,0,
                (struct sockaddr *)&(inbound_ptr->sin),
                sizeof(struct sockaddr_in));
      }
      inbound_list.clear();
      close(ref_sock);
   }

   /* Empty out the status file */
   statusfp = fopen(STATUS_FILE, "w");
   if (statusfp)
      fclose(statusfp);
   else
      traceit("Failed to empty out status file %s\n", STATUS_FILE);

   traceit("dxrfd exiting\n");
   // R3ABM Patch
   //fclose(logfp);
 
   return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
cmpl $0x2, %edi
jne 0x27d7
movq %rsi, %rbx
leaq 0xec31(%rip), %rdi      # 0x113e0
leaq 0x993a(%rip), %rsi      # 0xc0f0
movl $0x9, %edx
callq 0x2250
testl %eax, %eax
je 0x27f4
leaq 0x9970(%rip), %rdi      # 0xc13b
xorl %eax, %eax
callq 0x26fc
jmp 0x2874
leaq 0xa9c2(%rip), %rdi      # 0xd1a0
callq 0x2360
leaq 0xa9d1(%rip), %rdi      # 0xd1bb
callq 0x2360
jmp 0x2874
callq 0x2070
leaq 0x8b9(%rip), %rax       # 0x30b9
leaq 0x418(%rsp), %r14
movq %rax, -0x8(%r14)
movq %r14, %rdi
callq 0x22c0
movl $0x10000000, 0x80(%r14) # imm = 0x10000000
leaq 0x410(%rsp), %rsi
movl $0xf, %edi
xorl %edx, %edx
callq 0x22d0
testl %eax, %eax
je 0x2847
callq 0x2050
movl (%rax), %esi
leaq 0x991b(%rip), %rdi      # 0xc160
jmp 0x286d
leaq 0x410(%rsp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x22d0
testl %eax, %eax
je 0x288d
callq 0x2050
movl (%rax), %esi
leaq 0x9914(%rip), %rdi      # 0xc181
xorl %eax, %eax
callq 0x26fc
movl $0x1, %ebx
movl %ebx, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %r14
leaq 0x99fe(%rip), %rsi      # 0xc296
movq %r14, %rdi
callq 0x2270
testq %rax, %rax
je 0x2e97
movq %rax, %r15
leaq 0x99fd(%rip), %rdi      # 0xc2b0
movq %r14, %rsi
xorl %eax, %eax
callq 0x26fc
leaq 0x10(%rsp), %rdi
movl $0x3fc, %esi            # imm = 0x3FC
movq %r15, %rdx
callq 0x23a0
testq %rax, %rax
je 0x2ea0
leaq 0x10(%rsp), %r12
movl $0x454e574f, %ebp       # imm = 0x454E574F
movl $0x0, 0x4(%rsp)
movq %r12, %rdi
movl $0x23, %esi
callq 0x20e0
testq %rax, %rax
jne 0x2938
movq %r12, %rdi
movl $0xd, %esi
callq 0x20e0
testq %rax, %rax
je 0x2911
movb $0x0, (%rax)
movq %r12, %rdi
movl $0xa, %esi
callq 0x20e0
testq %rax, %rax
je 0x2926
movb $0x0, (%rax)
movq %r12, %rdi
movl $0x3d, %esi
callq 0x20e0
testq %rax, %rax
jne 0x2952
movq %r12, %rdi
movl $0x3fc, %esi            # imm = 0x3FC
movq %r15, %rdx
callq 0x23a0
testq %rax, %rax
jne 0x28ea
jmp 0x2e65
movq %rax, %r13
movb $0x0, (%rax)
movl 0x10(%rsp), %eax
xorl %ebp, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x52, %ecx
orl %eax, %ecx
je 0x2ae8
movl 0x10(%rsp), %eax
movl $0x494d4441, %ecx       # imm = 0x494D4441
xorl %ecx, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x4e, %ecx
orl %eax, %ecx
je 0x2be4
movq 0x10(%rsp), %rax
movabsq $0x495f4e455453494c, %rcx # imm = 0x495F4E455453494C
xorq %rcx, %rax
movzwl 0x18(%rsp), %ecx
xorq $0x50, %rcx
orq %rax, %rcx
je 0x2c48
movq 0x10(%rsp), %rax
movabsq $0x505f4e455453494c, %rcx # imm = 0x505F4E455453494C
xorq %rcx, %rax
movl 0x18(%rsp), %ecx
xorq $0x54524f, %rcx         # imm = 0x54524F
orq %rax, %rcx
je 0x2cd5
movq 0x10(%rsp), %rax
movabsq $0x5f444e414d4d4f43, %rcx # imm = 0x5F444E414D4D4F43
xorq %rcx, %rax
movq 0x15(%rsp), %rcx
movabsq $0x54524f505f444e, %rdx # imm = 0x54524F505F444E
xorq %rdx, %rcx
orq %rax, %rcx
je 0x2d42
movq 0x10(%rsp), %rax
movabsq $0x524553555f58414d, %rcx # imm = 0x524553555F58414D
xorq %rcx, %rax
movzwl 0x18(%rsp), %ecx
xorq $0x53, %rcx
orq %rax, %rcx
je 0x2d72
movdqa 0x10(%rsp), %xmm0
pcmpeqb 0x95de(%rip), %xmm0     # 0xc010
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x2d8c
movq 0x10(%rsp), %rax
movabsq $0x465f535554415453, %rcx # imm = 0x465F535554415453
xorq %rcx, %rax
movl 0x18(%rsp), %ecx
xorq $0x454c49, %rcx         # imm = 0x454C49
orq %rax, %rcx
je 0x2db6
movl 0x10(%rsp), %eax
movl $0x52455355, %ecx       # imm = 0x52455355
xorl %ecx, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x53, %ecx
orl %eax, %ecx
je 0x2df3
movl 0x10(%rsp), %eax
movl $0x434f4c42, %ecx       # imm = 0x434F4C42
xorl %ecx, %eax
movl 0x13(%rsp), %ecx
movl $0x534b43, %edx         # imm = 0x534B43
xorl %edx, %ecx
orl %eax, %ecx
je 0x2e30
movq 0x10(%rsp), %rax
movabsq $0x415445445f4f5351, %rcx # imm = 0x415445445F4F5351
xorq %rcx, %rax
movl 0x18(%rsp), %ecx
xorq $0x534c49, %rcx         # imm = 0x534C49
orq %rax, %rcx
jne 0x2d38
movsbl 0x1(%r13), %esi
cmpl $0x59, %esi
sete 0x1203b(%rip)           # 0x14b10
leaq 0x99b0(%rip), %rdi      # 0xc48c
xorl %eax, %eax
callq 0x26fc
jmp 0x2d34
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x11fdf(%rip)     # 0x14ad8
movb $0x0, 0x11fe0(%rip)     # 0x14ae0
incq %r13
movq %r13, %rdi
movl $0x20, %esi
callq 0x20e0
testq %rax, %rax
je 0x2b18
movb $0x0, (%rax)
movq %r13, %rdi
callq 0x2100
cmpq $0x6, %rax
jne 0x2c1a
movq %r14, 0x8(%rsp)
movzwl 0x4(%r13), %eax
movw %ax, 0x11fa1(%rip)      # 0x14adc
movl (%r13), %eax
movl %eax, 0x11f93(%rip)     # 0x14ad8
testb %al, %al
leaq 0x11f8a(%rip), %r14     # 0x14ad8
je 0x2b7b
movw $0x1, %r13w
xorl %ebp, %ebp
movsbl (%rbp,%r14), %edi
callq 0x2430
movb %al, (%rbp,%r14)
movzwl %r13w, %ebp
movq %r14, %rdi
callq 0x2100
incl %r13d
cmpq %rbp, %rax
ja 0x2b57
movl 0x11f57(%rip), %eax     # 0x14ad8
movl $0x5258, %ecx           # imm = 0x5258
xorl %ecx, %eax
movzbl 0x11f4b(%rip), %ecx     # 0x14ada
xorl $0x46, %ecx
orw %ax, %cx
movq 0x8(%rsp), %r14
jne 0x2c35
movsbl 0x11f34(%rip), %eax     # 0x14adb
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2c35
movsbl 0x11f22(%rip), %eax     # 0x14adc
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2c35
movsbl 0x11f14(%rip), %eax     # 0x14add
addl $-0x30, %eax
cmpl $0xa, %eax
jae 0x2c35
leaq 0x9769(%rip), %rdi      # 0xc341
leaq 0x11ef9(%rip), %rsi     # 0x14ad8
jmp 0x2d2d
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x11ef3(%rip)     # 0x14ae8
movb $0x0, 0x11ef4(%rip)     # 0x14af0
cmpb $0x20, 0x1(%r13)
jne 0x2ca5
leaq 0x9743(%rip), %rdi      # 0xc351
xorl %eax, %eax
callq 0x26fc
jmp 0x2938
leaq 0x96a6(%rip), %rdi      # 0xc2c7
movq %r13, %rsi
movl $0x6, %edx
xorl %eax, %eax
callq 0x26fc
jmp 0x2938
leaq 0x96c2(%rip), %rdi      # 0xc2fe
xorl %eax, %eax
callq 0x26fc
jmp 0x2d38
incq %r13
movq %r13, %rdi
movl $0x20, %esi
callq 0x20e0
testq %rax, %rax
je 0x2c60
movb $0x0, (%rax)
cmpb $0x0, (%r13)
je 0x2d5c
pxor %xmm0, %xmm0
movdqa %xmm0, 0x11e89(%rip)    # 0x14b00
movl $0xf, %edx
leaq 0x11e7d(%rip), %rdi     # 0x14b00
movq %r13, %rsi
callq 0x2120
leaq 0x9732(%rip), %rdi      # 0xc3c4
leaq 0x11e67(%rip), %rsi     # 0x14b00
xorl %eax, %eax
callq 0x26fc
jmp 0x2dad
movq %r13, %rbp
incq %rbp
movb $0x0, 0x9(%r13)
movq %rbp, %rdi
callq 0x2100
leaq -0x9(%rax), %rcx
cmpq $-0x7, %rcx
ja 0x2cf2
leaq 0x96af(%rip), %rdi      # 0xc378
movq %rbp, %rsi
xorl %eax, %eax
callq 0x26fc
jmp 0x2d38
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe55e(%rip)      # 0x11244
leaq 0x96f1(%rip), %rdi      # 0xc3de
jmp 0x2da4
leaq 0x11def(%rip), %rdi     # 0x14ae8
movq %rbp, %rsi
movq %rdi, %rbp
movq %rax, %rdx
callq 0x21b0
xorl %r13d, %r13d
movsbl (%r13,%rbp), %edi
callq 0x2430
movb %al, (%r13,%rbp)
incq %r13
cmpq $0x8, %r13
jne 0x2d0a
leaq 0x9668(%rip), %rdi      # 0xc392
movq %rbp, %rsi
xorl %eax, %eax
callq 0x26fc
incl 0x4(%rsp)
movl $0x454e574f, %ebp       # imm = 0x454E574F
jmp 0x2938
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe4f5(%rip)      # 0x11248
leaq 0x96a1(%rip), %rdi      # 0xc3fb
jmp 0x2da4
leaq 0x9645(%rip), %rdi      # 0xc3a8
movq %r13, %rsi
xorl %eax, %eax
callq 0x26fc
jmp 0x2938
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe4c9(%rip)      # 0x1124c
leaq 0x968c(%rip), %rdi      # 0xc416
jmp 0x2da4
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe4b3(%rip)      # 0x11250
leaq 0x9690(%rip), %rdi      # 0xc434
movl %eax, %esi
xorl %eax, %eax
callq 0x26fc
incl 0x4(%rsp)
jmp 0x2938
movl $0x1001, %edx           # imm = 0x1001
leaq 0x10cfe(%rip), %rdi     # 0x13ac0
xorl %esi, %esi
callq 0x2140
incq %r13
movl $0x1000, %edx           # imm = 0x1000
leaq 0x10ce8(%rip), %rdi     # 0x13ac0
movq %r13, %rsi
callq 0x2120
leaq 0x966d(%rip), %rdi      # 0xc454
leaq 0x10cd2(%rip), %rsi     # 0x13ac0
jmp 0x2c99
movl $0x1001, %edx           # imm = 0x1001
leaq 0xe621(%rip), %rdi      # 0x11420
xorl %esi, %esi
callq 0x2140
incq %r13
movl $0x1000, %edx           # imm = 0x1000
leaq 0xe60b(%rip), %rdi      # 0x11420
movq %r13, %rsi
callq 0x2120
leaq 0x9640(%rip), %rdi      # 0xc464
leaq 0xe5f5(%rip), %rsi      # 0x11420
jmp 0x2c99
movl $0x1001, %edx           # imm = 0x1001
leaq 0xf5f4(%rip), %rbp      # 0x12430
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2140
incq %r13
movl $0x1000, %edx           # imm = 0x1000
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2120
leaq 0x9615(%rip), %rdi      # 0xc475
jmp 0x2d2a
movq %r15, %rdi
callq 0x2200
cmpw $0xb, 0x4(%rsp)
jne 0x2ea8
movl 0xe3cd(%rip), %eax      # 0x11248
cmpl 0xe3c3(%rip), %eax      # 0x11244
jne 0x2fbf
leaq 0x962d(%rip), %rdi      # 0xc4bb
xorl %eax, %eax
callq 0x26fc
jmp 0x2eb9
leaq 0x93fa(%rip), %rdi      # 0xc298
jmp 0x2eaf
movq %r15, %rdi
callq 0x2200
leaq 0x95ed(%rip), %rdi      # 0xc49c
movq %r14, %rsi
xorl %eax, %eax
callq 0x26fc
movq 0x8(%rbx), %rsi
leaq 0x92dd(%rip), %rdi      # 0xc1a1
xorl %eax, %eax
callq 0x26fc
movl $0x1, %ebx
movl 0xe362(%rip), %edi      # 0x11238
cmpl $-0x1, %edi
je 0x2ee0
callq 0x2440
movl 0xe356(%rip), %edi      # 0x1123c
cmpl $-0x1, %edi
je 0x2ef0
callq 0x2440
cmpl $-0x1, 0xe349(%rip)     # 0x11240
je 0x2f6e
movl $0x180005, 0x107bd(%rip) # imm = 0x180005
movb $0x0, 0x107ba(%rip)     # 0x136c4
movq 0xe3a7(%rip), %r14      # 0x112b8
leaq 0xe390(%rip), %r12      # 0x112a8
cmpq %r12, %r14
je 0x2f57
leaq 0x1079c(%rip), %r15     # 0x136c0
movq 0x40(%r14), %r8
movl 0xe312(%rip), %edi      # 0x11240
addq $0x18, %r8
movl $0x5, %edx
movq %r15, %rsi
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x2060
movq %r14, %rdi
callq 0x2170
movq %rax, %r14
cmpq %r12, %rax
jne 0x2f24
leaq 0xe342(%rip), %rdi      # 0x112a0
callq 0xb2ba
movl 0xe2d7(%rip), %edi      # 0x11240
callq 0x2440
leaq 0x10b4b(%rip), %rdi     # 0x13ac0
leaq 0x92e5(%rip), %rsi      # 0xc261
callq 0x2270
movq %rax, 0x11b40(%rip)     # 0x14ac8
testq %rax, %rax
je 0x2f97
movq %rax, %rdi
callq 0x2200
jmp 0x2fac
leaq 0x92c5(%rip), %rdi      # 0xc263
leaq 0x10b1b(%rip), %rsi     # 0x13ac0
xorl %eax, %eax
callq 0x26fc
leaq 0x92d4(%rip), %rdi      # 0xc287
xorl %eax, %eax
callq 0x26fc
jmp 0x2879
callq 0x30cb
testl %eax, %eax
je 0x2fdb
leaq 0x91f4(%rip), %rdi      # 0xc1c3
leaq 0xe44a(%rip), %rsi      # 0x11420
jmp 0x2ec4
callq 0x333a
testl %eax, %eax
je 0x2ff7
leaq 0x91d8(%rip), %rdi      # 0xc1c3
leaq 0xf43e(%rip), %rsi      # 0x12430
jmp 0x2ec4
callq 0x36c6
testl %eax, %eax
je 0x3009
leaq 0x91cf(%rip), %rdi      # 0xc1d6
jmp 0x302b
callq 0x37a8
testl %eax, %eax
je 0x301b
leaq 0x91d0(%rip), %rdi      # 0xc1e9
jmp 0x302b
callq 0x388a
testl %eax, %eax
je 0x3037
leaq 0x91d1(%rip), %rdi      # 0xc1fc
xorl %eax, %eax
callq 0x26fc
jmp 0x2ecb
xorl %eax, %eax
leaq 0x10400(%rip), %rcx     # 0x13440
leaq 0x10539(%rip), %rdx     # 0x13580
pxor %xmm0, %xmm0
movdqu %xmm0, 0x2c(%rax,%rcx)
movdqa %xmm0, 0x20(%rax,%rcx)
movdqa %xmm0, 0x10(%rax,%rcx)
movdqa %xmm0, (%rax,%rcx)
movdqa %xmm0, (%rax,%rdx)
movdqa %xmm0, 0x10(%rax,%rdx)
movdqa %xmm0, 0x20(%rax,%rdx)
movdqu %xmm0, 0x2e(%rax,%rdx)
addq $0x40, %rax
cmpq $0x140, %rax            # imm = 0x140
jne 0x304b
leaq 0x9183(%rip), %rdi      # 0xc20f
leaq 0x91ad(%rip), %rsi      # 0xc240
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x26fc
callq 0x3952
callq 0x3be1
leaq 0x9198(%rip), %rdi      # 0xc245
xorl %eax, %eax
callq 0x26fc
jmp 0x2ed0