// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
addq $0x8, %rdi
movq %rdi, 0x20(%rsp)
callq 0x2320
testl %eax, %eax
jne 0x3140
cmpb $0x1, (%rbx)
je 0x30f7
leaq 0x2b0(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x2350
leaq 0x328(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x3105
movq %r14, 0x28(%rsp)
leaq 0xb8(%rsp), %r14
movq %rbx, 0x58(%rsp)
leaq 0x68(%rbx), %r12
leaq 0xa8(%rsp), %r13
movq %rsp, %rbp
movq 0x2b0(%rsp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0x2d0(%rsp,%rcx)
jne 0x2dbb
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 0x2da0
movq %r13, %rdi
callq 0x3809
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 0x3b5b
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3a04
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x2da0
callq 0x2240
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2db2
callq 0x2240
testb $0x5, %bl
je 0x2ced
leaq 0x2b0(%rsp), %rdi
callq 0x2070
movq 0x28(%rsp), %r12
cmpq $0x0, 0x8(%r12)
leaq 0x10(%rsp), %r14
movq 0x58(%rsp), %rbx
je 0x30c7
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x2350
leaq 0x120(%rsp), %rdi
callq 0x2090
testb %al, %al
je 0x3119
leaq 0x90(%rsp), %r12
leaq 0x70(%rsp), %r13
leaq 0x30(%rbx), %rax
movq %rax, 0x28(%rsp)
movq %rsp, %rbx
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0xc8(%rsp,%rcx)
jne 0x301e
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 0x3006
movq %rbx, %rdi
callq 0x3809
leaq 0x80(%rsp), %rbx
movq %r12, 0x80(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x4266
movq %rbx, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x22c0
cmpq $-0x1, %rax
je 0x2ff1
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
leaq 0x80(%rsp), %r14
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2280
movq %r13, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movw $0x0, 0x70(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x3b5b
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2f26
callq 0x2240
movq %r13, %r15
incq %rbx
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq $-0x1, %rcx
callq 0x2280
movq 0x38(%rsp), %r14
callq 0x2050
movq %rax, %rbx
movl (%rax), %r13d
movl $0x0, (%rax)
movq %r14, %rdi
leaq 0xa0(%rsp), %rsi
movl $0xa, %edx
callq 0x22e0
cmpq %r14, 0xa0(%rsp)
je 0x3134
movq %rax, %r12
movslq %r12d, %rax
cmpq %r12, %rax
jne 0x3128
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x3128
testl %eax, %eax
jne 0x2f9d
movl %r13d, (%rbx)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2fb1
callq 0x2240
movl %r12d, 0x34(%rsp)
movq 0x60(%rsp), %rsi
movq 0x28(%rsp), %rdi
leaq 0x34(%rsp), %rdx
movq %r15, %r13
callq 0x51a6
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
leaq 0x10(%rsp), %r14
leaq 0x90(%rsp), %r12
je 0x2fe9
callq 0x2240
leaq 0xa8(%rsp), %r15
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x3003
callq 0x2240
movq %rsp, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x3014
callq 0x2240
testb $0x5, %bpl
je 0x2e29
leaq 0xa8(%rsp), %rdi
callq 0x2070
movq 0x58(%rsp), %r14
movq 0x5f89(%rip), %rdi      # 0x8fc0
leaq 0x31dc(%rip), %rsi      # 0x621a
movl $0xd, %edx
callq 0x2290
movq 0x80(%r14), %rsi
movq 0x5f6a(%rip), %rdi      # 0x8fc0
callq 0x2180
movq %rax, %rbx
leaq 0x31c3(%rip), %rsi      # 0x6228
movl $0x8, %edx
movq %rax, %rdi
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 0x30d6
movb $0x1, (%rbx)
movq 0x20(%rsp), %rdi
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 0x30e3
movq %r12, %rdi
movq 0x20(%rsp), %rsi
callq 0x2449
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x30d6
movq %r12, %rdi
callq 0x2475
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x30ae
leaq 0x311a(%rip), %rdi      # 0x6249
callq 0x2300
leaq 0x310e(%rip), %rdi      # 0x6249
callq 0x2150
movl %eax, %edi
callq 0x2170
jmp 0x3149
movq %rax, %r12
jmp 0x3227
jmp 0x3153
movq %rax, %r12
jmp 0x319f
movq %rax, %r12
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x316a
callq 0x2240
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
jne 0x31a9
jmp 0x31ae
movq %rax, %r12
jmp 0x31ae
movq %rax, %r12
cmpl $0x0, (%rbx)
jne 0x318b
movl %r13d, (%rbx)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x319f
callq 0x2240
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x31ae
callq 0x2240
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x31f0
callq 0x2240
jmp 0x31f0
movq %rax, %r12
jmp 0x3203
jmp 0x31d1
movq %rax, %r12
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x3215
callq 0x2240
jmp 0x3215
jmp 0x3212
jmp 0x31ed
movq %rax, %r12
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x3203
callq 0x2240
leaq 0xa8(%rsp), %rdi
callq 0x20a0
jmp 0x3227
movq %rax, %r12
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3227
callq 0x2240
leaq 0x2b0(%rsp), %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x2390