// File: /workspace/github_cpp_makefile_star2_O2/mouda[P]LTE_random_access-simulate/main.cpp
// Function: main
int main(int argc, char** argv) {

	lineParsing(argc, argv); //./simulate -end endnum -rand RandomBackoffIndex -type start_scenario
	cout << "connection scenario is setting..." << endl;
	
	preamble = new int[lte::preambleNum];
	finish_time = new int[lte::EndNum];
	
	//end definitions!!
    End end[lte::EndNum];
	set_traffic(end);
	//
	
    srand(time(NULL));
    for(; _count < lte::EndNum ; _time +=5 ){
	for( int n = 0; n < lte::EndNum; n++ )
	    end[n].setpreamble(); 
	responseForUseSamePreamble();
	for( int n = 0; n < lte::EndNum; n++ ){
	    end[n].responseForOnlyOne();
	    end[n].settime();
	}
 
	if (_time == 1)
		cout << "===Event===" << endl;
	analysisForEvent(_time, _count, _goodEnd);
	
	for (int i = 0; i < lte::preambleNum; i++) {
	    preamble[i] = 0;
	}
    }
	
	cout << "===Node===\n";
	for (int i = 0; i < lte::EndNum; i++)	
		analysisForNode(end[i], i);
		
	int _Taccess = 0;
	int _TEcollision = 0;
    int _Tdelay = 0;
	for (int i = 0; i < lte::EndNum; i++)
	{	
		_Taccess += end[i].getIndex();
		_TEcollision += end[i].getCollision();
		_Tdelay += end[i].getDelayTime();
    }
	cerr << "_Taccess = " << _Taccess << endl;
    cerr << "===Analysis===\n";
    cerr << "Total success number : " << _goodEnd << endl
		 << "Total collision (counted by preambles) : " << collision_time << endl
		 << "Total collision (counted by terminals) : " << _TEcollision << endl
		 << "Collision probability (counted by preambles) : " << ((double) collision_time)/((double)_Taccess) << endl
		 << "Collision probability (counted by terminals) : " << ((double) _TEcollision)/((double) _Taccess) << endl
		 << "Access success probability : " << ((double) _goodEnd)/((double) _Taccess) << endl
		 << "Average delay : " << ((double) _Tdelay)/((double) lte::EndNum) << endl;
	// << "Variance of delay : " <<  << endl;
	

	cleanup();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x3909
movq 0x3d40f(%rip), %rdi     # 0x40fd0
leaq 0x2c648(%rip), %rsi     # 0x30210
callq 0x3260
movq %rax, %rdi
callq 0x3120
movslq 0x3d66c(%rip), %rax     # 0x41248
leaq (,%rax,4), %rdi
testq %rax, %rax
pushq $-0x1
popq %rbx
cmovsq %rbx, %rdi
callq 0x3030
movq %rax, 0x3d6a6(%rip)     # 0x412a0
movslq 0x3d64b(%rip), %r14     # 0x4124c
leaq (,%r14,4), %rdi
testq %r14, %r14
cmovsq %rbx, %rdi
callq 0x3030
movq %rax, 0x3d674(%rip)     # 0x41290
movl %r14d, %eax
movq %rsp, %rbx
imulq $0x18, %rax, %rax
leaq 0xf(%rax), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
testq %r14, %r14
je 0x3c5f
xorl %ecx, %ecx
movss 0x2c58d(%rip), %xmm0    # 0x301d0
movabsq $0x100000000, %rdx      # imm = 0x100000000
movups %xmm0, (%rbx,%rcx)
movq %rdx, 0x10(%rbx,%rcx)
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x3c4d
movq %rbx, %rdi
callq 0x3f2a
xorl %edi, %edi
callq 0x3210
movl %eax, %edi
callq 0x3250
movq 0x3d354(%rip), %r14     # 0x40fd0
leaq 0x2c5af(%rip), %r15     # 0x30232
movl 0x3d5c3(%rip), %eax     # 0x4124c
cmpl %eax, 0x3d619(%rip)     # 0x412a8
jge 0x3d48
movq %rbx, %r12
xorl %r13d, %r13d
cltq
cmpq %rax, %r13
jge 0x3cb9
movq %r12, %rdi
callq 0x361c
incq %r13
movl 0x3d599(%rip), %eax     # 0x4124c
addq $0x18, %r12
jmp 0x3c9b
callq 0x3fd5
movq %rbx, %r12
xorl %r13d, %r13d
movslq 0x3d581(%rip), %rax     # 0x4124c
cmpq %rax, %r13
jge 0x3ce9
movq %r12, %rdi
callq 0x3652
movq %r12, %rdi
callq 0x3694
incq %r13
addq $0x18, %r12
jmp 0x3cc4
movl 0x3d579(%rip), %edi     # 0x41268
cmpl $0x1, %edi
jne 0x3d0d
movq %r14, %rdi
movq %r15, %rsi
callq 0x3260
movq %rax, %rdi
callq 0x3120
movl 0x3d55b(%rip), %edi     # 0x41268
movl 0x3d595(%rip), %esi     # 0x412a8
movl 0x3d593(%rip), %edx     # 0x412ac
callq 0x4023
movq 0x3d57b(%rip), %rax     # 0x412a0
xorl %ecx, %ecx
movslq 0x3d51a(%rip), %rdx     # 0x41248
cmpq %rdx, %rcx
jge 0x3d3c
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x3d27
addl $0x5, 0x3d525(%rip)     # 0x41268
jmp 0x3c83
movq 0x3d281(%rip), %rdi     # 0x40fd0
leaq 0x2c4e8(%rip), %rsi     # 0x3023e
callq 0x3260
xorl %r14d, %r14d
movq %rbx, %r15
movslq 0x3d4e4(%rip), %rax     # 0x4124c
cmpq %rax, %r14
jge 0x3d81
movq %r15, %rdi
movl %r14d, %esi
callq 0x4117
incq %r14
addq $0x18, %r15
jmp 0x3d61
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
cltq
cmpq %rax, %r13
jge 0x3db6
addl 0x14(%rbx), %r15d
addl 0xc(%rbx), %r14d
movq %rbx, %rdi
callq 0x43d6
addl %eax, %r12d
incq %r13
movl 0x3d49c(%rip), %eax     # 0x4124c
addq $0x18, %rbx
jmp 0x3d8d
movq 0x3d233(%rip), %rbx     # 0x40ff0
leaq 0x2c486(%rip), %rsi     # 0x3024a
movq %rbx, %rdi
callq 0x3260
movq %rax, %rdi
movl %r15d, %esi
callq 0x33c0
movq %rax, %rdi
callq 0x3120
leaq 0x2c470(%rip), %rsi     # 0x30256
movq %rbx, %rdi
callq 0x3260
leaq 0x2c471(%rip), %rsi     # 0x30266
movq %rbx, %rdi
callq 0x3260
movl 0x3d4a9(%rip), %esi     # 0x412ac
movq %rax, %rdi
callq 0x33c0
movq %rax, %rdi
callq 0x3120
leaq 0x2c464(%rip), %rsi     # 0x3027e
movq %rax, %rdi
callq 0x3260
movl 0x3d474(%rip), %esi     # 0x4129c
movq %rax, %rdi
callq 0x33c0
movq %rax, %rdi
callq 0x3120
leaq 0x2c469(%rip), %rsi     # 0x302a8
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
movl %r14d, %esi
callq 0x33c0
movq %rax, %rdi
callq 0x3120
leaq 0x2c471(%rip), %rsi     # 0x302d2
movq %rax, %rdi
callq 0x3260
cvtsi2sdl 0x3d42b(%rip), %xmm0 # 0x4129c
cvtsi2sd %r15d, %xmm1
movsd %xmm1, -0x30(%rbp)
divsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x3120
leaq 0x2c46c(%rip), %rsi     # 0x30302
movq %rax, %rdi
callq 0x3260
cvtsi2sd %r14d, %xmm0
divsd -0x30(%rbp), %xmm0
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x3120
leaq 0x2c473(%rip), %rsi     # 0x30332
movq %rax, %rdi
callq 0x3260
cvtsi2sdl 0x3d3dd(%rip), %xmm0 # 0x412ac
divsd -0x30(%rbp), %xmm0
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x3120
leaq 0x2c465(%rip), %rsi     # 0x30350
movq %rax, %rdi
callq 0x3260
cvtsi2sd %r12d, %xmm0
cvtsi2sdl 0x3d34c(%rip), %xmm1 # 0x4124c
divsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x3120
callq 0x3b84
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq