// File: /workspace/github_cpp_makefile_star2_O3/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 $0x4b8, %rsp            # imm = 0x4B8
movq %rdi, %rbx
addq $0x8, %rdi
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
callq 0x2320
testl %eax, %eax
jne 0x3126
cmpb $0x1, (%rbx)
je 0x30dd
leaq 0x2b0(%rsp), %r15
movl $0x8, %edx
movq %r12, %rsi
movq %r15, %rdi
callq 0x2350
leaq 0x328(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x30eb
movq %r14, 0x28(%rsp)
leaq 0xb8(%rsp), %r14
leaq 0x68(%rbx), %r12
leaq 0xa8(%rsp), %r13
movq %rsp, %rbp
movq %rbx, 0x58(%rsp)
movq 0x2b0(%rsp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0x2d0(%rsp,%rcx)
jne 0x2da1
movq %r14, 0xa8(%rsp)
movq $0x0, 0xb0(%rsp)
movb $0x0, 0xb8(%rsp)
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2260
movsbl %al, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x23d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x20(%rax,%rcx), %ebx
testb $0x5, %bl
jne 0x2d86
movq %r13, %rdi
callq 0x37fb
leaq 0x10(%rsp), %rcx
movq %rcx, (%rsp)
movq $0x0, 0x8(%rsp)
movw $0x0, 0x10(%rsp)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq %rbp, %rdx
callq 0x3aff
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3a08
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x2d86
callq 0x2240
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2d98
callq 0x2240
testb $0x5, %bl
je 0x2cd3
leaq 0x2b0(%rsp), %rdi
callq 0x2070
movq 0x28(%rsp), %r12
movq 0x58(%rsp), %rbx
leaq 0x10(%rsp), %r14
cmpq $0x0, 0x8(%r12)
je 0x30ad
leaq 0xa8(%rsp), %r15
movl $0x8, %edx
movq %r12, %rsi
movq %r15, %rdi
callq 0x2350
leaq 0x120(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x30ff
leaq 0x30(%rbx), %rax
leaq 0x90(%rsp), %r12
leaq 0x70(%rsp), %r13
movq %rsp, %rbx
movq %rax, 0x28(%rsp)
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0xc8(%rsp,%rcx)
jne 0x3004
movq %r14, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2260
movsbl %al, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x23d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x20(%rax,%rcx), %ebp
testb $0x5, %bpl
jne 0x2fec
movq %rbx, %rdi
callq 0x37fb
leaq 0x80(%rsp), %rbx
movq %r12, 0x80(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x422a
movl $0x20, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x22c0
cmpq $-0x1, %rax
je 0x2fd7
leaq 0x80(%rsp), %r14
leaq 0x38(%rsp), %rdi
movq %rax, %rbx
xorl %edx, %edx
movq %rax, %rcx
movq %r14, %rsi
callq 0x2280
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq %r13, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movw $0x0, 0x70(%rsp)
leaq 0x60(%rsp), %rdx
callq 0x3aff
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2f0c
callq 0x2240
movq %r13, %r15
incq %rbx
leaq 0x38(%rsp), %rdi
movq $-0x1, %rcx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2280
movq 0x38(%rsp), %r14
callq 0x2050
movl (%rax), %r13d
leaq 0xa0(%rsp), %rsi
movl $0xa, %edx
movq %r14, %rdi
movq %rax, %rbx
movl $0x0, (%rax)
callq 0x22e0
cmpq %r14, 0xa0(%rsp)
je 0x311a
movq %rax, %r12
movslq %r12d, %rax
cmpq %r12, %rax
jne 0x310e
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x310e
testl %eax, %eax
jne 0x2f83
movl %r13d, (%rbx)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2f97
callq 0x2240
movq 0x60(%rsp), %rsi
movl %r12d, 0x34(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x34(%rsp), %rdx
movq %r15, %r13
callq 0x511c
movq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %r14
leaq 0x90(%rsp), %r12
cmpq %r13, %rdi
je 0x2fcf
callq 0x2240
leaq 0xa8(%rsp), %r15
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x2fe9
callq 0x2240
movq %rsp, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x2ffa
callq 0x2240
testb $0x5, %bpl
je 0x2e0f
leaq 0xa8(%rsp), %rdi
callq 0x2070
movq 0x58(%rsp), %r14
movq 0x5fa3(%rip), %rdi      # 0x8fc0
leaq 0x31be(%rip), %rsi      # 0x61e2
movl $0xd, %edx
callq 0x2290
movq 0x80(%r14), %rsi
movq 0x5f84(%rip), %rdi      # 0x8fc0
callq 0x2180
leaq 0x31a8(%rip), %rsi      # 0x61f0
movl $0x8, %edx
movq %rax, %rdi
movq %rax, %rbx
callq 0x2290
movq 0x48(%r14), %rsi
movq %rbx, %rdi
callq 0x2180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2260
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2190
movb $0x1, (%r14)
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
callq 0x21d0
leaq 0xa8(%rsp), %rdi
callq 0x20a0
jmp 0x30bc
movq 0x20(%rsp), %rdi
movb $0x1, (%rbx)
callq 0x21d0
xorl %ebx, %ebx
leaq 0x2b0(%rsp), %rdi
callq 0x20a0
movl %ebx, %eax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdi
callq 0x2499
xorl %ebx, %ebx
jmp 0x30c9
movq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x2449
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x30bc
movq %r12, %rdi
callq 0x2475
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x3094
leaq 0x30fc(%rip), %rdi      # 0x6211
callq 0x2300
leaq 0x30f0(%rip), %rdi      # 0x6211
callq 0x2150
movl %eax, %edi
callq 0x2170
jmp 0x312f
movq %rax, %r12
jmp 0x320d
jmp 0x3139
movq %rax, %r12
jmp 0x3185
movq 0x60(%rsp), %rdi
movq %rax, %r12
cmpq %r13, %rdi
je 0x3150
callq 0x2240
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
jne 0x318f
jmp 0x3194
movq %rax, %r12
jmp 0x3194
cmpl $0x0, (%rbx)
movq %rax, %r12
jne 0x3171
movl %r13d, (%rbx)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3185
callq 0x2240
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x3194
callq 0x2240
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x31d6
callq 0x2240
jmp 0x31d6
movq %rax, %r12
jmp 0x31e9
jmp 0x31b7
movq (%rsp), %rdi
movq %rax, %r12
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x31fb
callq 0x2240
jmp 0x31fb
jmp 0x31f8
jmp 0x31d3
movq %rax, %r12
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x31e9
callq 0x2240
leaq 0xa8(%rsp), %rdi
callq 0x20a0
jmp 0x320d
movq %rax, %r12
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x320d
callq 0x2240
leaq 0x2b0(%rsp), %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x2390