// File: /workspace/github_cpp_makefile_star2_O1/arush15june[P]DFA-CPP/dfa.cpp
// Function: build_dfa_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
DFA build_dfa_from_file(std::string filename) {
    /*
    Build DFA and StateDiagram from file.

    File Structure:
        (Adjacency List's)

    First Line
        q -> initial state
    Second Line
        f -> final state
    Next Line(s):
        <vertex_no>: <weight> <vertex_no> | [<weight> <vertex_no> ... | ...] 
    ``` dfa.gph
    1               -> initial state
    2               -> final state
    1: 97 2 | 37 3    -> Adjacency List for Node 1
    2: 97 1 | 27 3
    3: 37 1 | 27 2
    ```

    @param std::string filename: filename to read from
    @return DFA dfa: returns a DFA.
    */

    StateDiagram state_diagram;
    DFA dfa;
    
    std::ifstream state_file(filename);
    std::string str;
    int counter = 0;
    int nvertices, nedges;

    while(std::getline(state_file, str)) {
        if(counter == 0) {
            dfa.setInitialState(std::stoi(str));
        }
        else if(counter == 1){
            dfa.setFinalState(std::stoi(str));
        }
        else {
            /*  Build State Diagram
                - Split at colon.
                - set current state
                - Split the part after colon at |
                - Iterate over split at |
                    - Trim whitespace
                    - Split pair at space
                    - Convert to integers
                        weight -> pair[0]
                        state_no_y -> pair[1]
                    - insert edge in state diagram.
            */
            auto split_at_colon = split(str, ':');
            auto state = std::stoi(split_at_colon[0]);

            nvertices += 1;
            
            auto adj_list_vector = split(split_at_colon[1], '|');
            auto degree = 0;
            for(auto &pair: adj_list_vector) {
                auto trimmed_pair = trim_copy(pair);
                auto split_pair = split(trimmed_pair, ' ');
                
                int weight = std::stoi(split_pair[0]);
                int state_no_y = std::stoi(split_pair[1]);
                
                state_diagram.insertEdge(state, weight, state_no_y);
                nedges += 1;
                degree += 1;
            }
            state_diagram.degree[state] = degree;
        }
        counter++;
    }
    state_diagram.nvertices = nvertices;
    state_diagram.nedges = nedges;

    dfa.setStateDiagram(state_diagram);

    return dfa;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xde08, %rsp           # imm = 0xDE08
movq %rsi, %r14
movq %rdi, %r13
leaq -0x70a8(%rbp), %r15
xorl %r12d, %r12d
movl $0x5dd8, %edx           # imm = 0x5DD8
movq %r15, %rdi
xorl %esi, %esi
callq 0x20d0
movq %r12, 0x6d7c(%r15)
movl $0x5dd8, %edx           # imm = 0x5DD8
movq %r13, %rdi
xorl %esi, %esi
callq 0x20d0
movq %r12, 0x6d7c(%r13)
leaq -0x320(%rbp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x21f0
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x48(%rbp), %r14
movq %r13, -0x30(%rbp)
leaq -0x320(%rbp), %rbx
movq -0x320(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %edx
movq %rbx, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2230
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2b8e
cmpl $0x1, %r12d
je 0x264a
testl %r12d, %r12d
jne 0x26c6
movq %r12, %r14
movq -0xc0(%rbp), %r12
callq 0x2040
movq %rax, %r15
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
movl $0xa, %edx
callq 0x21a0
cmpq %r12, -0x80(%rbp)
je 0x2cfe
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x2d0a
movl (%r15), %ecx
cmpl $0x22, %ecx
je 0x2d0a
testl %ecx, %ecx
movq %r14, %r12
jne 0x2641
movl %ebx, (%r15)
movl %eax, 0x6d88(%r13)
jmp 0x26b6
movq %r12, %r14
movq -0xc0(%rbp), %r12
callq 0x2040
movq %rax, %r15
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
movl $0xa, %edx
callq 0x21a0
cmpq %r12, -0x80(%rbp)
je 0x2d16
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x2d22
movl (%r15), %ecx
cmpl $0x22, %ecx
je 0x2d22
testl %ecx, %ecx
movq %r14, %r12
jne 0x26af
movl %ebx, (%r15)
movl %eax, 0x6d8c(%r13)
leaq -0x320(%rbp), %rbx
leaq -0x48(%rbp), %r14
jmp 0x2b86
leaq -0x118(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x3a, %edx
callq 0x23fc
movq -0x118(%rbp), %rax
movq (%rax), %r15
callq 0x2040
movl (%rax), %ebx
movq %rax, -0x38(%rbp)
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0x80(%rbp), %rsi
movl $0xa, %edx
callq 0x21a0
cmpq %r15, -0x80(%rbp)
je 0x2d2e
movq %rax, %rdx
addq $-0x80000000, %rax      # imm = 0x80000000
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
cmpq %rcx, %rax
jb 0x2d3a
movq -0x38(%rbp), %rax
movl (%rax), %eax
cmpl $0x22, %eax
je 0x2d3a
movq %rdx, -0xa0(%rbp)
testl %eax, %eax
jne 0x2750
movq -0x38(%rbp), %rax
movl %ebx, (%rax)
movq %r12, -0xc8(%rbp)
movq -0x118(%rbp), %rsi
addq $0x20, %rsi
leaq -0x100(%rbp), %rdi
movl $0x7c, %edx
callq 0x23fc
movq -0x100(%rbp), %r12
movq -0xf8(%rbp), %rax
movq %rax, -0xd0(%rbp)
xorl %ebx, %ebx
cmpq %rax, %r12
je 0x2b4c
movq %r14, -0x58(%rbp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0x3740
movl %ebx, -0x94(%rbp)
movq -0x58(%rbp), %r14
movq -0x50(%rbp), %rax
leaq (%r14,%rax), %rcx
movq %rax, %rbx
sarq $0x2, %rbx
movq %r14, %r13
testq %rbx, %rbx
jle 0x282a
movq %rcx, -0x60(%rbp)
andq $-0x4, %rax
movq %rax, %r13
addq %r14, %r13
incq %rbx
leaq 0x3(%r14), %r15
movsbl -0x3(%r15), %edi
callq 0x2050
testl %eax, %eax
je 0x285b
movsbl -0x2(%r15), %edi
callq 0x2050
testl %eax, %eax
je 0x2861
movsbl -0x1(%r15), %edi
callq 0x2050
testl %eax, %eax
je 0x2867
movsbl (%r15), %edi
callq 0x2050
testl %eax, %eax
je 0x286a
decq %rbx
addq $0x4, %r15
cmpq $0x1, %rbx
jg 0x27e2
movq -0x60(%rbp), %rcx
movq %rcx, %rax
subq %r13, %rax
cmpq $0x1, %rax
je 0x2886
cmpq $0x2, %rax
je 0x2870
movq %rcx, %r15
cmpq $0x3, %rax
jne 0x28a7
movq %rcx, %rbx
movsbl (%r13), %edi
callq 0x2050
testl %eax, %eax
je 0x28a1
incq %r13
jmp 0x2873
addq $-0x3, %r15
jmp 0x286a
addq $-0x2, %r15
jmp 0x286a
decq %r15
movq -0x60(%rbp), %rcx
jmp 0x28a7
movq %rcx, %rbx
movsbl (%r13), %edi
callq 0x2050
testl %eax, %eax
je 0x28a1
incq %r13
jmp 0x2889
movq %rcx, %rbx
movsbl (%r13), %edi
callq 0x2050
testl %eax, %eax
movq %rbx, %rcx
cmovneq %rbx, %r13
movq %r13, %r15
jmp 0x28a7
movq %r13, %r15
movq %rbx, %rcx
cmpq %r15, %rcx
je 0x28c3
subq %r14, %r15
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movq %r15, %rdx
movq -0x30(%rbp), %r13
callq 0x2190
jmp 0x28d3
movq $0x0, -0x50(%rbp)
movb $0x0, (%r14)
movq -0x30(%rbp), %r13
movq -0x58(%rbp), %r15
movq -0x50(%rbp), %r14
leaq (%r15,%r14), %rbx
sarq $0x2, %r14
testq %r14, %r14
jle 0x2949
leaq (,%r14,4), %rax
movq %rbx, %r13
subq %rax, %r13
incq %r14
movsbl -0x1(%rbx), %edi
callq 0x2050
testl %eax, %eax
je 0x29ab
movsbl -0x2(%rbx), %edi
callq 0x2050
testl %eax, %eax
je 0x299c
movsbl -0x3(%rbx), %edi
callq 0x2050
testl %eax, %eax
je 0x29a1
movsbl -0x4(%rbx), %edi
callq 0x2050
testl %eax, %eax
je 0x29a7
addq $-0x4, %rbx
decq %r14
cmpq $0x1, %r14
jg 0x28f9
movq %r13, %rbx
movq -0x30(%rbp), %r13
movq %rbx, %rcx
subq %r15, %rcx
cmpq $0x1, %rcx
leaq -0x48(%rbp), %r14
je 0x2988
cmpq $0x2, %rcx
je 0x2978
movq %r15, %rax
cmpq $0x3, %rcx
jne 0x29b6
movsbl -0x1(%rbx), %edi
callq 0x2050
testl %eax, %eax
je 0x2997
decq %rbx
movsbl -0x1(%rbx), %edi
callq 0x2050
testl %eax, %eax
je 0x2997
decq %rbx
movsbl -0x1(%rbx), %edi
callq 0x2050
testl %eax, %eax
cmovneq %r15, %rbx
movq %rbx, %rax
jmp 0x29b6
decq %rbx
jmp 0x29ab
addq $-0x2, %rbx
jmp 0x29ab
addq $-0x3, %rbx
movq %rbx, %rax
movq -0x30(%rbp), %r13
leaq -0x48(%rbp), %r14
movq %rax, %rcx
subq %r15, %rcx
movq %rcx, -0x50(%rbp)
movb $0x0, (%rax)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq -0x58(%rbp), %rax
cmpq %r14, %rax
je 0x29e2
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x29e9
movups (%r14), %xmm0
movups %xmm0, (%rcx)
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %r14, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x20, %edx
callq 0x23fc
movq -0xe8(%rbp), %rax
movq (%rax), %r13
movq -0x38(%rbp), %rax
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r13, %rdi
leaq -0x88(%rbp), %rsi
movl $0xa, %edx
callq 0x21a0
cmpq %r13, -0x88(%rbp)
je 0x2cc6
movq %rax, %r15
addq $-0x80000000, %rax      # imm = 0x80000000
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
cmpq %rcx, %rax
movq -0x38(%rbp), %r13
jb 0x2cf2
movl (%r13), %eax
cmpl $0x22, %eax
je 0x2cf2
testl %eax, %eax
jne 0x2a82
movl %ebx, (%r13)
movq -0xe8(%rbp), %rax
movq %r13, %rcx
movq 0x20(%rax), %r13
movl (%rcx), %ebx
movl $0x0, (%rcx)
movq %r13, %rdi
leaq -0x88(%rbp), %rsi
movl $0xa, %edx
callq 0x21a0
cmpq %r13, -0x88(%rbp)
je 0x2cd6
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
movq -0x30(%rbp), %r13
jb 0x2ce6
movq -0x38(%rbp), %rcx
movl (%rcx), %ecx
cmpl $0x22, %ecx
je 0x2ce6
testl %ecx, %ecx
jne 0x2af0
movq -0x38(%rbp), %rcx
movl %ebx, (%rcx)
leaq -0x70a8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movl %r15d, %edx
movl %eax, %ecx
callq 0x3364
leaq -0xe8(%rbp), %rdi
callq 0x32fa
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x2b2d
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2170
incl -0x90(%rbp)
movl -0x94(%rbp), %ebx
incl %ebx
addq $0x20, %r12
cmpq -0xd0(%rbp), %r12
jne 0x2793
incl -0x8c(%rbp)
movslq -0xa0(%rbp), %rax
movl %ebx, -0x12d0(%rbp,%rax,4)
leaq -0x100(%rbp), %rdi
callq 0x32fa
leaq -0x118(%rbp), %rdi
callq 0x32fa
movq -0xc8(%rbp), %r12
leaq -0x320(%rbp), %rbx
incl %r12d
jmp 0x2591
movl -0x8c(%rbp), %eax
movl %eax, -0x32c(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x328(%rbp)
xorl %ebx, %ebx
leaq (%rbx,%rbp), %r15
addq $-0xde30, %r15          # imm = 0xFFFF21D0
leaq (%rbx,%rbp), %rsi
addq $-0x70a8, %rsi          # imm = 0x8F58
movq %r15, %rdi
callq 0x36c0
addq $0x18, %rbx
cmpq $0x5dd8, %rbx           # imm = 0x5DD8
jne 0x2ba8
movl $0x5dd8, %eax           # imm = 0x5DD8
leaq -0xde30(%rbp), %r15
addq %rax, %r15
leaq -0x70a8(%rbp), %rsi
addq %rax, %rsi
movl $0xfac, %edx            # imm = 0xFAC
movq %r15, %rdi
callq 0x2130
xorl %ebx, %ebx
leaq (%rbx,%r13), %rdi
leaq (%rbx,%rbp), %rsi
addq $-0xde30, %rsi          # imm = 0xFFFF21D0
callq 0x35a2
addq $0x18, %rbx
cmpq $0x5dd8, %rbx           # imm = 0x5DD8
jne 0x2bfb
movq %r13, %rdi
addq $0x5dd8, %rdi           # imm = 0x5DD8
movl $0xfac, %edx            # imm = 0xFAC
movq %r15, %rsi
callq 0x2130
movl $0x5dd8, %ebx           # imm = 0x5DD8
movq -0xde48(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x2c55
movq -0xde38(%rbp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2170
addq $-0x18, %rbx
jne 0x2c38
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2c7d
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2170
leaq -0x320(%rbp), %rdi
callq 0x2060
movl $0x5dd8, %ebx           # imm = 0x5DD8
movq -0x70c0(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x2cab
movq -0x70b0(%rbp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2170
addq $-0x18, %rbx
jne 0x2c8e
movq %r13, %rax
addq $0xde08, %rsp           # imm = 0xDE08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13b0(%rip), %rdi      # 0x407d
movq -0x38(%rbp), %r13
callq 0x20e0
leaq 0x13a0(%rip), %rdi      # 0x407d
movq -0x30(%rbp), %r13
callq 0x20e0
leaq 0x1390(%rip), %rdi      # 0x407d
callq 0x21b0
leaq 0x1384(%rip), %rdi      # 0x407d
callq 0x21b0
leaq 0x1378(%rip), %rdi      # 0x407d
callq 0x20e0
leaq 0x136c(%rip), %rdi      # 0x407d
callq 0x21b0
leaq 0x1360(%rip), %rdi      # 0x407d
callq 0x20e0
leaq 0x1354(%rip), %rdi      # 0x407d
callq 0x21b0
leaq 0x1348(%rip), %rdi      # 0x407d
callq 0x20e0
leaq 0x133c(%rip), %rdi      # 0x407d
callq 0x21b0
movq %rax, %r14
jmp 0x2e73
movq %rax, %r14
jmp 0x2e39
jmp 0x2dba
movq %rax, %r14
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2d6a
movq -0x38(%rbp), %rax
movl %ebx, (%rax)
movq -0x30(%rbp), %r13
jmp 0x2e39
jmp 0x2d75
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x2db1
movl %ebx, (%r15)
jmp 0x2db1
movq %rax, %r14
leaq -0xde30(%rbp), %rsi
movq %r15, %rdi
callq 0x2280
jmp 0x2e45
movq %rax, %r14
testq %rbx, %rbx
je 0x2db1
leaq -0xde30(%rbp), %rsi
movq %r15, %rdi
callq 0x2250
movq -0x30(%rbp), %r13
jmp 0x2e45
movq %rax, %r14
jmp 0x2e45
movq %rax, %r14
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x2e2d
movq -0x48(%rbp), %rsi
jmp 0x2e25
movq %rax, %r14
jmp 0x2e08
movq %rax, %r14
jmp 0x2e14
movq %rax, %r14
jmp 0x2e2d
movq %rax, %r14
cmpl $0x0, (%r13)
movq %r13, %rax
movq -0x30(%rbp), %r13
je 0x2e06
jmp 0x2e08
movq %rax, %r14
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2e08
movl %ebx, (%rax)
leaq -0xe8(%rbp), %rdi
callq 0x32fa
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x2e2d
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2170
leaq -0x100(%rbp), %rdi
callq 0x32fa
leaq -0x118(%rbp), %rdi
callq 0x32fa
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2e67
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2170
leaq -0x320(%rbp), %rdi
callq 0x2060
movl $0x5dd8, %ebx           # imm = 0x5DD8
movq -0x18(%r13,%rbx), %rdi
testq %rdi, %rdi
je 0x2e8f
movq -0x8(%r13,%rbx), %rsi
subq %rdi, %rsi
callq 0x2170
addq $-0x18, %rbx
jne 0x2e78
movl $0x5dd8, %ebx           # imm = 0x5DD8
movq -0x70c0(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x2eb7
movq -0x70b0(%rbp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2170
addq $-0x18, %rbx
jne 0x2e9a
movq %r14, %rdi
callq 0x2210