// File: aalto-speech[P]ftk/src/MSFG.cc
// Function: MultiStringFactorGraph::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void
MultiStringFactorGraph::read(const std::string &filename)
{
    ifstream infile(filename);
    if (!infile) return;

    int node_count, arc_count, end_node_count;
    char type;
    string line;
    getline(infile, line);
    stringstream ss(line);
    ss >> node_count >> arc_count >> end_node_count;

    nodes.clear();
    string_end_nodes.clear();
    reverse_string_end_nodes.clear();
    nodes.resize(node_count);

    msfg_node_idx_t node_idx;
    string factor;
    for (int i=0; i<node_count; i++) {
        getline(infile, line);
        stringstream nodess(line);
        nodess >> type;
        if (type != 'n') {
            cerr << "Some problem reading MSFG file" << endl;
            exit(EXIT_FAILURE);
        }
        nodess >> node_idx >> factor;
        nodes[node_idx].factor.assign(factor);
        factor_node_map[factor].push_back(node_idx);
    }

    msfg_node_idx_t src_node, tgt_node;
    for (int i=0; i<arc_count; i++) {
        getline(infile, line);
        stringstream arcss(line);
        arcss >> type;
        if (type != 'a') {
            cerr << "Some problem reading MSFG file" << endl;
            exit(EXIT_FAILURE);
        }
        arcss >> src_node >> tgt_node;
        create_arc(src_node, tgt_node);
    }

    msfg_node_idx_t end_node_idx;
    string curr_string;
    for (int i=0; i<arc_count; i++) {
        getline(infile, line);
        stringstream endnss(line);
        endnss >> type;
        if (type != 'e') {
            cerr << "Some problem reading MSFG file" << endl;
            exit(EXIT_FAILURE);
        }
        endnss >> curr_string >> end_node_idx;
        string_end_nodes[curr_string] = end_node_idx;
        reverse_string_end_nodes[end_node_idx] = curr_string;
    }

    infile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x990, %rsp            # imm = 0x990
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x8f8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x4640
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x41d0
movb %al, -0x8e9(%rbp)
jmp 0x2ebc3
movb -0x8e9(%rbp), %al
testb $0x1, %al
jne 0x2ebcf
jmp 0x2ebf5
movl $0x1, -0x228(%rbp)
jmp 0x2f22c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2f271
leaq -0x258(%rbp), %rdi
movq %rdi, -0x900(%rbp)
callq 0x4560
movq -0x900(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x40b0
jmp 0x2ec1d
movl $0x10, %edi
movl $0x8, %esi
callq 0x13950
movl %eax, -0x904(%rbp)
jmp 0x2ec34
movl -0x904(%rbp), %edx
leaq -0x3e0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4630
jmp 0x2ec4f
leaq -0x3e0(%rbp), %rdi
leaq -0x22c(%rbp), %rsi
callq 0x4290
movq %rax, -0x910(%rbp)
jmp 0x2ec6b
movq -0x910(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x4290
movq %rax, -0x918(%rbp)
jmp 0x2ec87
movq -0x918(%rbp), %rdi
leaq -0x234(%rbp), %rsi
callq 0x4290
jmp 0x2ec9c
movq -0x8f8(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x920(%rbp)
callq 0x314e0
movq -0x8f8(%rbp), %rdi
addq $0x38, %rdi
callq 0x31500
movq -0x8f8(%rbp), %rdi
addq $0x68, %rdi
callq 0x31520
movq -0x920(%rbp), %rdi
movslq -0x22c(%rbp), %rsi
callq 0x31540
jmp 0x2ece8
leaq -0x408(%rbp), %rdi
callq 0x4560
movl $0x0, -0x40c(%rbp)
movl -0x40c(%rbp), %eax
cmpl -0x22c(%rbp), %eax
jge 0x2eed1
leaq -0x218(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x40b0
jmp 0x2ed25
movl $0x10, %edi
movl $0x8, %esi
callq 0x13950
movl %eax, -0x924(%rbp)
jmp 0x2ed3c
movl -0x924(%rbp), %edx
leaq -0x598(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4630
jmp 0x2ed57
leaq -0x598(%rbp), %rdi
leaq -0x235(%rbp), %rsi
callq 0x4520
jmp 0x2ed6c
movsbl -0x235(%rbp), %eax
cmpl $0x6e, %eax
je 0x2ee1f
movq 0x65265(%rip), %rdi     # 0x93fe8
leaq 0x3799c(%rip), %rsi     # 0x66726
callq 0x43c0
movq %rax, -0x930(%rbp)
jmp 0x2ed98
movq -0x930(%rbp), %rdi
movq 0x651f2(%rip), %rsi     # 0x93f98
callq 0x4400
jmp 0x2edad
movl $0x1, %edi
callq 0x4470
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2f265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2f259
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2f24d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x598(%rbp), %rdi
callq 0x4310
jmp 0x2f24d
leaq -0x598(%rbp), %rdi
leaq -0x3e4(%rbp), %rsi
callq 0x4070
movq %rax, -0x938(%rbp)
jmp 0x2ee3b
movq -0x938(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x44b0
jmp 0x2ee50
movq -0x8f8(%rbp), %rdi
addq $0x20, %rdi
movl -0x3e4(%rbp), %eax
movl %eax, %esi
callq 0x30240
movq %rax, %rdi
leaq -0x408(%rbp), %rsi
callq 0x4720
jmp 0x2ee79
movq -0x8f8(%rbp), %rdi
addq $0x98, %rdi
leaq -0x408(%rbp), %rsi
callq 0x30f60
movq %rax, -0x940(%rbp)
jmp 0x2ee9c
movq -0x940(%rbp), %rdi
leaq -0x3e4(%rbp), %rsi
callq 0x23b00
jmp 0x2eeb1
leaq -0x598(%rbp), %rdi
callq 0x4310
movl -0x40c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40c(%rbp)
jmp 0x2ecfe
movl $0x0, -0x5a4(%rbp)
movl -0x5a4(%rbp), %eax
cmpl -0x230(%rbp), %eax
jge 0x2f01e
leaq -0x218(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x40b0
jmp 0x2ef02
movl $0x10, %edi
movl $0x8, %esi
callq 0x13950
movl %eax, -0x944(%rbp)
jmp 0x2ef19
movl -0x944(%rbp), %edx
leaq -0x730(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4630
jmp 0x2ef34
leaq -0x730(%rbp), %rdi
leaq -0x235(%rbp), %rsi
callq 0x4520
jmp 0x2ef49
movsbl -0x235(%rbp), %eax
cmpl $0x61, %eax
je 0x2efb3
movq 0x6508c(%rip), %rdi     # 0x93fe8
leaq 0x377c3(%rip), %rsi     # 0x66726
callq 0x43c0
movq %rax, -0x950(%rbp)
jmp 0x2ef71
movq -0x950(%rbp), %rdi
movq 0x65019(%rip), %rsi     # 0x93f98
callq 0x4400
jmp 0x2ef86
movl $0x1, %edi
callq 0x4470
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x730(%rbp), %rdi
callq 0x4310
jmp 0x2f24d
leaq -0x730(%rbp), %rdi
leaq -0x59c(%rbp), %rsi
callq 0x4070
movq %rax, -0x958(%rbp)
jmp 0x2efcf
movq -0x958(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x4070
jmp 0x2efe4
movq -0x8f8(%rbp), %rdi
movl -0x59c(%rbp), %esi
movl -0x5a0(%rbp), %edx
callq 0x2d990
jmp 0x2effe
leaq -0x730(%rbp), %rdi
callq 0x4310
movl -0x5a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5a4(%rbp)
jmp 0x2eedb
leaq -0x758(%rbp), %rdi
callq 0x4560
movl $0x0, -0x75c(%rbp)
movl -0x75c(%rbp), %eax
cmpl -0x230(%rbp), %eax
jge 0x2f1e4
leaq -0x218(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x40b0
jmp 0x2f05b
movl $0x10, %edi
movl $0x8, %esi
callq 0x13950
movl %eax, -0x95c(%rbp)
jmp 0x2f072
movl -0x95c(%rbp), %edx
leaq -0x8e8(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4630
jmp 0x2f08d
leaq -0x8e8(%rbp), %rdi
leaq -0x235(%rbp), %rsi
callq 0x4520
jmp 0x2f0a2
movsbl -0x235(%rbp), %eax
cmpl $0x65, %eax
je 0x2f123
movq 0x64f33(%rip), %rdi     # 0x93fe8
leaq 0x3766a(%rip), %rsi     # 0x66726
callq 0x43c0
movq %rax, -0x968(%rbp)
jmp 0x2f0ca
movq -0x968(%rbp), %rdi
movq 0x64ec0(%rip), %rsi     # 0x93f98
callq 0x4400
jmp 0x2f0df
movl $0x1, %edi
callq 0x4470
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2f241
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x8e8(%rbp), %rdi
callq 0x4310
jmp 0x2f241
leaq -0x8e8(%rbp), %rdi
leaq -0x758(%rbp), %rsi
callq 0x44b0
movq %rax, -0x970(%rbp)
jmp 0x2f13f
movq -0x970(%rbp), %rdi
leaq -0x734(%rbp), %rsi
callq 0x4070
jmp 0x2f154
movq -0x8f8(%rbp), %rdi
movl -0x734(%rbp), %eax
movl %eax, -0x97c(%rbp)
addq $0x38, %rdi
leaq -0x758(%rbp), %rsi
callq 0x30600
movq %rax, -0x978(%rbp)
jmp 0x2f180
movq -0x8f8(%rbp), %rdi
movq -0x978(%rbp), %rax
movl -0x97c(%rbp), %ecx
movl %ecx, (%rax)
addq $0x68, %rdi
leaq -0x734(%rbp), %rsi
callq 0x307c0
movq %rax, -0x988(%rbp)
jmp 0x2f1af
movq -0x988(%rbp), %rdi
leaq -0x758(%rbp), %rsi
callq 0x4040
jmp 0x2f1c4
leaq -0x8e8(%rbp), %rdi
callq 0x4310
movl -0x75c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x75c(%rbp)
jmp 0x2f034
leaq -0x218(%rbp), %rdi
callq 0x40c0
jmp 0x2f1f2
leaq -0x758(%rbp), %rdi
callq 0x4828
leaq -0x408(%rbp), %rdi
callq 0x4828
leaq -0x3e0(%rbp), %rdi
callq 0x4310
leaq -0x258(%rbp), %rdi
callq 0x4828
movl $0x0, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x4100
addq $0x990, %rsp            # imm = 0x990
popq %rbp
retq
leaq -0x758(%rbp), %rdi
callq 0x4828
leaq -0x408(%rbp), %rdi
callq 0x4828
leaq -0x3e0(%rbp), %rdi
callq 0x4310
leaq -0x258(%rbp), %rdi
callq 0x4828
leaq -0x218(%rbp), %rdi
callq 0x4100
movq -0x220(%rbp), %rdi
callq 0x46e0
nopl (%rax)