// File: /workspace/github_c_makefile_star2_O3/stonezwr[P]SpiKL-IP/parser.C
// Function: Parser::Parse(char const*)
void Parser::Parse(const char * filename){
    int mnist_duration = 500; // the default mnist duration (duration of the possion spike train)
    int i;
    char linestring[8192];
    char ** token = new char*[64];
    FILE * fp = fopen(filename,"r");
    assert(fp != NULL);

    assert(fp != 0);
    while(fgets(linestring, 8191, fp) != NULL){
        if(strlen(linestring) <= 1) continue;
        if(linestring[0] == '#') continue;

        token[0] = strtok(linestring," \t\n");
        assert(token[0] != NULL);

       if(strcmp(token[0],"neurongroup")==0){
            // neurongroup name number
            token[1] = strtok(NULL," \t\n");
            assert(token[1] != NULL);
            token[2] = strtok(NULL," \t\n");
            assert(token[2] != NULL);
            token[3] = strtok(NULL," \t\n");
            assert(token[3] != NULL);
            // read the v_mem from the netlist if applicable
            token[4] = strtok(NULL," \t\n");
            double v_mem = token[4] == NULL ? LSM_V_THRESH : atof(token[4]);
            ParseNeuronGroup(token[1], atoi(token[2]), token[3], v_mem);
        }else if(strcmp(token[0],"column")==0){
            token[1] = strtok(NULL," \t\n");
            assert(token[1] != NULL);
            token[2] = strtok(NULL," \t\n");
            assert(token[2] != NULL);
            token[3] = strtok(NULL," \t\n");
            assert(token[3] != NULL);
            token[4] = strtok(NULL," \t\n");
            assert(token[4] != NULL);

            assert(_network->CheckExistence(token[1]) == false);
            int dim1 = atoi(token[2]);
            int dim2 = atoi(token[3]);
            int dim3 = atoi(token[4]);
            assert((dim1>0)&&(dim2>0)&&(dim3>0));
            _network->LSMAddNeuronGroup(token[1],dim1,dim2,dim3);
        }else if(strcmp(token[0],"lsmsynapse")==0){
            token[1] = strtok(NULL," \t\n");
            assert(token[1] != NULL);
            token[2] = strtok(NULL," \t\n");
            assert(token[2] != NULL);
            token[3] = strtok(NULL," \t\n");
            assert(token[3] != NULL);
            token[4] = strtok(NULL," \t\n");
            assert(token[4] != NULL);
            token[5] = strtok(NULL," \t\n");
            assert(token[5] != NULL);
            token[6] = strtok(NULL," \t\n");
            assert(token[6] != NULL);
            token[7] = strtok(NULL," \t\n");
            assert(token[7] != NULL);

            assert(_network->CheckExistence(token[1]) == true);
            assert(_network->CheckExistence(token[2]) == true);

            ParseLSMSynapse(token[1],token[2],atoi(token[3]),atoi(token[4]),atoi(token[5]),atoi(token[6]),token[7]);
        }else if(strcmp(token[0],"speech")==0){
            token[1] = strtok(NULL," \t\n");
            assert(token[1] != NULL);
            token[2] = strtok(NULL," \t\n");
            assert(token[2] != NULL);

            ParseSpeech(atoi(token[1]),token[2]);
        }else if(strcmp(token[0],"end")==0){
            break;
        }else{
            cout<<token[0]<<endl;
            assert(0);
        }

    }
    fclose(fp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2038, %rsp           # imm = 0x2038
movq %rsi, %rax
movq %rdi, %rbp
leaq 0x55f4(%rip), %rsi      # 0x179da
movq %rax, %rdi
callq 0x3360
testq %rax, %rax
je 0x12a81
movq %rax, %r12
leaq 0x30(%rsp), %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %rax, %rdx
callq 0x34c0
testq %rax, %rax
je 0x12793
leaq 0x30(%rsp), %r13
leaq 0x71c8(%rip), %r15      # 0x195e9
movq %rbp, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r13, %rdi
callq 0x3150
cmpq $0x2, %rax
jb 0x1277a
cmpb $0x23, 0x30(%rsp)
je 0x1277a
movq %r13, %rdi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x127f6
movq %rax, %rbx
movq %rax, %rdi
leaq 0x7184(%rip), %rsi      # 0x195ed
callq 0x33f0
testl %eax, %eax
je 0x12501
movq %rbx, %rdi
leaq 0x719b(%rip), %rsi      # 0x1961b
callq 0x33f0
testl %eax, %eax
je 0x1258b
movq %rbx, %rdi
leaq 0x71c8(%rip), %rsi      # 0x1965f
callq 0x33f0
testl %eax, %eax
je 0x1264a
movq %rbx, %rdi
leaq 0x58bd(%rip), %rsi      # 0x17d6b
callq 0x33f0
testl %eax, %eax
jne 0x127ad
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12891
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12872
movq %rax, %r14
movq %rbx, %rdi
callq 0x3490
movq %rbp, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0x12cce
jmp 0x1277a
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12853
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12834
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12815
movq %r15, %rsi
movq %rax, %r15
xorl %edi, %edi
callq 0x34a0
movsd 0x513b(%rip), %xmm0     # 0x17690
testq %rax, %rax
je 0x12562
movq %rax, %rdi
callq 0x33a0
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
callq 0x3490
movq %rbp, %rdi
movq %rbx, %rsi
movl %eax, %edx
movq %r15, %rcx
movsd 0x8(%rsp), %xmm0
callq 0x12aa0
jmp 0x12773
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x1294b
movq %rax, %r13
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x1292c
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x1290d
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x128ee
movq %rax, %r15
movq (%rbp), %rdi
movq %r13, %rsi
callq 0xcd10
testb %al, %al
jne 0x128cf
movq %rbx, %rdi
callq 0x3490
movl %eax, %ebx
movq %r14, %rdi
callq 0x3490
movl %eax, %ebp
movq %r15, %rdi
callq 0x3490
testl %ebx, %ebx
jle 0x128b0
testl %ebp, %ebp
jle 0x128b0
testl %eax, %eax
jle 0x128b0
movq 0x18(%rsp), %r8
movq (%r8), %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %ebp, %ecx
movq %r8, %rbp
movl %eax, %r8d
callq 0xd322
jmp 0x1276e
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x12a62
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12a43
movq %rax, %r13
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12a24
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12a05
movq %rax, %r12
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x129e6
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x129c7
movq %r15, %rsi
movq %rax, %r15
movq %r14, 0x28(%rsp)
movq %r13, %r14
xorl %edi, %edi
callq 0x34a0
testq %rax, %rax
je 0x129a8
movq %rax, %r13
movq 0x18(%rsp), %rbp
movq (%rbp), %rdi
movq 0x8(%rsp), %rsi
callq 0xcd10
testb %al, %al
je 0x1296a
movq (%rbp), %rdi
movq %r14, %rsi
callq 0xcd10
testb %al, %al
je 0x12989
movq %rbx, %rdi
callq 0x3490
movl %eax, 0x14(%rsp)
movq %r12, %rdi
callq 0x3490
movl %eax, %ebx
movq 0x28(%rsp), %rdi
callq 0x3490
movl %eax, %r12d
movq %r15, %rdi
callq 0x3490
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
movl 0x14(%rsp), %ecx
movl %ebx, %r8d
movl %r12d, %r9d
pushq %r13
pushq %rax
callq 0x12c12
addq $0x10, %rsp
movq 0x20(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x6e6f(%rip), %r15      # 0x195e9
movq %r13, %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %r12, %rdx
callq 0x34c0
testq %rax, %rax
jne 0x1242b
movq %r12, %rdi
callq 0x32d0
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5a18(%rip), %rsi      # 0x181cc
movq %rbx, %rdi
callq 0x33f0
testl %eax, %eax
je 0x12793
movq 0xe809(%rip), %rdi      # 0x20fd0
movq %rbx, %rsi
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x5bf2(%rip), %rdi      # 0x183d0
leaq 0x6dda(%rip), %rsi      # 0x195bf
leaq 0x6ddc(%rip), %rcx      # 0x195c8
movl $0x68, %edx
callq 0x31b0
leaq 0x531f(%rip), %rdi      # 0x17b1c
leaq 0x6dbb(%rip), %rsi      # 0x195bf
leaq 0x6dbd(%rip), %rcx      # 0x195c8
movl $0x2b, %edx
callq 0x31b0
leaq 0x6dee(%rip), %rdi      # 0x1960a
leaq 0x6d9c(%rip), %rsi      # 0x195bf
leaq 0x6d9e(%rip), %rcx      # 0x195c8
movl $0x34, %edx
callq 0x31b0
leaq 0x6dbe(%rip), %rdi      # 0x195f9
leaq 0x6d7d(%rip), %rsi      # 0x195bf
leaq 0x6d7f(%rip), %rcx      # 0x195c8
movl $0x32, %edx
callq 0x31b0
leaq 0x52d3(%rip), %rdi      # 0x17b2d
leaq 0x6d5e(%rip), %rsi      # 0x195bf
leaq 0x6d60(%rip), %rcx      # 0x195c8
movl $0x30, %edx
callq 0x31b0
leaq 0x6d80(%rip), %rdi      # 0x195f9
leaq 0x6d3f(%rip), %rsi      # 0x195bf
leaq 0x6d41(%rip), %rcx      # 0x195c8
movl $0x61, %edx
callq 0x31b0
leaq 0x5295(%rip), %rdi      # 0x17b2d
leaq 0x6d20(%rip), %rsi      # 0x195bf
leaq 0x6d22(%rip), %rcx      # 0x195c8
movl $0x5f, %edx
callq 0x31b0
leaq 0x5bda(%rip), %rdi      # 0x18491
leaq 0x6d01(%rip), %rsi      # 0x195bf
leaq 0x6d03(%rip), %rcx      # 0x195c8
movl $0x47, %edx
callq 0x31b0
leaq 0x6d5d(%rip), %rdi      # 0x19633
leaq 0x6ce2(%rip), %rsi      # 0x195bf
leaq 0x6ce4(%rip), %rcx      # 0x195c8
movl $0x43, %edx
callq 0x31b0
leaq 0x6d2d(%rip), %rdi      # 0x19622
leaq 0x6cc3(%rip), %rsi      # 0x195bf
leaq 0x6cc5(%rip), %rcx      # 0x195c8
movl $0x41, %edx
callq 0x31b0
leaq 0x6cf6(%rip), %rdi      # 0x1960a
leaq 0x6ca4(%rip), %rsi      # 0x195bf
leaq 0x6ca6(%rip), %rcx      # 0x195c8
movl $0x3f, %edx
callq 0x31b0
leaq 0x6cc6(%rip), %rdi      # 0x195f9
leaq 0x6c85(%rip), %rsi      # 0x195bf
leaq 0x6c87(%rip), %rcx      # 0x195c8
movl $0x3d, %edx
callq 0x31b0
leaq 0x51db(%rip), %rdi      # 0x17b2d
leaq 0x6c66(%rip), %rsi      # 0x195bf
leaq 0x6c68(%rip), %rcx      # 0x195c8
movl $0x3b, %edx
callq 0x31b0
leaq 0x6d2c(%rip), %rdi      # 0x1969d
leaq 0x6c47(%rip), %rsi      # 0x195bf
leaq 0x6c49(%rip), %rcx      # 0x195c8
movl $0x59, %edx
callq 0x31b0
leaq 0x6d38(%rip), %rdi      # 0x196c8
leaq 0x6c28(%rip), %rsi      # 0x195bf
leaq 0x6c2a(%rip), %rcx      # 0x195c8
movl $0x5a, %edx
callq 0x31b0
leaq 0x6cdd(%rip), %rdi      # 0x1968c
leaq 0x6c09(%rip), %rsi      # 0x195bf
leaq 0x6c0b(%rip), %rcx      # 0x195c8
movl $0x57, %edx
callq 0x31b0
leaq 0x6cad(%rip), %rdi      # 0x1967b
leaq 0x6bea(%rip), %rsi      # 0x195bf
leaq 0x6bec(%rip), %rcx      # 0x195c8
movl $0x55, %edx
callq 0x31b0
leaq 0x6c7d(%rip), %rdi      # 0x1966a
leaq 0x6bcb(%rip), %rsi      # 0x195bf
leaq 0x6bcd(%rip), %rcx      # 0x195c8
movl $0x53, %edx
callq 0x31b0
leaq 0x6c16(%rip), %rdi      # 0x19622
leaq 0x6bac(%rip), %rsi      # 0x195bf
leaq 0x6bae(%rip), %rcx      # 0x195c8
movl $0x51, %edx
callq 0x31b0
leaq 0x6bdf(%rip), %rdi      # 0x1960a
leaq 0x6b8d(%rip), %rsi      # 0x195bf
leaq 0x6b8f(%rip), %rcx      # 0x195c8
movl $0x4f, %edx
callq 0x31b0
leaq 0x6baf(%rip), %rdi      # 0x195f9
leaq 0x6b6e(%rip), %rsi      # 0x195bf
leaq 0x6b70(%rip), %rcx      # 0x195c8
movl $0x4d, %edx
callq 0x31b0
leaq 0x50c4(%rip), %rdi      # 0x17b2d
leaq 0x6b4f(%rip), %rsi      # 0x195bf
leaq 0x6b51(%rip), %rcx      # 0x195c8
movl $0x4b, %edx
callq 0x31b0
leaq 0x6b2c(%rip), %rdi      # 0x195b4
leaq 0x6b30(%rip), %rsi      # 0x195bf
leaq 0x6b32(%rip), %rcx      # 0x195c8
movl $0x23, %edx
callq 0x31b0