// File: /workspace/github_cpp_makefile_star2_O2/aalto-speech[P]ftk/src/substrings.cc
// Function: get_substrings(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, float, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, float>>>&, bool)
int get_substrings(const string &infname,
                   unsigned int maxlen,
                   map<string,float> &substrs,
                   bool utf8) {

    ifstream infile(infname);
    if (!infile) {
        cerr << "Something went wrong opening the input file." << endl;
        exit(1);
    }

    float count;
    string line, word;

    while (getline(infile, line)) {
        stringstream ss(line);
        ss >> count;
        ss >> word;

        vector<unsigned int> char_positions;
        get_character_positions(word, char_positions, utf8);

        for (unsigned int i=0; i<char_positions.size()-1; i++)
            for (unsigned int j=i+1; j<char_positions.size() && j-i <= maxlen; j++) {
                unsigned int start_pos = char_positions[i];
                unsigned int end_pos = char_positions[j];
                substrs[word.substr(start_pos, end_pos-start_pos)] += count;
            }
    }

    infile.close();
    return substrs.size();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movl %ecx, -0x54(%rbp)
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %rsi
leaq -0x2c8(%rbp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x4540
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x2a8(%rbp,%rax)
jne 0x4d95
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0xc0(%rbp), %r14
leaq -0x450(%rbp), %r13
leaq -0xa0(%rbp), %r12
leaq -0x2c8(%rbp), %rdi
movq %r14, %rsi
callq 0x4090
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4d51
movq %r13, %rdi
movq %r14, %rsi
pushq $0x18
popq %rdx
callq 0x4520
movq %r13, %rdi
leaq -0x5c(%rbp), %rsi
callq 0x46a0
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
callq 0x43f0
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
cmpb $0x0, -0x54(%rbp)
je 0x4c49
andl $0x0, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x55d0
andl $0x0, -0xa0(%rbp)
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, -0x78(%rbp)
jbe 0x4c95
movq -0x80(%rbp), %rcx
movb (%rcx,%rax), %dl
pushq $0x1
popq %rcx
testb %dl, %dl
jns 0x4c2d
pushq $0x4
popq %rcx
cmpb $-0x11, %dl
ja 0x4c2d
cmpb $-0x20, %dl
pushq $0x2
popq %rcx
sbbl $-0x1, %ecx
addl %ecx, %eax
movl %eax, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x559c
movl -0xa0(%rbp), %eax
jmp 0x4c02
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
callq 0x4460
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x4c63
movq %rax, -0x48(%rbp)
xorl %eax, %eax
movl %eax, -0x30(%rbp)
movl %eax, %eax
movq -0x98(%rbp), %rcx
incq %rcx
cmpq %rax, %rcx
jbe 0x4c8d
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x559c
movl -0x30(%rbp), %eax
incl %eax
jmp 0x4c65
movq %r12, %rdi
callq 0x46b8
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
xorl %edx, %edx
movl %edx, %r13d
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
decq %rdx
cmpq %r13, %rdx
jbe 0x4d2d
leal 0x1(%r13), %edx
movl %edx, -0x2c(%rbp)
pushq $0x1
popq %rdx
movl %edx, %r14d
leal (%r14,%r13), %esi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpl %r15d, %r14d
ja 0x4d25
cmpq %rsi, %rdx
jbe 0x4d25
movl (%rax,%r13,4), %edx
movl (%rax,%rsi,4), %ecx
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
subl %edx, %ecx
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
callq 0x4360
movq %rbx, %rdi
movq %r12, %rsi
callq 0x54c8
movss -0x58(%rbp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
movq %r12, %rdi
callq 0x46b8
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
incl %r14d
jmp 0x4cc1
movl -0x2c(%rbp), %edx
jmp 0x4c9f
leaq -0x50(%rbp), %rdi
callq 0x5a76
leaq -0x450(%rbp), %r13
movq %r13, %rdi
callq 0x42b0
leaq -0xc0(%rbp), %r14
jmp 0x4b8d
leaq -0x2c8(%rbp), %rdi
callq 0x40a0
movl 0x28(%rbx), %ebx
leaq -0x80(%rbp), %rdi
callq 0x46b8
leaq -0xc0(%rbp), %rdi
callq 0x46b8
leaq -0x2c8(%rbp), %rdi
callq 0x40d0
movl %ebx, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3124c(%rip), %rdi     # 0x35fe8
leaq 0x1f27f(%rip), %rsi     # 0x24022
callq 0x4340
movq %rax, %rdi
callq 0x4180
pushq $0x1
popq %rdi
callq 0x43c0
movq %rax, %rbx
jmp 0x4e0f
jmp 0x4dc3
jmp 0x4dd1
jmp 0x4dc3
movq %rax, %rbx
jmp 0x4dfa
movq %rax, %rbx
jmp 0x4dee
jmp 0x4dd6
jmp 0x4dd1
movq %rax, %rbx
jmp 0x4de5
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x46b8
leaq -0x50(%rbp), %rdi
callq 0x5a76
leaq -0x450(%rbp), %rdi
callq 0x42b0
leaq -0x80(%rbp), %rdi
callq 0x46b8
leaq -0xc0(%rbp), %rdi
callq 0x46b8
leaq -0x2c8(%rbp), %rdi
callq 0x40d0
movq %rbx, %rdi
callq 0x45e0