// File: /workspace/github_cpp_makefile_star2_O3/tdv[P]boss/boss/src/regtool/main.cpp
// Function: main
int main(int argc, char const **argv)
{
  try
  {
    if (argc < 2)
    {
      ShowHelp();
      return -1;
    }
    
    if (argc == 2 && !std::strcmp(argv[1], "-help"))
    {
      ShowHelp();
      return 0;
    }
    
    if (argc != 4)
    {
      std::cout << "Bad params." << std::endl;
      return -1;
    }
    
    std::string RegistryFilePath = argv[2];

    auto Reg = Boss::Base<Boss::ServiceRegistry>::Create();
    Boss::RefObjQIPtr<Boss::IServiceRegistryCtrl> Ctrl(Reg);    
    if (!Ctrl.Get())
      throw std::runtime_error("Failed to get RegCtrl.");
    Boss::RefObjQIPtr<Boss::ISerializable> Serializable(Ctrl);
    if (!Serializable.Get())
      throw std::runtime_error("Failed to get ISerializable interface from Registry object.");
    
    if (!std::strcmp(argv[1], "-reg"))
    {
      std::string ModulePath = argv[3];
      
      try
      {
        Load(Serializable, RegistryFilePath);
      }
      catch (std::exception const &)
      {
      }

      auto Info = Boss::Base<Boss::LocalServiceInfo>::Create();
      {
        auto Module = Boss::ModuleHolder(std::move(Boss::DllHolder(ModulePath)));
        
        Info->SetModulePath(ModulePath);
        Info->SetServiceId(Module.GetServiceId());
        
        for (auto const &i : Module.GetClassIds())
          Info->AddCoClassId(i);
        
        if (Ctrl->AddService(Info.Get()) != Boss::Status::Ok)
        {
          std::cout << "Failed to reg service." << std::endl;
          return -1;
        }
        
        Save(Serializable, RegistryFilePath);
      }
      return 0;
    }
    if (!std::strcmp(argv[1], "-unreg"))
    {
      std::string ServiceName = argv[3];
      
      Load(Serializable, RegistryFilePath);
      
      if (Ctrl->DelService(Boss::Crc32(ServiceName.c_str(), ServiceName.length())) != Boss::Status::Ok)
      {
        std::cout << "Failed to reg service." << std::endl;
        return -1;
      }
      
      Save(Serializable, RegistryFilePath);

      return 0;
    }
    
    std::cout << "Bad params." << std::endl;
    return -1;
    
  }
  catch (std::exception const &e)
  {
    std::cout << e.what() << std::endl;
  }
  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xa0, %rsp
cmpl $0x1, %edi
jg 0x27422
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x27231
jmp 0x278dd
movq %rsi, %rbx
cmpl $0x4, %edi
je 0x27497
cmpl $0x2, %edi
jne 0x27447
movq 0x8(%rbx), %rdi
leaq 0xb18ff(%rip), %rsi     # 0xd8d39
callq 0x19500
testl %eax, %eax
je 0x2758a
leaq 0xfa032(%rip), %rbx     # 0x121480
leaq 0xb18ea(%rip), %rsi     # 0xd8d3f
movl $0xb, %edx
movq %rbx, %rdi
callq 0x964b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x77600
movsbl %al, %esi
leaq 0xfa000(%rip), %rdi     # 0x121480
callq 0x95fb0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x95580
jmp 0x278dd
movq 0x10(%rbx), %rsi
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0xa94a0
leaq 0x20(%rsp), %rdi
callq 0x27d14
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x278ec
movq (%rdi), %rax
leaq 0x10(%rsp), %rdx
movl $0xfefc5245, %esi       # imm = 0xFEFC5245
callq *0x28(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x278ec
movq %rsp, %rdx
movq $0x0, (%rdx)
movq (%rdi), %rax
movl $0x28c07f90, %esi       # imm = 0x28C07F90
callq *0x20(%rax)
cmpq $0x0, (%rsp)
je 0x27920
movq 0x8(%rbx), %r14
leaq 0xb1887(%rip), %rsi     # 0xd8d9e
movq %r14, %rdi
callq 0x19500
testl %eax, %eax
je 0x27596
leaq 0xb1890(%rip), %rsi     # 0xd8dba
movq %r14, %rdi
callq 0x19500
testl %eax, %eax
je 0x276f6
leaq 0xf9f3f(%rip), %rbx     # 0x121480
leaq 0xb17f7(%rip), %rsi     # 0xd8d3f
movl $0xb, %edx
movq %rbx, %rdi
callq 0x964b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x77600
movsbl %al, %esi
leaq 0xf9f0d(%rip), %rdi     # 0x121480
callq 0x95fb0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x95580
jmp 0x27898
xorl %ebx, %ebx
callq 0x27231
jmp 0x278dd
movq 0x18(%rbx), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0xa94a0
movq (%rsp), %r15
testq %r15, %r15
je 0x275bb
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x58(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x80(%rsp), %rsi
callq 0x272b0
testq %r15, %r15
je 0x275de
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x58(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x1ddc0
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x27dc4
leaq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
movq $0x0, (%rdi)
callq 0x28368
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x27ef4
movq 0x8(%rsp), %rbx
leaq 0x18(%rsp), %rdi
callq 0x27f52
movl %eax, 0x1c(%rbx)
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x28018
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %r14
cmpq %r14, %rbx
je 0x27676
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
movl (%rbx), %esi
callq 0x28208
addq $0x4, %rbx
cmpq %r14, %rbx
jne 0x27658
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x27683
movq %rbx, %rdi
callq 0x29fe0
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %rsi
testq %rax, %rax
cmoveq %rax, %rsi
movq (%rdi), %rax
callq *0x28(%rax)
testl %eax, %eax
je 0x27789
leaq 0xf9dd3(%rip), %rbx     # 0x121480
leaq 0xb16ef(%rip), %rsi     # 0xd8da3
movl $0x16, %edx
movq %rbx, %rdi
callq 0x964b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x77600
movsbl %al, %esi
leaq 0xf9da1(%rip), %rdi     # 0x121480
callq 0x95fb0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x95580
jmp 0x277c9
movq 0x18(%rbx), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0xa94a0
movq (%rsp), %r15
testq %r15, %r15
je 0x2771b
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x80(%rsp), %rsi
callq 0x272b0
testq %r15, %r15
je 0x2773e
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x30(%rsp)
movq 0x10(%rsp), %rdi
movq 0x68(%rsp), %rax
testl %eax, %eax
je 0x277ec
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rcx
xorl %edx, %edx
leaq 0xb1bb4(%rip), %r8      # 0xd9320
movb (%rcx,%rdx), %r9b
xorb %sil, %r9b
movzbl %r9b, %r9d
shrl $0x8, %esi
xorl (%r8,%r9,4), %esi
incq %rdx
cmpl %edx, %eax
jne 0x2776c
notl %esi
jmp 0x277ee
movq (%rsp), %r15
testq %r15, %r15
je 0x2779b
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x38(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x80(%rsp), %rsi
callq 0x27359
testq %r15, %r15
je 0x277be
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x38(%rsp)
xorl %ebx, %ebx
leaq 0x18(%rsp), %rdi
callq 0x28368
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x27885
movq (%rdi), %rax
callq *0x20(%rax)
jmp 0x27885
xorl %esi, %esi
movq (%rdi), %rax
callq *0x30(%rax)
testl %eax, %eax
je 0x27845
leaq 0xf9c81(%rip), %rbx     # 0x121480
leaq 0xb159d(%rip), %rsi     # 0xd8da3
movl $0x16, %edx
movq %rbx, %rdi
callq 0x964b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x77600
movsbl %al, %esi
leaq 0xf9c4f(%rip), %rdi     # 0x121480
callq 0x95fb0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x95580
jmp 0x27885
movq (%rsp), %r15
testq %r15, %r15
je 0x27857
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x28(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x80(%rsp), %rsi
callq 0x27359
testq %r15, %r15
je 0x2787a
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x28(%rsp)
xorl %ebx, %ebx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x27898
callq 0x29fe0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x278a7
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x278b7
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x278c7
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x278dd
callq 0x29fe0
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl $0x10, %edi
callq 0x2a2e0
movq %rax, %r15
leaq 0xb144b(%rip), %rsi     # 0xd8d4b
movq %rax, %rdi
callq 0x3dae0
leaq 0xf2761(%rip), %rsi     # 0x11a070
leaq 0xc84a(%rip), %rdx      # 0x34160
movq %r15, %rdi
callq 0x2b330
jmp 0x27952
movl $0x10, %edi
callq 0x2a2e0
movq %rax, %r15
leaq 0xb142e(%rip), %rsi     # 0xd8d62
movq %rax, %rdi
callq 0x3dae0
leaq 0xf272d(%rip), %rsi     # 0x11a070
leaq 0xc816(%rip), %rdx      # 0x34160
movq %r15, %rdi
callq 0x2b330
jmp 0x27a59
jmp 0x27a59
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x27970
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x28(%rsp)
jmp 0x27ae3
jmp 0x27a59
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x27997
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x38(%rsp)
jmp 0x27ac9
jmp 0x27a59
jmp 0x27a59
jmp 0x27a59
jmp 0x27a59
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x279cd
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x30(%rsp)
jmp 0x27ae3
jmp 0x27a59
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27a20
jmp 0x27aa4
jmp 0x27a59
jmp 0x27aac
jmp 0x27a59
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27ad3
jmp 0x27a9c
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x27a17
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x58(%rsp)
cmpl $0x1, %r14d
jne 0x27ae3
movq %rbx, %rdi
callq 0x2a440
callq 0x2a4b0
jmp 0x275e7
jmp 0x27a59
jmp 0x27a9c
jmp 0x27aa4
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2a340
jmp 0x27af6
jmp 0x27a59
jmp 0x27a59
movq %rax, %rdi
callq 0x1e4f5
jmp 0x27a63
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27b05
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2a340
jmp 0x27b05
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27b15
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27b25
jmp 0x27b56
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27ae3
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27af6
movq %rdx, %r14
movq %rax, %rbx
jmp 0x27ac9
movq %rdx, %r14
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x27ac9
callq 0x29fe0
leaq 0x18(%rsp), %rdi
callq 0x28368
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x27ae3
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x27af6
callq 0x29fe0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x27b05
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27b15
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x27b25
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x27b5c
callq 0x29fe0
jmp 0x27b5c
jmp 0x27a59
jmp 0x27a59
jmp 0x27a59
jmp 0x27a59
jmp 0x27a59
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x27b9e
movq %rbx, %rdi
callq 0x2a440
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0xf9906(%rip), %rdi     # 0x121480
movq %rax, %rsi
callq 0x969e0
movq %rax, %rdi
callq 0x962c0
callq 0x2a4b0
xorl %ebx, %ebx
jmp 0x278dd
movq %rax, %rbx
callq 0x2a4b0
movq %rbx, %rdi
callq 0xd47f0
jmp 0x27a59
nop