// File: /workspace/github_c_makefile_star2_O0/stonezwr[P]SpiKL-IP/main.C
// Function: main
int main(int argc, char * argv[]){
    struct timeval val1,val2;
    struct timezone zone;
    struct NTParg* NTPargptr;
    int rc;
    int i;
    void * status;
    long t;

    gettimeofday(&val1,&zone);
    //  srand(time(NULL));
    for(i = 0; i < 4142; ++i) file[i] = -1;

    Network array_network[NUM_THREADS];

    for(i = 0; i < NUM_THREADS; i++){
        array_network[i].SetTid(i);
        Parser parser(&array_network[i]);
#ifdef SPIKL_IP
        parser.Parse("netlist_SpiKL_IP.txt"); // For English spoken letters
#else
        parser.Parse("netlist.txt"); // For English spoken letters
#endif
        array_network[i].CrossValidation(NFOLD);
    }

    pthread_t threads[NUM_THREADS];
    pthread_attr_t attr;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);

    for(t = 0; t < NUM_THREADS; t++){
        NTPargptr = new(struct NTParg);
        NTPargptr->tid = t;
        NTPargptr->network = &array_network[t];

        printf("In main: creating thread %ld \n",t);
        rc = pthread_create(&threads[t],&attr,ParallelSim,(void *) NTPargptr);
        if(rc){
            printf("ERROR; return code form pthread_create() is %d \n",rc);
            exit(-1);
        }
    }

    pthread_attr_destroy(&attr);
    for(t = 0; t < NUM_THREADS; t++){
        rc = pthread_join(threads[t],&status);
        if(rc){
            printf("ERROR; return code form pthread_join() is %d \n",rc);
            exit(-1);
        }
        printf("Main: completed joining with thread %ld ! \n",t);
    }
    printf("Main: program completed. Exiting. \n");

    gettimeofday(&val2,&zone);
    cout<<"Wall clock time: "<<((val2.tv_sec-val1.tv_sec)+double(val2.tv_usec-val1.tv_usec)*1e-6)<<" seconds"<<endl;

    cout<<"Readout the results ..."<<endl; 
    cout<<"Number of samples: "<<array_network[0].NumSpeech()<<endl;
    // collect the result directly from network:
    CollectResultsFromNetwork(array_network);
    // collect the test error at each iteration
    CollectTestErrorFromNetwork(array_network);

    pthread_exit(NULL);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf50, %rsp            # imm = 0xF50
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4650
movl $0x0, -0x48(%rbp)
cmpl $0x102e, -0x48(%rbp)    # imm = 0x102E
jge 0x32db3
movslq -0x48(%rbp), %rcx
leaq 0x1a6af(%rip), %rax     # 0x4d450
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x32d8d
leaq -0xe40(%rbp), %rax
movq %rax, -0xed0(%rbp)
movq %rax, %rcx
addq $0xde8, %rcx            # imm = 0xDE8
movq %rcx, -0xec8(%rbp)
movq %rax, -0xec0(%rbp)
movq -0xec0(%rbp), %rdi
movq %rdi, -0xed8(%rbp)
callq 0x1c840
jmp 0x32dee
movq -0xec8(%rbp), %rcx
movq -0xed8(%rbp), %rax
addq $0x2c8, %rax            # imm = 0x2C8
cmpq %rcx, %rax
movq %rax, -0xec0(%rbp)
jne 0x32dd9
movl $0x0, -0x48(%rbp)
cmpl $0x5, -0x48(%rbp)
jge 0x32f35
movslq -0x48(%rbp), %rax
movl %eax, %esi
imulq $0x2c8, %rax, %rax      # imm = 0x2C8
leaq -0xe40(%rbp,%rax), %rdi
callq 0x33300
jmp 0x32e3b
movslq -0x48(%rbp), %rax
imulq $0x2c8, %rax, %rax      # imm = 0x2C8
leaq -0xe40(%rbp,%rax), %rsi
leaq -0xe58(%rbp), %rdi
callq 0x2adc0
jmp 0x32e5c
leaq 0x401d(%rip), %rsi      # 0x36e80
leaq -0xe58(%rbp), %rdi
callq 0x2ade0
jmp 0x32e71
movslq -0x48(%rbp), %rax
imulq $0x2c8, %rax, %rax      # imm = 0x2C8
leaq -0xe40(%rbp,%rax), %rdi
movl $0x5, %esi
callq 0x217a0
jmp 0x32e90
jmp 0x32e92
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x32e15
movq -0xed0(%rbp), %rcx
movq %rax, %rsi
movq -0xed8(%rbp), %rax
movq %rsi, -0xe48(%rbp)
movl %edx, -0xe4c(%rbp)
cmpq %rax, %rcx
movq %rax, -0xee0(%rbp)
je 0x32efe
movq -0xee0(%rbp), %rdi
addq $-0x2c8, %rdi           # imm = 0xFD38
movq %rdi, -0xee8(%rbp)
callq 0x1cdc0
movq -0xed0(%rbp), %rcx
movq -0xee8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xee0(%rbp)
jne 0x32eca
jmp 0x33241
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe48(%rbp)
movl %eax, -0xe4c(%rbp)
leaq -0xe40(%rbp), %rax
movq %rax, -0xef8(%rbp)
addq $0xde8, %rax            # imm = 0xDE8
movq %rax, -0xef0(%rbp)
jmp 0x3320b
leaq -0xeb8(%rbp), %rdi
callq 0x4450
leaq -0xeb8(%rbp), %rdi
xorl %esi, %esi
callq 0x44f0
movq $0x0, -0x58(%rbp)
cmpq $0x5, -0x58(%rbp)
jge 0x3301c
movl $0x10, %edi
callq 0x4380
movq %rax, -0xf00(%rbp)
jmp 0x32f75
movq -0xf00(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
imulq $0x2c8, %rax, %rax      # imm = 0x2C8
leaq -0xe40(%rbp,%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rsi
leaq 0x3ee4(%rip), %rdi      # 0x36e95
xorl %eax, %eax
callq 0x4060
jmp 0x32fba
movq -0x58(%rbp), %rax
leaq -0xe80(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
movq -0x40(%rbp), %rcx
leaq -0xeb8(%rbp), %rsi
leaq -0x128e(%rip), %rdx     # 0x31d50
callq 0x4730
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x33009
movl -0x44(%rbp), %esi
leaq 0x3ebe(%rip), %rdi      # 0x36eb4
xorl %eax, %eax
callq 0x4060
jmp 0x32fff
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4440
jmp 0x3300b
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x32f57
leaq -0xeb8(%rbp), %rdi
callq 0x4680
movq $0x0, -0x58(%rbp)
cmpq $0x5, -0x58(%rbp)
jge 0x330a4
movq -0x58(%rbp), %rax
movq -0xe80(%rbp,%rax,8), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4310
movl %eax, -0xf04(%rbp)
jmp 0x33054
movl -0xf04(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x33080
movl -0x44(%rbp), %esi
leaq 0x3e78(%rip), %rdi      # 0x36ee5
xorl %eax, %eax
callq 0x4060
jmp 0x33076
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4440
movq -0x58(%rbp), %rsi
leaq 0x3e89(%rip), %rdi      # 0x36f14
xorl %eax, %eax
callq 0x4060
jmp 0x33094
jmp 0x33096
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x33030
leaq 0x3e95(%rip), %rdi      # 0x36f40
xorl %eax, %eax
callq 0x4060
jmp 0x330b4
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4650
movq 0x19f00(%rip), %rdi     # 0x4cfc8
leaq 0x3e95(%rip), %rsi      # 0x36f64
callq 0x4360
movq %rax, -0xf10(%rbp)
jmp 0x330dd
movq -0xf10(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rcx
subq %rsi, %rdx
cvtsi2sd %rdx, %xmm1
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x38f4(%rip), %xmm2     # 0x36a00
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x4770
movq %rax, -0xf18(%rbp)
jmp 0x33122
movq -0xf18(%rbp), %rdi
leaq 0x38f5(%rip), %rsi      # 0x36a25
callq 0x4360
movq %rax, -0xf20(%rbp)
jmp 0x3313e
movq -0xf20(%rbp), %rdi
movq 0x19e6c(%rip), %rsi     # 0x4cfb8
callq 0x43b0
jmp 0x33153
movq 0x19e6e(%rip), %rdi     # 0x4cfc8
leaq 0x3e15(%rip), %rsi      # 0x36f76
callq 0x4360
movq %rax, -0xf28(%rbp)
jmp 0x3316f
movq -0xf28(%rbp), %rdi
movq 0x19e3b(%rip), %rsi     # 0x4cfb8
callq 0x43b0
jmp 0x33184
movq 0x19e3d(%rip), %rdi     # 0x4cfc8
leaq 0x3dfc(%rip), %rsi      # 0x36f8e
callq 0x4360
movq %rax, -0xf30(%rbp)
jmp 0x331a0
leaq -0xe40(%rbp), %rdi
callq 0x2c930
movl %eax, -0xf34(%rbp)
jmp 0x331b4
movl -0xf34(%rbp), %esi
movq -0xf30(%rbp), %rdi
callq 0x46c0
movq %rax, -0xf40(%rbp)
jmp 0x331cf
movq -0xf40(%rbp), %rdi
movq 0x19ddb(%rip), %rsi     # 0x4cfb8
callq 0x43b0
jmp 0x331e4
leaq -0xe40(%rbp), %rdi
callq 0x321d0
jmp 0x331f2
leaq -0xe40(%rbp), %rdi
callq 0x32c70
jmp 0x33200
xorl %eax, %eax
movl %eax, %edi
callq 0x46e0
jmp 0x3320b
movq -0xef0(%rbp), %rdi
addq $-0x2c8, %rdi           # imm = 0xFD38
movq %rdi, -0xf48(%rbp)
callq 0x1cdc0
movq -0xef8(%rbp), %rcx
movq -0xf48(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xef0(%rbp)
jne 0x3320b
jmp 0x33241
movq -0xe48(%rbp), %rdi
callq 0x46d0
nopl (%rax)