// File: /workspace/github_cpp_makefile_star2_O3/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 $0x438, %rsp            # imm = 0x438
movl %ecx, -0x54(%rbp)
movq %rdx, -0x88(%rbp)
movl %esi, %r12d
movq %rdi, %rsi
leaq -0x2d8(%rbp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x45a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x2b8(%rbp,%rax)
jne 0x5489
leaq -0xc0(%rbp), %rdx
movq %rdx, -0x10(%rdx)
xorl %ecx, %ecx
movq %rcx, -0x8(%rdx)
movb %cl, (%rdx)
leaq -0x98(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq %rcx, -0x8(%rdx)
movb %cl, (%rdx)
leaq -0xd0(%rbp), %r14
leaq -0x460(%rbp), %r15
leaq -0x50(%rbp), %r13
leaq -0x80(%rbp), %rbx
leaq (%rax,%rbp), %rdi
addq $-0x2d8, %rdi           # imm = 0xFD28
movl $0xa, %esi
callq 0x4370
movsbl %al, %edx
leaq -0x2d8(%rbp), %rdi
movq %r14, %rsi
callq 0x4670
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5422
movq %r15, %rdi
movq %r14, %rsi
movl $0x18, %edx
callq 0x4580
movq %r15, %rdi
leaq -0x5c(%rbp), %rsi
callq 0x46f0
movq %r15, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4450
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
cmpb $0x0, -0x54(%rbp)
je 0x5287
movl $0x0, -0x2c(%rbp)
movq %r13, %rdi
xorl %esi, %esi
leaq -0x2c(%rbp), %rdx
callq 0x6056
movl $0x0, -0x2c(%rbp)
movq -0xa0(%rbp), %rax
testq %rax, %rax
je 0x5312
xorl %ecx, %ecx
movq -0xa8(%rbp), %rdx
movb (%rdx,%rcx), %sil
movl $0x1, %edx
testb %sil, %sil
jns 0x524c
movl $0x4, %edx
cmpb $-0x11, %sil
ja 0x524c
cmpb $-0x20, %sil
movl $0x2, %edx
sbbl $-0x1, %edx
addl %ecx, %edx
movl %edx, -0x2c(%rbp)
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x5267
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x527a
movq %r13, %rdi
leaq -0x2c(%rbp), %rdx
callq 0x618e
movq -0xa0(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpq %rcx, %rax
ja 0x5220
jmp 0x5312
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x64b6
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x52b6
movq %rax, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x78(%rbp), %rax
cmpq $-0x1, %rax
je 0x5300
xorl %ecx, %ecx
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x52df
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x52ef
movq %r13, %rdi
leaq -0x2c(%rbp), %rdx
callq 0x618e
movq -0x78(%rbp), %rax
movl -0x2c(%rbp), %ecx
incl %ecx
movl %ecx, -0x2c(%rbp)
leaq 0x1(%rax), %rdx
cmpq %rcx, %rdx
ja 0x52c9
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5312
callq 0x4350
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rax
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x4, %rcx
je 0x53db
xorl %r15d, %r15d
movl %r15d, %r13d
leal 0x1(%r13), %esi
movq %rax, %rcx
subq %rdi, %rcx
sarq $0x2, %rcx
testl %r12d, %r12d
movq %rsi, -0xb0(%rbp)
je 0x53c8
cmpq %rsi, %rcx
jbe 0x53c8
movl $0x2, %r14d
movl (%rdi,%r15,4), %edx
movl (%rdi,%rsi,4), %ecx
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
subl %edx, %ecx
movq %rbx, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x43b0
movq -0x88(%rbp), %rdi
movq %rbx, %rsi
callq 0x5f12
movss -0x58(%rbp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x53a5
callq 0x4350
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rax
movq %rax, %rcx
subq %rdi, %rcx
sarq $0x2, %rcx
cmpl %r12d, %r14d
ja 0x53c8
leal (%r14,%r13), %esi
incl %r14d
cmpq %rsi, %rcx
ja 0x5355
decq %rcx
movq -0xb0(%rbp), %r15
cmpq %r15, %rcx
ja 0x532d
testq %rdi, %rdi
je 0x53e5
callq 0x4350
leaq -0x460(%rbp), %r15
movq %r15, %rdi
movq 0x30b9a(%rip), %rsi     # 0x35f90
callq 0x42c0
leaq -0x3e0(%rbp), %rdi
callq 0x4110
movq -0x2d8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0xd0(%rbp), %r14
leaq -0x50(%rbp), %r13
jmp 0x5175
leaq -0x2d8(%rbp), %rdi
callq 0x40a0
movq -0x88(%rbp), %rax
movq 0x28(%rax), %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x5451
callq 0x4350
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x5469
callq 0x4350
leaq -0x2d8(%rbp), %rdi
callq 0x40c0
movl %ebx, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30b58(%rip), %rdi     # 0x35fe8
leaq 0x22b89(%rip), %rsi     # 0x28020
movl $0x2c, %edx
callq 0x4400
movq 0x30b40(%rip), %rdi     # 0x35fe8
callq 0x4180
movl $0x1, %edi
callq 0x4420
movq %rax, %rbx
jmp 0x554a
jmp 0x54ca
jmp 0x54ea
jmp 0x54ca
movq %rax, %rbx
jmp 0x54fb
movq %rax, %rbx
jmp 0x551a
jmp 0x54d3
jmp 0x54ea
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x54ed
callq 0x4350
jmp 0x54ed
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x54fb
callq 0x4350
movq 0x30a8e(%rip), %rsi     # 0x35f90
leaq -0x460(%rbp), %rdi
callq 0x42c0
leaq -0x3e0(%rbp), %rdi
callq 0x4110
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x5532
callq 0x4350
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x554a
callq 0x4350
leaq -0x2d8(%rbp), %rdi
callq 0x40c0
movq %rbx, %rdi
callq 0x4640