// File: /workspace/github_c_makefile_star2_O2/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 0x4bc4(%rip), %rsi      # 0x149ba
movq %rax, %rdi
callq 0x3320
testq %rax, %rax
je 0x103f8
movq %rax, %r12
leaq 0x30(%rsp), %r13
leaq 0x67b3(%rip), %r15      # 0x165c9
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq %r13, %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %r12, %rdx
callq 0x3490
testq %rax, %rax
je 0x101a1
movq %r13, %rdi
callq 0x3130
cmpq $0x2, %rax
jb 0xfe20
cmpb $0x23, 0x30(%rsp)
je 0xfe20
movq %r13, %rdi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x101bb
movq %rax, %rbx
movq %rax, %rdi
leaq 0x675e(%rip), %rsi      # 0x165cd
callq 0x33d0
testl %eax, %eax
je 0xff07
movq %rbx, %rdi
leaq 0x6775(%rip), %rsi      # 0x165fb
callq 0x33d0
testl %eax, %eax
je 0xff98
movq %rbx, %rdi
leaq 0x67a2(%rip), %rsi      # 0x1663f
callq 0x33d0
testl %eax, %eax
je 0x10057
movq %rbx, %rdi
leaq 0x4e97(%rip), %rsi      # 0x14d4b
callq 0x33d0
testl %eax, %eax
jne 0x1018a
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x10247
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x1022b
movq %rax, %r14
movq %rbx, %rdi
callq 0x3460
movq %rbp, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0x1061e
jmp 0xfe20
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x1020f
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x101f3
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x101d7
movq %r15, %rsi
movq %rax, %r15
xorl %edi, %edi
callq 0x3470
movsd 0x4715(%rip), %xmm0     # 0x14670
testq %rax, %rax
je 0xff68
movq %rax, %rdi
callq 0x3360
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
callq 0x3460
movq %rbp, %rdi
movq %rbx, %rsi
movl %eax, %edx
movq %r15, %rcx
movsd 0x8(%rsp), %xmm0
callq 0x10446
leaq 0x6636(%rip), %r15      # 0x165c9
jmp 0xfe20
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x102ef
movq %rax, %r13
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x102d3
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x102b7
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x1029b
movq %rax, %r15
movq (%rbp), %rdi
movq %r13, %rsi
callq 0xb022
testb %al, %al
jne 0x1027f
movq %rbx, %rdi
callq 0x3460
movl %eax, %ebx
movq %r14, %rdi
callq 0x3460
movl %eax, %ebp
movq %r15, %rdi
callq 0x3460
testl %ebx, %ebx
jle 0x10263
testl %ebp, %ebp
jle 0x10263
testl %eax, %eax
jle 0x10263
movq 0x18(%rsp), %r8
movq (%r8), %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %ebp, %ecx
movq %r8, %rbp
movl %eax, %r8d
callq 0xb4fa
jmp 0x10179
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x103df
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x103c6
movq %rax, %r13
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x103ad
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x10394
movq %rax, %r12
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x1037b
movq %rax, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x3470
testq %rax, %rax
je 0x1035f
movq %r15, %rsi
movq %rax, %r15
movq %r14, 0x28(%rsp)
movq %r13, %r14
xorl %edi, %edi
callq 0x3470
testq %rax, %rax
je 0x10343
movq %rax, %r13
movq 0x18(%rsp), %rbp
movq (%rbp), %rdi
movq 0x8(%rsp), %rsi
callq 0xb022
testb %al, %al
je 0x1030b
movq (%rbp), %rdi
movq %r14, %rsi
callq 0xb022
testb %al, %al
je 0x10327
movq %rbx, %rdi
callq 0x3460
movl %eax, 0x14(%rsp)
movq %r12, %rdi
callq 0x3460
movl %eax, %ebx
movq 0x28(%rsp), %rdi
callq 0x3460
movl %eax, %r12d
movq %r15, %rdi
callq 0x3460
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 0x10562
popq %rax
popq %rcx
movq 0x20(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x6444(%rip), %r15      # 0x165c9
jmp 0xfe20
leaq 0x501b(%rip), %rsi      # 0x151ac
movq %rbx, %rdi
callq 0x33d0
testl %eax, %eax
jne 0x10415
movq %r12, %rdi
callq 0x32b0
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x493a(%rip), %rdi      # 0x14afc
leaq 0x63d6(%rip), %rsi      # 0x1659f
leaq 0x63d8(%rip), %rcx      # 0x165a8
pushq $0x2b
jmp 0x1040f
leaq 0x640c(%rip), %rdi      # 0x165ea
leaq 0x63ba(%rip), %rsi      # 0x1659f
leaq 0x63bc(%rip), %rcx      # 0x165a8
pushq $0x34
jmp 0x1040f
leaq 0x63df(%rip), %rdi      # 0x165d9
leaq 0x639e(%rip), %rsi      # 0x1659f
leaq 0x63a0(%rip), %rcx      # 0x165a8
pushq $0x32
jmp 0x1040f
leaq 0x48f7(%rip), %rdi      # 0x14b0d
leaq 0x6382(%rip), %rsi      # 0x1659f
leaq 0x6384(%rip), %rcx      # 0x165a8
pushq $0x30
jmp 0x1040f
leaq 0x63a7(%rip), %rdi      # 0x165d9
leaq 0x6366(%rip), %rsi      # 0x1659f
leaq 0x6368(%rip), %rcx      # 0x165a8
pushq $0x61
jmp 0x1040f
leaq 0x48bf(%rip), %rdi      # 0x14b0d
leaq 0x634a(%rip), %rsi      # 0x1659f
leaq 0x634c(%rip), %rcx      # 0x165a8
pushq $0x5f
jmp 0x1040f
leaq 0x5207(%rip), %rdi      # 0x15471
leaq 0x632e(%rip), %rsi      # 0x1659f
leaq 0x6330(%rip), %rcx      # 0x165a8
pushq $0x47
jmp 0x1040f
leaq 0x638d(%rip), %rdi      # 0x16613
leaq 0x6312(%rip), %rsi      # 0x1659f
leaq 0x6314(%rip), %rcx      # 0x165a8
pushq $0x43
jmp 0x1040f
leaq 0x6360(%rip), %rdi      # 0x16602
leaq 0x62f6(%rip), %rsi      # 0x1659f
leaq 0x62f8(%rip), %rcx      # 0x165a8
pushq $0x41
jmp 0x1040f
leaq 0x632c(%rip), %rdi      # 0x165ea
leaq 0x62da(%rip), %rsi      # 0x1659f
leaq 0x62dc(%rip), %rcx      # 0x165a8
pushq $0x3f
jmp 0x1040f
leaq 0x62ff(%rip), %rdi      # 0x165d9
leaq 0x62be(%rip), %rsi      # 0x1659f
leaq 0x62c0(%rip), %rcx      # 0x165a8
pushq $0x3d
jmp 0x1040f
leaq 0x4817(%rip), %rdi      # 0x14b0d
leaq 0x62a2(%rip), %rsi      # 0x1659f
leaq 0x62a4(%rip), %rcx      # 0x165a8
pushq $0x3b
jmp 0x1040f
leaq 0x636b(%rip), %rdi      # 0x1667d
leaq 0x6286(%rip), %rsi      # 0x1659f
leaq 0x6288(%rip), %rcx      # 0x165a8
pushq $0x59
jmp 0x1040f
leaq 0x637a(%rip), %rdi      # 0x166a8
leaq 0x626a(%rip), %rsi      # 0x1659f
leaq 0x626c(%rip), %rcx      # 0x165a8
pushq $0x5a
jmp 0x1040f
leaq 0x6322(%rip), %rdi      # 0x1666c
leaq 0x624e(%rip), %rsi      # 0x1659f
leaq 0x6250(%rip), %rcx      # 0x165a8
pushq $0x57
jmp 0x1040f
leaq 0x62f5(%rip), %rdi      # 0x1665b
leaq 0x6232(%rip), %rsi      # 0x1659f
leaq 0x6234(%rip), %rcx      # 0x165a8
pushq $0x55
jmp 0x1040f
leaq 0x62c8(%rip), %rdi      # 0x1664a
leaq 0x6216(%rip), %rsi      # 0x1659f
leaq 0x6218(%rip), %rcx      # 0x165a8
pushq $0x53
jmp 0x1040f
leaq 0x6267(%rip), %rdi      # 0x16602
leaq 0x61fd(%rip), %rsi      # 0x1659f
leaq 0x61ff(%rip), %rcx      # 0x165a8
pushq $0x51
jmp 0x1040f
leaq 0x6236(%rip), %rdi      # 0x165ea
leaq 0x61e4(%rip), %rsi      # 0x1659f
leaq 0x61e6(%rip), %rcx      # 0x165a8
pushq $0x4f
jmp 0x1040f
leaq 0x620c(%rip), %rdi      # 0x165d9
leaq 0x61cb(%rip), %rsi      # 0x1659f
leaq 0x61cd(%rip), %rcx      # 0x165a8
pushq $0x4d
jmp 0x1040f
leaq 0x4727(%rip), %rdi      # 0x14b0d
leaq 0x61b2(%rip), %rsi      # 0x1659f
leaq 0x61b4(%rip), %rcx      # 0x165a8
pushq $0x4b
jmp 0x1040f
leaq 0x6195(%rip), %rdi      # 0x16594
leaq 0x6199(%rip), %rsi      # 0x1659f
leaq 0x619b(%rip), %rcx      # 0x165a8
pushq $0x23
popq %rdx
callq 0x31b0
movq 0xfbac(%rip), %rdi      # 0x1ffc8
movq %rbx, %rsi
callq 0x32a0
movq %rax, %rdi
callq 0x3160
leaq 0x4f7d(%rip), %rdi      # 0x153b0
leaq 0x6165(%rip), %rsi      # 0x1659f
leaq 0x6167(%rip), %rcx      # 0x165a8
pushq $0x68
jmp 0x1040f
nop