// File: /workspace/github_cpp_makefile_star2_O1/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 0x990e(%rip), %rsi      # 0xc0c4
movl $0x9, %edx
callq 0x2250
testl %eax, %eax
je 0x27f4
leaq 0x9944(%rip), %rdi      # 0xc10f
xorl %eax, %eax
callq 0x26fc
jmp 0x2874
leaq 0xa996(%rip), %rdi      # 0xd174
callq 0x2360
leaq 0xa9a5(%rip), %rdi      # 0xd18f
callq 0x2360
jmp 0x2874
callq 0x2070
leaq 0x905(%rip), %rax       # 0x3105
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 0x98ef(%rip), %rdi      # 0xc134
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 0x98e8(%rip), %rdi      # 0xc155
xorl %eax, %eax
callq 0x26fc
movl $0x1, %ebp
movl %ebp, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %r14
leaq 0x99d2(%rip), %rsi      # 0xc26a
movq %r14, %rdi
callq 0x2270
testq %rax, %rax
je 0x2ed2
movq %rax, %r15
leaq 0x99d1(%rip), %rdi      # 0xc284
xorl %r13d, %r13d
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 0x2e9e
leaq 0x10(%rsp), %r12
movl $0x454e574f, %ebp       # imm = 0x454E574F
xorl %r13d, %r13d
movl %r13d, 0x4(%rsp)
movq %r12, %rdi
movl $0x23, %esi
callq 0x20e0
testq %rax, %rax
jne 0x293b
movq %r12, %rdi
movl $0xd, %esi
callq 0x20e0
testq %rax, %rax
je 0x2914
movb $0x0, (%rax)
movq %r12, %rdi
movl $0xa, %esi
callq 0x20e0
testq %rax, %rax
je 0x2929
movb $0x0, (%rax)
movq %r12, %rdi
movl $0x3d, %esi
callq 0x20e0
testq %rax, %rax
jne 0x2955
movq %r12, %rdi
movl $0x3fc, %esi            # imm = 0x3FC
movq %r15, %rdx
callq 0x23a0
testq %rax, %rax
jne 0x28ed
jmp 0x2e99
movq %rax, %r13
movb $0x0, (%rax)
movl 0x10(%rsp), %eax
xorl %ebp, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x52, %ecx
orl %eax, %ecx
je 0x2aeb
movl 0x10(%rsp), %eax
movl $0x494d4441, %ecx       # imm = 0x494D4441
xorl %ecx, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x4e, %ecx
orl %eax, %ecx
je 0x2be7
movq 0x10(%rsp), %rax
movabsq $0x495f4e455453494c, %rcx # imm = 0x495F4E455453494C
xorq %rcx, %rax
movzwl 0x18(%rsp), %ecx
xorq $0x50, %rcx
orq %rax, %rcx
je 0x2c50
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 0x2cd6
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 0x2d40
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 0x95db(%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 0x2dd3
movl 0x10(%rsp), %eax
movl $0x52455355, %ecx       # imm = 0x52455355
xorl %ecx, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x53, %ecx
orl %eax, %ecx
je 0x2e10
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 0x2e4d
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 0x2c46
movsbl 0x1(%r13), %esi
cmpl $0x59, %esi
sete 0x12038(%rip)           # 0x14b10
leaq 0x9981(%rip), %rdi      # 0xc460
xorl %eax, %eax
callq 0x26fc
jmp 0x2e87
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x11fdc(%rip)     # 0x14ad8
movb $0x0, 0x11fdd(%rip)     # 0x14ae0
incq %r13
movq %r13, %rdi
movl $0x20, %esi
callq 0x20e0
testq %rax, %rax
je 0x2b1b
movb $0x0, (%rax)
movq %r13, %rdi
callq 0x2100
cmpq $0x6, %rax
jne 0x2c1d
movq %r14, 0x8(%rsp)
movzwl 0x4(%r13), %eax
movw %ax, 0x11f9e(%rip)      # 0x14adc
movl (%r13), %eax
movl %eax, 0x11f90(%rip)     # 0x14ad8
testb %al, %al
leaq 0x11f87(%rip), %r14     # 0x14ad8
je 0x2b7e
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 0x2b5a
movl 0x11f54(%rip), %eax     # 0x14ad8
movl $0x5258, %ecx           # imm = 0x5258
xorl %ecx, %eax
movzbl 0x11f48(%rip), %ecx     # 0x14ada
xorl $0x46, %ecx
orw %ax, %cx
movq 0x8(%rsp), %r14
jne 0x2c38
movsbl 0x11f31(%rip), %eax     # 0x14adb
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2c38
movsbl 0x11f1f(%rip), %eax     # 0x14adc
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2c38
movsbl 0x11f11(%rip), %eax     # 0x14add
addl $-0x30, %eax
cmpl $0xa, %eax
jae 0x2c38
leaq 0x973a(%rip), %rdi      # 0xc315
leaq 0x11ef6(%rip), %rsi     # 0x14ad8
jmp 0x2e80
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x11ef0(%rip)     # 0x14ae8
movb $0x0, 0x11ef1(%rip)     # 0x14af0
cmpb $0x20, 0x1(%r13)
jne 0x2ca6
leaq 0x9714(%rip), %rdi      # 0xc325
xorl %eax, %eax
callq 0x26fc
jmp 0x2d6b
leaq 0x9677(%rip), %rdi      # 0xc29b
movq %r13, %rsi
movl $0x6, %edx
xorl %eax, %eax
callq 0x26fc
jmp 0x2d6b
leaq 0x9693(%rip), %rdi      # 0xc2d2
xorl %eax, %eax
callq 0x26fc
movl $0x454e574f, %ebp       # imm = 0x454E574F
jmp 0x2d6b
incq %r13
movq %r13, %rdi
movl $0x20, %esi
callq 0x20e0
testq %rax, %rax
je 0x2c68
movb $0x0, (%rax)
cmpb $0x0, (%r13)
je 0x2d5a
pxor %xmm0, %xmm0
movdqa %xmm0, 0x11e81(%rip)    # 0x14b00
movl $0xf, %edx
leaq 0x11e75(%rip), %rdi     # 0x14b00
movq %r13, %rsi
callq 0x2120
leaq 0x96fe(%rip), %rdi      # 0xc398
leaq 0x11e5f(%rip), %rsi     # 0x14b00
jmp 0x2d37
movq %r13, %rdi
incq %rdi
movb $0x0, 0x9(%r13)
movq %rdi, 0x8(%rsp)
callq 0x2100
leaq -0x9(%rax), %rcx
cmpq $-0x7, %rcx
ja 0x2cf3
leaq 0x9680(%rip), %rdi      # 0xc34c
movq 0x8(%rsp), %rsi
jmp 0x2d64
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe55d(%rip)      # 0x11244
leaq 0x96c4(%rip), %rdi      # 0xc3b2
jmp 0x2da4
leaq 0x11dee(%rip), %r13     # 0x14ae8
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0x21b0
movq %r13, %rsi
xorl %r13d, %r13d
movsbl (%r13,%rsi), %edi
callq 0x2430
leaq 0x11dc6(%rip), %rsi     # 0x14ae8
movb %al, (%r13,%rsi)
incq %r13
cmpq $0x8, %r13
jne 0x2d10
leaq 0x962f(%rip), %rdi      # 0xc366
xorl %eax, %eax
callq 0x26fc
jmp 0x2dad
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe4f7(%rip)      # 0x11248
leaq 0x9677(%rip), %rdi      # 0xc3cf
jmp 0x2da4
leaq 0x961b(%rip), %rdi      # 0xc37c
movq %r13, %rsi
xorl %eax, %eax
callq 0x26fc
movl 0x4(%rsp), %r13d
jmp 0x2db5
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe4c9(%rip)      # 0x1124c
leaq 0x9660(%rip), %rdi      # 0xc3ea
jmp 0x2da4
incq %r13
movq %r13, %rdi
callq 0x2380
movl %eax, 0xe4b3(%rip)      # 0x11250
leaq 0x9664(%rip), %rdi      # 0xc408
movl %eax, %esi
xorl %eax, %eax
callq 0x26fc
movl 0x4(%rsp), %r13d
incl %r13d
movq %r12, %rdi
movl $0x3fc, %esi            # imm = 0x3FC
movq %r15, %rdx
callq 0x23a0
testq %rax, %rax
jne 0x28e8
jmp 0x2e9e
movl $0x1001, %edx           # imm = 0x1001
leaq 0x10ce1(%rip), %rdi     # 0x13ac0
xorl %esi, %esi
callq 0x2140
incq %r13
movl $0x1000, %edx           # imm = 0x1000
leaq 0x10ccb(%rip), %rdi     # 0x13ac0
movq %r13, %rsi
callq 0x2120
leaq 0x9624(%rip), %rdi      # 0xc428
leaq 0x10cb5(%rip), %rsi     # 0x13ac0
jmp 0x2d37
movl $0x1001, %edx           # imm = 0x1001
leaq 0xe604(%rip), %rdi      # 0x11420
xorl %esi, %esi
callq 0x2140
incq %r13
movl $0x1000, %edx           # imm = 0x1000
leaq 0xe5ee(%rip), %rdi      # 0x11420
movq %r13, %rsi
callq 0x2120
leaq 0x95f7(%rip), %rdi      # 0xc438
leaq 0xe5d8(%rip), %rsi      # 0x11420
jmp 0x2d37
movl $0x1001, %edx           # imm = 0x1001
leaq 0xf5d7(%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 0x95cc(%rip), %rdi      # 0xc449
movq %rbp, %rsi
xorl %eax, %eax
callq 0x26fc
movl 0x4(%rsp), %r13d
incl %r13d
movl $0x454e574f, %ebp       # imm = 0x454E574F
jmp 0x2db5
movl 0x4(%rsp), %r13d
movq %r15, %rdi
callq 0x2200
cmpw $0xb, %r13w
jne 0x2edb
movl 0xe395(%rip), %eax      # 0x11248
cmpl 0xe38b(%rip), %eax      # 0x11244
jne 0x3037
leaq 0x95c9(%rip), %rdi      # 0xc48f
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x26fc
jmp 0x2eef
leaq 0x9393(%rip), %rdi      # 0xc26c
jmp 0x2ee2
leaq 0x958e(%rip), %rdi      # 0xc470
xorl %r15d, %r15d
movq %r14, %rsi
xorl %eax, %eax
callq 0x26fc
movl $0x1, %ebp
testb %r15b, %r15b
je 0x2f18
callq 0x3117
testl %eax, %eax
je 0x3019
movl %eax, %ebp
leaq 0x9288(%rip), %rdi      # 0xc197
leaq 0xe50a(%rip), %rsi      # 0x11420
jmp 0x2f23
movq 0x8(%rbx), %rsi
leaq 0x9252(%rip), %rdi      # 0xc175
xorl %eax, %eax
callq 0x26fc
movl 0xe308(%rip), %edi      # 0x11238
cmpl $-0x1, %edi
je 0x2f3a
callq 0x2440
movl 0xe2fc(%rip), %edi      # 0x1123c
cmpl $-0x1, %edi
je 0x2f4a
callq 0x2440
cmpl $-0x1, 0xe2ef(%rip)     # 0x11240
je 0x2fc8
movl $0x180005, 0x10763(%rip) # imm = 0x180005
movb $0x0, 0x10760(%rip)     # 0x136c4
movq 0xe34d(%rip), %rbx      # 0x112b8
leaq 0xe336(%rip), %r15      # 0x112a8
cmpq %r15, %rbx
je 0x2fb1
leaq 0x10742(%rip), %r14     # 0x136c0
movq 0x40(%rbx), %r8
movl 0xe2b8(%rip), %edi      # 0x11240
addq $0x18, %r8
movl $0x5, %edx
movq %r14, %rsi
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x2060
movq %rbx, %rdi
callq 0x2170
movq %rax, %rbx
cmpq %r15, %rax
jne 0x2f7e
leaq 0xe2e8(%rip), %rdi      # 0x112a0
callq 0xb342
movl 0xe27d(%rip), %edi      # 0x11240
callq 0x2440
leaq 0x10af1(%rip), %rdi     # 0x13ac0
leaq 0x925f(%rip), %rsi      # 0xc235
callq 0x2270
movq %rax, 0x11ae6(%rip)     # 0x14ac8
testq %rax, %rax
je 0x2ff1
movq %rax, %rdi
callq 0x2200
jmp 0x3006
leaq 0x923f(%rip), %rdi      # 0xc237
leaq 0x10ac1(%rip), %rsi     # 0x13ac0
xorl %eax, %eax
callq 0x26fc
leaq 0x924e(%rip), %rdi      # 0xc25b
xorl %eax, %eax
callq 0x26fc
jmp 0x2879
callq 0x3386
testl %eax, %eax
je 0x3041
movl %eax, %ebp
leaq 0x916c(%rip), %rdi      # 0xc197
leaq 0xf3fe(%rip), %rsi      # 0x12430
jmp 0x2f23
xorl %ebp, %ebp
movb $0x1, %r15b
jmp 0x2ef4
callq 0x35b6
testl %eax, %eax
je 0x3058
movl %eax, %ebp
leaq 0x9157(%rip), %rdi      # 0xc1aa
jmp 0x30f9
callq 0x3692
testl %eax, %eax
je 0x306f
movl %eax, %ebp
leaq 0x9153(%rip), %rdi      # 0xc1bd
jmp 0x30f9
callq 0x376e
testl %eax, %eax
je 0x3083
movl %eax, %ebp
leaq 0x914f(%rip), %rdi      # 0xc1d0
jmp 0x30f9
xorl %eax, %eax
leaq 0x103b4(%rip), %rcx     # 0x13440
leaq 0x104ed(%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 0x3097
leaq 0x910b(%rip), %rdi      # 0xc1e3
leaq 0x9135(%rip), %rsi      # 0xc214
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x26fc
callq 0x3834
callq 0x3ac3
leaq 0x9120(%rip), %rdi      # 0xc219
xorl %eax, %eax
callq 0x26fc
jmp 0x2f2a