// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xa8, %rsp
cmpl $0x1, %edi
jg 0x29bbb
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x299c9
jmp 0x2a087
movq %rsi, %rbx
movl %edi, %ebp
cmpl $0x4, %edi
je 0x29bef
cmpl $0x2, %ebp
jne 0x29ce5
movq 0x8(%rbx), %rdi
leaq 0xb2160(%rip), %rsi     # 0xdbd39
callq 0x1b500
testl %eax, %eax
je 0x29e90
cmpl $0x4, %ebp
jne 0x29ce5
movq 0x10(%rbx), %rsi
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0xabd20
leaq 0x28(%rsp), %rdi
callq 0x2a4ea
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x29c32
movq (%rdi), %rax
leaq 0x18(%rsp), %rdx
movl $0xfefc5245, %esi       # imm = 0xFEFC5245
callq *0x28(%rax)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2a097
leaq 0x8(%rsp), %rdx
movq $0x0, (%rdx)
movq (%rdi), %rax
movl $0x28c07f90, %esi       # imm = 0x28C07F90
callq *0x20(%rax)
cmpq $0x0, 0x8(%rsp)
je 0x2a0cb
movq 0x8(%rbx), %r14
leaq 0xb2130(%rip), %rsi     # 0xdbd9e
movq %r14, %rdi
callq 0x1b500
testl %eax, %eax
je 0x29d35
leaq 0xb2135(%rip), %rsi     # 0xdbdba
movq %r14, %rdi
callq 0x1b500
testl %eax, %eax
je 0x29e9c
leaq 0xfc7e4(%rip), %rbx     # 0x126480
leaq 0xb209c(%rip), %rsi     # 0xdbd3f
movl $0xb, %edx
movq %rbx, %rdi
callq 0x98d30
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x79e80
movsbl %al, %esi
leaq 0xfc7b2(%rip), %rdi     # 0x126480
callq 0x98830
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x97e00
jmp 0x2a041
leaq 0xfc794(%rip), %rbx     # 0x126480
leaq 0xb204c(%rip), %rsi     # 0xdbd3f
movl $0xb, %edx
movq %rbx, %rdi
callq 0x98d30
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x79e80
movsbl %al, %esi
leaq 0xfc762(%rip), %rdi     # 0x126480
callq 0x98830
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x97e00
jmp 0x2a087
movq 0x18(%rbx), %rsi
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0xabd20
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x29d5b
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x60(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x88(%rsp), %rsi
callq 0x29a48
testq %r15, %r15
je 0x29d7e
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x60(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x20128
leaq 0x48(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x2a59a
leaq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq %rax, 0x20(%rsp)
movq $0x0, (%rdi)
callq 0x2ab4a
movq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x2a6be
movq 0x10(%rsp), %rbx
leaq 0x20(%rsp), %rdi
callq 0x2a724
movl %eax, 0x1c(%rbx)
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2a7ea
movq 0x48(%rsp), %rbx
movq 0x50(%rsp), %r14
cmpq %r14, %rbx
je 0x29e0e
movq 0x10(%rsp), %rdi
addq $0x8, %rdi
movl (%rbx), %esi
callq 0x2a9d4
addq $0x4, %rbx
jmp 0x29df3
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x29e1d
callq 0x2c860
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rax
leaq 0x10(%rax), %rsi
testq %rax, %rax
cmoveq %rax, %rsi
movq (%rdi), %rax
callq *0x28(%rax)
testl %eax, %eax
je 0x29f30
leaq 0xfc639(%rip), %rbx     # 0x126480
leaq 0xb1f55(%rip), %rsi     # 0xdbda3
movl $0x16, %edx
movq %rbx, %rdi
callq 0x98d30
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x79e80
movsbl %al, %esi
leaq 0xfc607(%rip), %rdi     # 0x126480
callq 0x98830
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x97e00
jmp 0x29f71
xorl %ebx, %ebx
callq 0x299c9
jmp 0x2a087
movq 0x18(%rbx), %rsi
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0xabd20
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x29ec2
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x38(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x88(%rsp), %rsi
callq 0x29a48
testq %r15, %r15
je 0x29ee5
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x38(%rsp)
movq 0x18(%rsp), %rdi
movq 0x70(%rsp), %rax
testl %eax, %eax
je 0x29f94
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq 0x68(%rsp), %rcx
xorl %edx, %edx
leaq 0xb240d(%rip), %r8      # 0xdc320
movb (%rcx,%rdx), %r9b
xorb %sil, %r9b
movzbl %r9b, %r9d
shrl $0x8, %esi
xorl (%r8,%r9,4), %esi
incq %rdx
cmpl %edx, %eax
jne 0x29f13
notl %esi
jmp 0x29f96
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x29f43
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x40(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x88(%rsp), %rsi
callq 0x29af1
testq %r15, %r15
je 0x29f66
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x40(%rsp)
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdi
callq 0x2ab4a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2a02e
movq (%rdi), %rax
callq *0x20(%rax)
jmp 0x2a02e
xorl %esi, %esi
movq (%rdi), %rax
callq *0x30(%rax)
testl %eax, %eax
je 0x29fed
leaq 0xfc4d9(%rip), %rbx     # 0x126480
leaq 0xb1df5(%rip), %rsi     # 0xdbda3
movl $0x16, %edx
movq %rbx, %rdi
callq 0x98d30
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x79e80
movsbl %al, %esi
leaq 0xfc4a7(%rip), %rdi     # 0x126480
callq 0x98830
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x97e00
jmp 0x2a02e
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x2a000
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x88(%rsp), %rsi
callq 0x29af1
testq %r15, %r15
je 0x2a023
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x30(%rsp)
xorl %ebx, %ebx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a041
callq 0x2c860
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2a051
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2a061
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2a071
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a087
callq 0x2c860
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x2cb60
movq %rax, %r15
leaq 0xb1ca0(%rip), %rsi     # 0xdbd4b
movq %rax, %rdi
callq 0x40360
leaq 0xf4fb6(%rip), %rsi     # 0x11f070
leaq 0xc91f(%rip), %rdx      # 0x369e0
movq %r15, %rdi
callq 0x2dbb0
jmp 0x2a0fd
movl $0x10, %edi
callq 0x2cb60
movq %rax, %r15
leaq 0xb1c83(%rip), %rsi     # 0xdbd62
movq %rax, %rdi
callq 0x40360
leaq 0xf4f82(%rip), %rsi     # 0x11f070
leaq 0xc8eb(%rip), %rdx      # 0x369e0
movq %r15, %rdi
callq 0x2dbb0
jmp 0x2a21f
jmp 0x2a21f
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x2a11b
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x30(%rsp)
jmp 0x2a2a5
jmp 0x2a21f
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x2a142
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x40(%rsp)
jmp 0x2a282
jmp 0x2a21f
jmp 0x2a21f
jmp 0x2a21f
jmp 0x2a21f
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x2a178
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x38(%rsp)
jmp 0x2a2a5
jmp 0x2a21f
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a1d1
jmp 0x2a252
jmp 0x2a21f
jmp 0x2a25a
jmp 0x2a21f
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a28c
jmp 0x2a24a
movq %rdx, %r14
movq %rax, %rbx
testq %r15, %r15
je 0x2a1c8
movq (%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movq $0x0, 0x60(%rsp)
cmpl $0x1, %r14d
jne 0x2a2a5
movq %rbx, %rdi
callq 0x2ccc0
callq 0x2cd30
jmp 0x29d87
jmp 0x2a21f
jmp 0x2a24a
jmp 0x2a252
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2cbc0
jmp 0x2a2b8
jmp 0x2a232
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2cbc0
jmp 0x2a2d1
jmp 0x2a21f
jmp 0x2a21f
movq %rax, %rdi
callq 0x2087b
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a2ea
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a2d1
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a303
jmp 0x2a262
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a2a5
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a2b8
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a282
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2a319
movq %rdx, %r14
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2a282
callq 0x2c860
leaq 0x20(%rsp), %rdi
callq 0x2ab4a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2a29c
movq (%rdi), %rax
callq *0x20(%rax)
movq $0x0, 0x10(%rsp)
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a2b8
callq 0x2c860
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2a2c8
movq (%rdi), %rax
callq *0x18(%rax)
movq $0x0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2a2e1
movq (%rdi), %rax
callq *0x18(%rax)
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2a2fa
movq (%rdi), %rax
callq *0x20(%rax)
movq $0x0, 0x28(%rsp)
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a319
callq 0x2c860
cmpl $0x1, %r14d
jne 0x2a374
movq %rbx, %rdi
callq 0x2ccc0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0xfc149(%rip), %rdi     # 0x126480
movq %rax, %rsi
callq 0x99260
movq %rax, %rdi
callq 0x98b40
callq 0x2cd30
xorl %ebx, %ebx
jmp 0x2a087
jmp 0x2a21f
jmp 0x2a21f
jmp 0x2a21f
jmp 0x2a21f
jmp 0x2a21f
movq %rax, %rbx
callq 0x2cd30
movq %rbx, %rdi
callq 0xd7070
jmp 0x2a21f
nop