// File: 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:
subq $0x548, %rsp            # imm = 0x548
movl $0x0, 0x544(%rsp)
movl %edi, 0x540(%rsp)
movq %rsi, 0x538(%rsp)
cmpl $0x2, 0x540(%rsp)
jge 0xff2d
movq 0x90b6(%rip), %rdi      # 0x18fb8
leaq 0x1274(%rip), %rsi      # 0x1117d
callq 0x32a0
movq %rax, %rdi
movq 0x9090(%rip), %rsi      # 0x18fa8
callq 0x32d0
movl $0x0, 0x544(%rsp)
jmp 0x10549
callq 0xfaf0
movq %rax, 0x530(%rsp)
movq 0x530(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x538(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xa0(%rsp)
leaq 0x50f(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x3480
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x510(%rsp), %rdi
callq 0x3360
jmp 0xff92
leaq 0x4d7(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x3480
movq 0x90(%rsp), %rdx
leaq 0x1127(%rip), %rsi      # 0x110dd
leaq 0x4d8(%rsp), %rdi
callq 0x3360
jmp 0xffc5
movq 0x98(%rsp), %rdi
leaq 0x510(%rsp), %rsi
leaq 0x4d8(%rsp), %rdx
callq 0x3f00
jmp 0xffe4
leaq 0x4d8(%rsp), %rdi
callq 0x3160
leaq 0x4d7(%rsp), %rdi
callq 0x32e0
leaq 0x510(%rsp), %rdi
callq 0x3160
leaq 0x50f(%rsp), %rdi
callq 0x32e0
cmpl $0x3, 0x540(%rsp)
jne 0x103dc
movq 0x538(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x2c8(%rsp), %rdi
movl $0x8, %edx
callq 0x34b0
movq 0x2c8(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x2c8(%rsp,%rax), %rdi
callq 0x3450
movb %al, 0x8f(%rsp)
jmp 0x10066
movb 0x8f(%rsp), %al
testb $0x1, %al
jne 0x10174
jmp 0x10077
movq 0x8f72(%rip), %rdi      # 0x18ff0
leaq 0x111e(%rip), %rsi      # 0x111a3
callq 0x32a0
movq %rax, 0x80(%rsp)
jmp 0x10094
movq 0x80(%rsp), %rdi
movq 0x538(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x32a0
movq %rax, 0x78(%rsp)
jmp 0x100b4
movq 0x78(%rsp), %rdi
movq 0x8ee8(%rip), %rsi      # 0x18fa8
callq 0x32d0
jmp 0x100c7
movl $0xffffffff, 0x544(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x2c4(%rsp)
jmp 0x103b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
jmp 0x10149
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
jmp 0x1012f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
leaq 0x4d8(%rsp), %rdi
callq 0x3160
leaq 0x4d7(%rsp), %rdi
callq 0x32e0
leaq 0x510(%rsp), %rdi
callq 0x3160
leaq 0x50f(%rsp), %rdi
callq 0x32e0
jmp 0x10558
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
jmp 0x103ca
leaq 0x138(%rsp), %rdi
callq 0x31c0
jmp 0x10183
leaq 0x148(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x2c8(%rsp), %rdi
callq 0x33e0
movq %rax, 0x70(%rsp)
jmp 0x101a4
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdi
callq 0x3070
jmp 0x101b5
leaq 0x2c8(%rsp), %rdi
callq 0x3060
jmp 0x101c4
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movq %rax, 0x130(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x3290
jmp 0x101ec
movq 0x530(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
leaq 0x110(%rsp), %rdx
movl $0x3, %ecx
callq 0x3940
jmp 0x10210
movq 0x138(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x138(%rsp,%rax), %rdi
xorl %esi, %esi
callq 0x3440
jmp 0x1022d
movq 0x8d84(%rip), %rdi      # 0x18fb8
leaq 0xf0(%rsp), %rsi
callq 0x3240
movq %rax, 0x60(%rsp)
jmp 0x10248
movq 0x60(%rsp), %rdi
movq 0x8d54(%rip), %rsi      # 0x18fa8
callq 0x32d0
jmp 0x1025b
movq 0x8d56(%rip), %rdi      # 0x18fb8
leaq 0xf4a(%rip), %rsi       # 0x111b3
callq 0x32a0
movq %rax, 0x58(%rsp)
jmp 0x10275
xorl %eax, %eax
movl %eax, %edi
callq 0x3250
movq 0x58(%rsp), %rdi
movq %rax, %rsi
movq 0x130(%rsp), %rax
subq %rax, %rsi
callq 0x34a0
movq %rax, 0x50(%rsp)
jmp 0x1029d
movq 0x50(%rsp), %rdi
leaq 0xf13(%rip), %rsi       # 0x111bc
callq 0x32a0
movq %rax, 0x48(%rsp)
jmp 0x102b5
leaq 0x110(%rsp), %rdi
callq 0x31b0
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x3090
movq %rax, 0x40(%rsp)
jmp 0x102d6
movq 0x40(%rsp), %rdi
leaq 0xef1(%rip), %rsi       # 0x111d3
callq 0x32a0
movq %rax, 0x38(%rsp)
jmp 0x102ee
movq 0x38(%rsp), %rdi
movq 0x8cae(%rip), %rsi      # 0x18fa8
callq 0x32d0
jmp 0x10301
movq 0x530(%rsp), %rdi
callq 0x46f0
jmp 0x10310
movl $0x0, 0x544(%rsp)
movl $0x1, 0x2c4(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x3160
leaq 0x110(%rsp), %rdi
callq 0x3160
leaq 0x138(%rsp), %rdi
callq 0x31e0
jmp 0x103b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
jmp 0x103a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
jmp 0x1039c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x3160
leaq 0x110(%rsp), %rdi
callq 0x3160
leaq 0x138(%rsp), %rdi
callq 0x31e0
jmp 0x103ca
leaq 0x2c8(%rsp), %rdi
callq 0x30a0
jmp 0x10549
leaq 0x2c8(%rsp), %rdi
callq 0x30a0
jmp 0x10558
jmp 0x103de
movq 0x8bd3(%rip), %rdi      # 0x18fb8
leaq 0xdee(%rip), %rsi       # 0x111da
callq 0x32a0
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x3370
movq 0x28(%rsp), %rsi
movq 0x8bc9(%rip), %rdi      # 0x18fd8
callq 0x3050
movq %rax, 0x30(%rsp)
jmp 0x1041b
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3110
movb %al, 0x27(%rsp)
jmp 0x10435
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x1043f
jmp 0x10468
movl $0x3, 0x2c4(%rsp)
jmp 0x104ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
jmp 0x1052f
movq 0x530(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x5b20
movq %rax, 0x18(%rsp)
jmp 0x10489
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
movl $0x3, %ecx
callq 0x3940
jmp 0x104a7
movq 0x8b0a(%rip), %rdi      # 0x18fb8
leaq 0xb0(%rsp), %rsi
callq 0x3240
movq %rax, 0x8(%rsp)
jmp 0x104c2
movq 0x8(%rsp), %rdi
movq 0x8ada(%rip), %rsi      # 0x18fa8
callq 0x32d0
jmp 0x104d5
leaq 0xb0(%rsp), %rdi
callq 0x3160
movl $0x0, 0x2c4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x3160
movl 0x2c4(%rsp), %eax
testl %eax, %eax
je 0x10509
jmp 0x10507
jmp 0x1053e
jmp 0x103de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x500(%rsp)
movl %eax, 0x4fc(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x3160
leaq 0xd0(%rsp), %rdi
callq 0x3160
jmp 0x10558
movl $0x0, 0x544(%rsp)
movl 0x544(%rsp), %eax
addq $0x548, %rsp            # imm = 0x548
retq
movq 0x500(%rsp), %rdi
callq 0x3470