// File: Luthaf[P]zeopp/feature.cc
// Function: FEATURE::createSegments(ATOM_NETWORK*, VORONOI_NETWORK*, DIJKSTRA_NETWORK*, std::basic_fstream<char, std::char_traits<char>>&, int)
int FEATURE::createSegments(ATOM_NETWORK *uc,VORONOI_NETWORK *origVNet, DIJKSTRA_NETWORK *origDNet, std::fstream &output, int initIndex){
    nsegments = 0;
    segments = std::vector<int> ();
    segmentChannel(uc);
    if(nsegments == 0){
        std::cerr << "Error occurred during channel segmentation. No segments were found." << "\n"
        << "Exiting..." << "\n";
        exit(1);
    }
    
    std::vector< std::vector<int> > nodesForSegments = std::vector < std::vector<int> > (nsegments, std::vector<int> ());
    std::vector<CHANNEL> segChannels = std::vector<CHANNEL> ();
    for(unsigned int i = 0; i < segments.size(); i++){
        nodesForSegments[segments[i]].push_back(reverseIDMappings.find(i)->second);
    }
    
    int zeroVecs [3][3] = {{0, 0, 0},{ 0, 0, 0}, {0, 0, 0}};
    
    for(int i = 0; i < nsegments; i++){
        DIJKSTRA_NETWORK segNet;
        DIJKSTRA_NETWORK::filterDnetEdges(nodesForSegments[i], origVNet, &segNet);
        std::vector<bool> infoStorage; std::vector<CHANNEL> channels;
        findChannels(&segNet, &infoStorage, &channels);
        int dim;
        if(channels.size() != 0){
            dim = channels[0].dimensionality;
            segChannels.push_back(CHANNEL(nodesForSegments[i], origDNet, dim, channels[0].basis));
        }
        else{
            dim = 0;
            segChannels.push_back(CHANNEL(nodesForSegments[i], origDNet, 0, zeroVecs));
        }
        segChannels[i].writeToVMD("segment", initIndex + i, output);
    }
    return nsegments;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x478(%rbp)
movl $0x0, 0x138(%rax)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0x48(%rbp), %rdi
callq 0xd0d0
movq -0x478(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
leaq -0x48(%rbp), %rsi
callq 0x22ed0
leaq -0x48(%rbp), %rdi
callq 0xec80
movq -0x478(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xd8840
movq -0x478(%rbp), %rax
cmpl $0x0, 0x138(%rax)
jne 0xdacab
movq 0x198388(%rip), %rdi    # 0x272ff0
leaq 0x120cde(%rip), %rsi    # 0x1fb94d
callq 0x5540
movq %rax, %rdi
leaq 0x11e9a7(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x12068d(%rip), %rsi    # 0x1fb31a
callq 0x5540
movq %rax, %rdi
leaq 0x11e989(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x1, %edi
callq 0x67c0
movq -0x478(%rbp), %rax
movslq 0x138(%rax), %rax
movq %rax, -0x490(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
leaq -0x80(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0xd0d0
leaq -0x81(%rbp), %rdi
movq %rdi, -0x480(%rbp)
callq 0x12b40
movq -0x490(%rbp), %rsi
movq -0x488(%rbp), %rdx
movq -0x480(%rbp), %rcx
leaq -0x60(%rbp), %rdi
callq 0xaedd0
jmp 0xdad12
leaq -0x81(%rbp), %rdi
callq 0x13770
leaq -0x80(%rbp), %rdi
callq 0xec80
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x52a0
leaq -0xb0(%rbp), %rdi
callq 0x84dd0
movl $0x0, -0xb4(%rbp)
movq -0x478(%rbp), %rdi
movl -0xb4(%rbp), %eax
movq %rax, -0x498(%rbp)
addq $0x140, %rdi            # imm = 0x140
callq 0x10090
movq %rax, %rcx
movq -0x498(%rbp), %rax
cmpq %rcx, %rax
jae 0xdae65
movq -0x478(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0xed60
movslq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x10890
movq -0x478(%rbp), %rdi
movq %rax, -0x4a8(%rbp)
addq $0x30, %rdi
movl -0xb4(%rbp), %eax
movl %eax, -0xc4(%rbp)
leaq -0xc4(%rbp), %rsi
callq 0x102e0
movq %rax, -0x4a0(%rbp)
jmp 0xdaddd
movq -0x4a0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x10350
movq -0x4a8(%rbp), %rdi
movq %rax, %rsi
addq $0x4, %rsi
callq 0xd1b0
jmp 0xdae0c
jmp 0xdae0e
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0xdad50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x81(%rbp), %rdi
callq 0x13770
leaq -0x80(%rbp), %rdi
callq 0xec80
jmp 0xdb2c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb2b4
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0x24, %edx
callq 0x52a0
movl $0x0, -0xf4(%rbp)
movq -0x478(%rbp), %rcx
movl -0xf4(%rbp), %eax
cmpl 0x138(%rcx), %eax
jge 0xdb27d
leaq -0x158(%rbp), %rdi
callq 0x94790
jmp 0xdaea9
movslq -0xf4(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x10890
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
callq 0xeec0
jmp 0xdaeca
movq -0x18(%rbp), %rsi
leaq -0x170(%rbp), %rdi
leaq -0x158(%rbp), %rdx
callq 0x94c30
jmp 0xdaee3
leaq -0x170(%rbp), %rdi
callq 0xec80
leaq -0x198(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
callq 0xf670
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x84dd0
movq -0x4b8(%rbp), %rsi
movq -0x4b0(%rbp), %rdx
leaq -0x158(%rbp), %rdi
callq 0xc9b80
jmp 0xdaf31
leaq -0x1b0(%rbp), %rdi
callq 0xd62c0
cmpq $0x0, %rax
je 0xdb09d
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b0(%rbp), %rdi
callq 0xe0560
movl 0x108(%rax), %eax
movl %eax, -0x1b4(%rbp)
movslq -0xf4(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x10890
movq %rax, %rsi
leaq -0x300(%rbp), %rdi
callq 0xeec0
jmp 0xdaf84
movq -0x20(%rbp), %rax
movq %rax, -0x4c8(%rbp)
movl -0x1b4(%rbp), %eax
movl %eax, -0x4bc(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b0(%rbp), %rdi
callq 0xe0560
movq -0x4c8(%rbp), %rdx
movl -0x4bc(%rbp), %ecx
movq %rax, %r8
addq $0x10c, %r8             # imm = 0x10C
leaq -0x2e8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0xe0830
jmp 0xdafd7
leaq -0xb0(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0xce2a0
jmp 0xdafec
leaq -0x2e8(%rbp), %rdi
callq 0x86880
leaq -0x300(%rbp), %rdi
callq 0xec80
jmp 0xdb15c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb26f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xec80
jmp 0xdb26f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb257
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb08c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x86880
leaq -0x300(%rbp), %rdi
callq 0xec80
jmp 0xdb257
movl $0x0, -0x1b4(%rbp)
movslq -0xf4(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x10890
movq %rax, %rsi
leaq -0x448(%rbp), %rdi
callq 0xeec0
jmp 0xdb0c8
movq -0x20(%rbp), %rdx
leaq -0x430(%rbp), %rdi
leaq -0x448(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xf0(%rbp), %r8
callq 0xe0830
jmp 0xdb0ea
leaq -0xb0(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xce2a0
jmp 0xdb0ff
leaq -0x430(%rbp), %rdi
callq 0x86880
leaq -0x448(%rbp), %rdi
callq 0xec80
jmp 0xdb15c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb14b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x86880
leaq -0x448(%rbp), %rdi
callq 0xec80
jmp 0xdb257
movslq -0xf4(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0xe0560
movq %rax, -0x4d8(%rbp)
leaq -0x469(%rbp), %rdi
movq %rdi, -0x4d0(%rbp)
callq 0x5900
movq -0x4d0(%rbp), %rdx
leaq 0x1207fa(%rip), %rsi    # 0x1fb991
leaq -0x468(%rbp), %rdi
callq 0x47530
jmp 0xdb1a5
movq -0x4d8(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0xf4(%rbp), %eax
addl %eax, %edx
movq -0x28(%rbp), %rcx
leaq -0x468(%rbp), %rsi
callq 0xc9150
jmp 0xdb1c9
leaq -0x468(%rbp), %rdi
callq 0x5300
leaq -0x469(%rbp), %rdi
callq 0x55d0
leaq -0x1b0(%rbp), %rdi
callq 0x84ee0
leaq -0x198(%rbp), %rdi
callq 0xf9b0
leaq -0x158(%rbp), %rdi
callq 0xf840
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0xdae82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb24b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x468(%rbp), %rdi
callq 0x5300
leaq -0x469(%rbp), %rdi
callq 0x55d0
leaq -0x1b0(%rbp), %rdi
callq 0x84ee0
leaq -0x198(%rbp), %rdi
callq 0xf9b0
leaq -0x158(%rbp), %rdi
callq 0xf840
jmp 0xdb2b4
movq -0x478(%rbp), %rax
movl 0x138(%rax), %eax
movl %eax, -0x4dc(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x84ee0
leaq -0x60(%rbp), %rdi
callq 0x108b0
movl -0x4dc(%rbp), %eax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0x84ee0
leaq -0x60(%rbp), %rdi
callq 0x108b0
movq -0x90(%rbp), %rdi
callq 0x58f0
nopw %cs:(%rax,%rax)