// File: /workspace/github_c_makefile_star2_O1/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 0x51e8(%rip), %rsi      # 0x1793a
movq %rax, %rdi
callq 0x3360
testq %rax, %rax
je 0x12ded
movq %rax, %r12
leaq 0x30(%rsp), %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %rax, %rdx
callq 0x34c0
testq %rax, %rax
je 0x12aff
leaq 0x30(%rsp), %r13
leaq 0x6dbc(%rip), %r15      # 0x19549
movq %rbp, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r13, %rdi
callq 0x3150
cmpq $0x2, %rax
jb 0x12ae6
cmpb $0x23, 0x30(%rsp)
je 0x12ae6
movq %r13, %rdi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12b62
movq %rax, %rbx
movq %rax, %rdi
leaq 0x6d78(%rip), %rsi      # 0x1954d
callq 0x33f0
testl %eax, %eax
je 0x1286d
movq %rbx, %rdi
leaq 0x6d8f(%rip), %rsi      # 0x1957b
callq 0x33f0
testl %eax, %eax
je 0x128f7
movq %rbx, %rdi
leaq 0x6dbc(%rip), %rsi      # 0x195bf
callq 0x33f0
testl %eax, %eax
je 0x129b6
movq %rbx, %rdi
leaq 0x54b1(%rip), %rsi      # 0x17ccb
callq 0x33f0
testl %eax, %eax
jne 0x12b19
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12bfd
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12bde
movq %rax, %r14
movq %rbx, %rdi
callq 0x3490
movq %rbp, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0x1303a
jmp 0x12ae6
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12bbf
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12ba0
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12b81
movq %r15, %rsi
movq %rax, %r15
xorl %edi, %edi
callq 0x34a0
movsd 0x4d2f(%rip), %xmm0     # 0x175f0
testq %rax, %rax
je 0x128ce
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 0x12e0c
jmp 0x12adf
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12cb7
movq %rax, %r13
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12c98
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12c79
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12c5a
movq %rax, %r15
movq (%rbp), %rdi
movq %r13, %rsi
callq 0xcf94
testb %al, %al
jne 0x12c3b
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 0x12c1c
testl %ebp, %ebp
jle 0x12c1c
testl %eax, %eax
jle 0x12c1c
movq 0x18(%rsp), %r8
movq (%r8), %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %ebp, %ecx
movq %r8, %rbp
movl %eax, %r8d
callq 0xd5ac
jmp 0x12ada
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x12dce
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12daf
movq %rax, %r13
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12d90
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12d71
movq %rax, %r12
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12d52
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x34a0
testq %rax, %rax
je 0x12d33
movq %r15, %rsi
movq %rax, %r15
movq %r14, 0x28(%rsp)
movq %r13, %r14
xorl %edi, %edi
callq 0x34a0
testq %rax, %rax
je 0x12d14
movq %rax, %r13
movq 0x18(%rsp), %rbp
movq (%rbp), %rdi
movq 0x8(%rsp), %rsi
callq 0xcf94
testb %al, %al
je 0x12cd6
movq (%rbp), %rdi
movq %r14, %rsi
callq 0xcf94
testb %al, %al
je 0x12cf5
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 0x12f7e
addq $0x10, %rsp
movq 0x20(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x6a63(%rip), %r15      # 0x19549
movq %r13, %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %r12, %rdx
callq 0x34c0
testq %rax, %rax
jne 0x12797
movq %r12, %rdi
callq 0x32d0
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x560c(%rip), %rsi      # 0x1812c
movq %rbx, %rdi
callq 0x33f0
testl %eax, %eax
je 0x12aff
movq 0xe49d(%rip), %rdi      # 0x20fd0
movq %rbx, %rsi
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x57e6(%rip), %rdi      # 0x18330
leaq 0x69ce(%rip), %rsi      # 0x1951f
leaq 0x69d0(%rip), %rcx      # 0x19528
movl $0x68, %edx
callq 0x31b0
leaq 0x4f13(%rip), %rdi      # 0x17a7c
leaq 0x69af(%rip), %rsi      # 0x1951f
leaq 0x69b1(%rip), %rcx      # 0x19528
movl $0x2b, %edx
callq 0x31b0
leaq 0x69e2(%rip), %rdi      # 0x1956a
leaq 0x6990(%rip), %rsi      # 0x1951f
leaq 0x6992(%rip), %rcx      # 0x19528
movl $0x34, %edx
callq 0x31b0
leaq 0x69b2(%rip), %rdi      # 0x19559
leaq 0x6971(%rip), %rsi      # 0x1951f
leaq 0x6973(%rip), %rcx      # 0x19528
movl $0x32, %edx
callq 0x31b0
leaq 0x4ec7(%rip), %rdi      # 0x17a8d
leaq 0x6952(%rip), %rsi      # 0x1951f
leaq 0x6954(%rip), %rcx      # 0x19528
movl $0x30, %edx
callq 0x31b0
leaq 0x6974(%rip), %rdi      # 0x19559
leaq 0x6933(%rip), %rsi      # 0x1951f
leaq 0x6935(%rip), %rcx      # 0x19528
movl $0x61, %edx
callq 0x31b0
leaq 0x4e89(%rip), %rdi      # 0x17a8d
leaq 0x6914(%rip), %rsi      # 0x1951f
leaq 0x6916(%rip), %rcx      # 0x19528
movl $0x5f, %edx
callq 0x31b0
leaq 0x57ce(%rip), %rdi      # 0x183f1
leaq 0x68f5(%rip), %rsi      # 0x1951f
leaq 0x68f7(%rip), %rcx      # 0x19528
movl $0x47, %edx
callq 0x31b0
leaq 0x6951(%rip), %rdi      # 0x19593
leaq 0x68d6(%rip), %rsi      # 0x1951f
leaq 0x68d8(%rip), %rcx      # 0x19528
movl $0x43, %edx
callq 0x31b0
leaq 0x6921(%rip), %rdi      # 0x19582
leaq 0x68b7(%rip), %rsi      # 0x1951f
leaq 0x68b9(%rip), %rcx      # 0x19528
movl $0x41, %edx
callq 0x31b0
leaq 0x68ea(%rip), %rdi      # 0x1956a
leaq 0x6898(%rip), %rsi      # 0x1951f
leaq 0x689a(%rip), %rcx      # 0x19528
movl $0x3f, %edx
callq 0x31b0
leaq 0x68ba(%rip), %rdi      # 0x19559
leaq 0x6879(%rip), %rsi      # 0x1951f
leaq 0x687b(%rip), %rcx      # 0x19528
movl $0x3d, %edx
callq 0x31b0
leaq 0x4dcf(%rip), %rdi      # 0x17a8d
leaq 0x685a(%rip), %rsi      # 0x1951f
leaq 0x685c(%rip), %rcx      # 0x19528
movl $0x3b, %edx
callq 0x31b0
leaq 0x6920(%rip), %rdi      # 0x195fd
leaq 0x683b(%rip), %rsi      # 0x1951f
leaq 0x683d(%rip), %rcx      # 0x19528
movl $0x59, %edx
callq 0x31b0
leaq 0x692c(%rip), %rdi      # 0x19628
leaq 0x681c(%rip), %rsi      # 0x1951f
leaq 0x681e(%rip), %rcx      # 0x19528
movl $0x5a, %edx
callq 0x31b0
leaq 0x68d1(%rip), %rdi      # 0x195ec
leaq 0x67fd(%rip), %rsi      # 0x1951f
leaq 0x67ff(%rip), %rcx      # 0x19528
movl $0x57, %edx
callq 0x31b0
leaq 0x68a1(%rip), %rdi      # 0x195db
leaq 0x67de(%rip), %rsi      # 0x1951f
leaq 0x67e0(%rip), %rcx      # 0x19528
movl $0x55, %edx
callq 0x31b0
leaq 0x6871(%rip), %rdi      # 0x195ca
leaq 0x67bf(%rip), %rsi      # 0x1951f
leaq 0x67c1(%rip), %rcx      # 0x19528
movl $0x53, %edx
callq 0x31b0
leaq 0x680a(%rip), %rdi      # 0x19582
leaq 0x67a0(%rip), %rsi      # 0x1951f
leaq 0x67a2(%rip), %rcx      # 0x19528
movl $0x51, %edx
callq 0x31b0
leaq 0x67d3(%rip), %rdi      # 0x1956a
leaq 0x6781(%rip), %rsi      # 0x1951f
leaq 0x6783(%rip), %rcx      # 0x19528
movl $0x4f, %edx
callq 0x31b0
leaq 0x67a3(%rip), %rdi      # 0x19559
leaq 0x6762(%rip), %rsi      # 0x1951f
leaq 0x6764(%rip), %rcx      # 0x19528
movl $0x4d, %edx
callq 0x31b0
leaq 0x4cb8(%rip), %rdi      # 0x17a8d
leaq 0x6743(%rip), %rsi      # 0x1951f
leaq 0x6745(%rip), %rcx      # 0x19528
movl $0x4b, %edx
callq 0x31b0
leaq 0x6720(%rip), %rdi      # 0x19514
leaq 0x6724(%rip), %rsi      # 0x1951f
leaq 0x6726(%rip), %rcx      # 0x19528
movl $0x23, %edx
callq 0x31b0