// File: /workspace/github_cpp_makefile_star2_O2/jkom-cloud[P]mmseg/src/main.cpp
// Function: main
int main(int argc, const char *argv[]) {
  if (argc < 2) {
    std::cout<<"Usage: mmseg <dictionary> [input.txt]"<<std::endl;
    return 0;
  }

  MMSeg * pmmseg = MMSeg::getInstance();

  pmmseg->load(argv[1]);

  if (argc == 3) {
    std::ifstream ifs(argv[2]);
    if (! ifs.good()) {
      std::cerr << "Failed to open " << argv[2] << std::endl;
      return -1;
    }
    std::stringstream ss;
    ss << ifs.rdbuf();
    ifs.close();

    time_t now = time(0);
    auto s = ss.str();
    auto so = pmmseg->segment(s);

    ss.clear();
    std::cout << so << std::endl;

    std::cout << "Done in " << time(0)  - now << " seconds,  words from " << s.size() << " chars" << std::endl;
    pmmseg->unload();

    return 0;
  }

  while (true) {
    std::cout << "Input String: ";
    std::string line;
    if (! std::getline(std::cin, line)) break;
    std::string ss = pmmseg->segment(trim(line));
    std::cout <<ss << std::endl; 
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
cmpl $0x1, %edi
jg 0x52a2
movq 0x4d2f(%rip), %rdi      # 0x9fb8
leaq 0xf20(%rip), %rsi       # 0x61b0
callq 0x2240
movq %rax, %rdi
callq 0x2110
jmp 0x5409
movq %rsi, %r14
movl %edi, %ebx
callq 0x5112
movq 0x8(%r14), %rsi
movq %rax, (%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x20e0
leaq 0xe70(%rip), %rsi       # 0x613a
leaq 0x250(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x20e0
movq (%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x250(%rsp), %rdx
callq 0x28d8
leaq 0x250(%rsp), %rdi
callq 0x2100
leaq 0x48(%rsp), %rdi
callq 0x2100
cmpl $0x3, %ebx
jne 0x5363
movq 0x10(%r14), %rsi
leaq 0x48(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x2370
movq (%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x68(%rsp,%rax)
je 0x5410
movq 0x4cb5(%rip), %rdi      # 0x9ff0
leaq 0xe94(%rip), %rsi       # 0x61d6
callq 0x2240
movq 0x10(%r14), %rsi
movq %rax, %rdi
callq 0x2240
movq %rax, %rdi
callq 0x2110
pushq $-0x1
popq %rbx
jmp 0x5527
movq 0x4c4e(%rip), %r14      # 0x9fb8
movq 0x4c67(%rip), %r12      # 0x9fd8
leaq 0xe95(%rip), %r15       # 0x620d
leaq 0x48(%rsp), %r13
leaq 0x250(%rsp), %rbp
pushq $0x3
popq %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2240
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x53ff
movq %r13, %rdi
callq 0x3295
movq (%rsp), %rsi
movq %rbp, %rdi
movq %rax, %rdx
movl %ebx, %ecx
callq 0x263e
movq %r14, %rdi
movq %rbp, %rsi
callq 0x21f0
movq %rax, %rdi
callq 0x2110
movq %rbp, %rdi
callq 0x2100
movq %r13, %rdi
callq 0x2100
jmp 0x5388
leaq 0x48(%rsp), %rdi
callq 0x2100
xorl %ebx, %ebx
jmp 0x5531
leaq 0x250(%rsp), %rbx
movq %rbx, %rdi
callq 0x2180
leaq 0x260(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2070
leaq 0x48(%rsp), %rdi
callq 0x2060
xorl %edi, %edi
callq 0x2200
movq %rax, %r14
leaq 0x268(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2300
leaq 0x8(%rsp), %rdx
leaq 0x28(%rsp), %rdi
pushq $0x3
popq %rcx
movq (%rsp), %rsi
callq 0x263e
movq 0x250(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2340
movq 0x4b2d(%rip), %rdi      # 0x9fb8
leaq 0x28(%rsp), %rsi
callq 0x21f0
movq %rax, %rdi
callq 0x2110
movq 0x4b14(%rip), %rdi      # 0x9fb8
leaq 0xd3b(%rip), %rsi       # 0x61e6
callq 0x2240
xorl %edi, %edi
movq %rax, %rbx
callq 0x2200
subq %r14, %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2230
leaq 0xd20(%rip), %rsi       # 0x61ef
movq %rax, %rdi
callq 0x2240
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x2170
leaq 0xd1b(%rip), %rsi       # 0x6206
movq %rax, %rdi
callq 0x2240
movq %rax, %rdi
callq 0x2110
movq (%rsp), %rdi
callq 0x2d0e
leaq 0x28(%rsp), %rdi
callq 0x2100
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0x250(%rsp), %rdi
callq 0x2190
xorl %ebx, %ebx
leaq 0x48(%rsp), %rdi
callq 0x20a0
movl %ebx, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x556e
jmp 0x554e
jmp 0x5553
movq %rax, %rbx
jmp 0x5578
movq %rax, %rbx
jmp 0x5585
jmp 0x5593
jmp 0x55a5
movq %rax, %rbx
jmp 0x55b2
leaq 0x28(%rsp), %rdi
movq %rax, %rbx
callq 0x2100
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0x250(%rsp), %rdi
callq 0x2190
leaq 0x48(%rsp), %rdi
callq 0x20a0
jmp 0x55b2
jmp 0x55a5
leaq 0x250(%rsp), %rdi
movq %rax, %rbx
callq 0x2100
jmp 0x55a8
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2350