// File: /workspace/github_cpp_makefile_star2_O2/jkom-cloud[P]mmseg/src/Mmseg.cpp
// Function: mmsegSpace::MMSeg::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int mmsegSpace::MMSeg::load(const std::string& dict, const std::string& char_freqs) {
    mtx.lock();
    if (is_inited) {// 已经加载词典
      fprintf(stderr, "Dict has been loaded!");
      mtx.unlock();
      return 0;
    }

    std::ifstream ifs(dict);
    if (!ifs.is_open()) {
      fprintf(stderr, "open %s failed!!", dict.c_str());
      mtx.unlock();
      return -1;
    }

    while (ifs.good()) {
      std::string line;
      if (! std::getline(ifs, line)) break;
      auto word = TransCode::from_utf8(trim(line));
      dict_.add(word);
    }
    ifs.close();

    if (char_freqs.empty()) {
      is_inited = true;
      mtx.unlock();
      return 0;
    }

    std::ifstream fin(char_freqs);
    if (!fin.is_open()) {
      fprintf(stderr, "open %s failed!!", char_freqs.c_str());
      mtx.unlock();
      return -1;
    }

    while (fin.good()) {
      std::string line;
      if (! std::getline(fin, line)) break;
      auto s = trim(line);
      size_t pos = s.find(' ');
      if (pos != std::string::npos) {
        auto word = TransCode::from_utf8(s.substr(0, pos));
        int freq = std::stoi(s.substr(pos+1));
        char_freqs_.emplace(word[0], freq);
      }
    }
    fin.close();

    std::cout << "Loaded Dict: " << dict_.size() << ", Freq: " << char_freqs_.size() << std::endl;
    is_inited = true;
    mtx.unlock();
    return 0;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rdi, %r15
addq $0x8, %rdi
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
callq 0x319a
cmpb $0x1, (%r15)
movq %r15, (%rsp)
je 0x2bf6
leaq 0x2a0(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2310
leaq 0x318(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x2c20
movq (%rsp), %rax
leaq 0xa8(%rsp), %rbp
leaq 0x2a0(%rsp), %r15
leaq 0x98(%rsp), %r12
leaq 0x18(%rsp), %r13
leaq 0x68(%rax), %r14
movq 0x2a0(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x2c0(%rsp,%rax)
jne 0x29e0
movq %rbp, 0x98(%rsp)
andq $0x0, 0xa0(%rsp)
movb $0x0, 0xa8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x29d3
movq %r12, %rdi
callq 0x3295
movq %r13, %rdi
movq %rax, %rsi
callq 0x31ae
movq %r14, %rdi
movq %r13, %rsi
callq 0x32a4
movq %r13, %rdi
callq 0x321c
movq %r12, %rdi
callq 0x2100
jmp 0x295b
leaq 0x98(%rsp), %rdi
callq 0x2100
leaq 0x2a0(%rsp), %rdi
callq 0x2060
cmpq $0x0, 0x8(%rbx)
je 0x2b39
leaq 0x98(%rsp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x2310
leaq 0x110(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x2c4a
movq (%rsp), %rax
leaq 0x18(%rsp), %r13
leaq 0x78(%rsp), %rbp
leaq 0x38(%rsp), %r14
leaq 0x58(%rsp), %rbx
leaq 0x30(%rax), %r15
movq 0x98(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0xb8(%rsp,%rax)
jne 0x2b5b
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2b51
movq %r13, %rdi
callq 0x3295
movq %rbp, %rdi
movq %rax, %rsi
callq 0x22a0
movq %rbp, %rdi
pushq $0x20
popq %rsi
xorl %edx, %edx
callq 0x2280
cmpq $-0x1, %rax
je 0x2b24
movq %rax, %r12
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2260
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31ae
movq %r14, %rdi
callq 0x2100
incq %r12
movq %r12, %rdx
movq %r14, %rdi
movq %rbp, %rsi
pushq $-0x1
popq %rcx
callq 0x2260
movq %r14, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x3359
movq %r14, %rdi
movl %eax, %r12d
callq 0x2100
movq 0x58(%rsp), %rsi
movl %r12d, 0x14(%rsp)
leaq 0x14(%rsp), %rdx
movq %r15, %rdi
callq 0x4cb8
movq %rbx, %rdi
callq 0x321c
movq %rbp, %rdi
callq 0x2100
movq %r13, %rdi
callq 0x2100
jmp 0x2a3c
movq (%rsp), %rax
movq 0x8(%rsp), %rdi
movb $0x1, (%rax)
callq 0x21a0
xorl %ebx, %ebx
jmp 0x2bd5
leaq 0x18(%rsp), %rdi
callq 0x2100
leaq 0x98(%rsp), %rdi
callq 0x2060
movq 0x7449(%rip), %rdi      # 0x9fb8
leaq 0x35ec(%rip), %rsi      # 0x6162
callq 0x2240
movq (%rsp), %rcx
movq 0x80(%rcx), %rsi
movq %rax, %rdi
callq 0x2170
leaq 0x35db(%rip), %rsi      # 0x6170
movq %rax, %rdi
callq 0x2240
movq (%rsp), %rcx
movq 0x48(%rcx), %rsi
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x2110
movq (%rsp), %rax
xorl %ebx, %ebx
movb $0x1, (%rax)
movq 0x8(%rsp), %rdi
callq 0x21a0
leaq 0x98(%rsp), %rdi
callq 0x20a0
leaq 0x2a0(%rsp), %rdi
callq 0x20a0
movl %ebx, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x73c3(%rip), %rax      # 0x9fc0
leaq 0x3537(%rip), %rdi      # 0x613b
movq (%rax), %rcx
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
callq 0x23a0
movq 0x8(%rsp), %rdi
callq 0x21a0
xorl %ebx, %ebx
jmp 0x2be2
movq 0x7399(%rip), %rax      # 0x9fc0
movq (%r14), %rdx
leaq 0x3520(%rip), %rsi      # 0x6151
movq (%rax), %rdi
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %rdi
callq 0x21a0
pushq $-0x1
popq %rbx
jmp 0x2bd5
movq 0x736f(%rip), %rax      # 0x9fc0
movq (%rbx), %rdx
leaq 0x34f6(%rip), %rsi      # 0x6151
movq (%rax), %rdi
xorl %eax, %eax
callq 0x22b0
pushq $-0x1
popq %rbx
jmp 0x2bbe
jmp 0x2c6f
movq %rax, %rbx
jmp 0x2cf9
movq %rax, %rbx
jmp 0x2cda
jmp 0x2c9c
leaq 0x38(%rsp), %rdi
movq %rax, %rbx
callq 0x2100
jmp 0x2c9f
leaq 0x38(%rsp), %rdi
movq %rax, %rbx
callq 0x2100
jmp 0x2cae
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x321c
jmp 0x2cae
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x2100
jmp 0x2cd0
jmp 0x2ccd
leaq 0x18(%rsp), %rdi
movq %rax, %rbx
callq 0x321c
jmp 0x2cec
jmp 0x2ce9
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2100
leaq 0x98(%rsp), %rdi
callq 0x20a0
jmp 0x2cf9
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2100
leaq 0x2a0(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2350