// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
callq 0x3a75
movq 0x3f25b(%rip), %r15     # 0x42fd0
leaq 0x2f494(%rip), %rsi     # 0x33210
movl $0x21, %edx
movq %r15, %rdi
callq 0x32d0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movslq 0x3f4a1(%rip), %rax     # 0x43258
leaq (,%rax,4), %rdi
testq %rax, %rax
movq $-0x1, %rbx
cmovsq %rbx, %rdi
callq 0x3030
movq %rax, 0x3f4d7(%rip)     # 0x432b0
movslq 0x3f47c(%rip), %r12     # 0x4325c
leaq (,%r12,4), %rdi
testq %r12, %r12
cmovsq %rbx, %rdi
callq 0x3030
movq %rax, 0x3f4a5(%rip)     # 0x432a0
movl %r12d, %eax
movq %rsp, %r14
leaq (%rax,%rax,2), %rcx
leaq 0xf(,%rcx,8), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
testq %r12, %r12
je 0x3e4c
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
movss 0x2f3a2(%rip), %xmm0    # 0x331d0
movabsq $0x100000000, %rdx      # imm = 0x100000000
movupd %xmm0, (%r14,%rcx)
movq %rdx, 0x10(%r14,%rcx)
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x3e38
movq %r14, %rdi
callq 0x42fd
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x3230
movl %eax, %edi
callq 0x3270
movl 0x3f3f2(%rip), %eax     # 0x4325c
cmpl %eax, 0x3f448(%rip)     # 0x432b8
jge 0x3f63
testl %eax, %eax
jle 0x3e9b
movq %r14, %r13
xorl %r12d, %r12d
movq %r13, %rdi
callq 0x366c
incq %r12
movslq 0x3f3ca(%rip), %rax     # 0x4325c
addq $0x18, %r13
cmpq %rax, %r12
jl 0x3e80
callq 0x441d
cmpl $0x0, 0x3f3b5(%rip)     # 0x4325c
jle 0x3ed2
movq %r14, %r13
xorl %r12d, %r12d
movq %r13, %rdi
callq 0x36a2
movq %r13, %rdi
callq 0x36e4
incq %r12
movslq 0x3f393(%rip), %rax     # 0x4325c
addq $0x18, %r13
cmpq %rax, %r12
jl 0x3eaf
movl 0x3f3a0(%rip), %edi     # 0x43278
cmpl $0x1, %edi
jne 0x3f1e
movl $0xb, %edx
movq %r15, %rdi
leaq 0x2f346(%rip), %rsi     # 0x33232
callq 0x32d0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movl 0x3f35a(%rip), %edi     # 0x43278
movl 0x3f394(%rip), %esi     # 0x432b8
movl 0x3f392(%rip), %edx     # 0x432bc
callq 0x4469
cmpl $0x0, 0x3f322(%rip)     # 0x43258
jle 0x3f57
movq 0x3f371(%rip), %rax     # 0x432b0
xorl %ecx, %ecx
movl $0x0, (%rax,%rcx,4)
incq %rcx
movslq 0x3f306(%rip), %rdx     # 0x43258
cmpq %rdx, %rcx
jl 0x3f41
addl $0x5, 0x3f31a(%rip)     # 0x43278
jmp 0x3e64
movq 0x3f066(%rip), %rdi     # 0x42fd0
leaq 0x2f2cd(%rip), %rsi     # 0x3323e
movl $0xb, %edx
callq 0x32d0
cmpl $0x0, 0x3f2da(%rip)     # 0x4325c
jle 0x3feb
xorl %ebx, %ebx
movq %r14, %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0x45c6
incq %rbx
movslq 0x3f2bf(%rip), %rax     # 0x4325c
addq $0x18, %r15
cmpq %rax, %rbx
jl 0x3f89
testl %eax, %eax
jle 0x3fe9
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r15d, %r15d
xorl %ebx, %ebx
movl 0x8(%r14,%rcx), %esi
subl 0x10(%r14,%rcx), %esi
js 0x42de
addl 0xc(%r14,%rcx), %r15d
addl 0x14(%r14,%rcx), %ebx
addl %esi, %edx
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x3fbb
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x3ff2
xorl %ebx, %ebx
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x3eff2(%rip), %r14     # 0x42ff0
leaq 0x2f245(%rip), %rsi     # 0x3324a
movl $0xb, %edx
movq %r14, %rdi
callq 0x32d0
movq %r14, %rdi
movl %ebx, %esi
callq 0x3400
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x2f209(%rip), %rsi     # 0x33256
movl $0xf, %edx
movq %r14, %rdi
callq 0x32d0
leaq 0x2f205(%rip), %rsi     # 0x33266
movl $0x17, %edx
movq %r14, %rdi
callq 0x32d0
movl 0x3f248(%rip), %esi     # 0x432bc
movq %r14, %rdi
callq 0x3400
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rax, %r14
leaq 0x2f1ce(%rip), %rsi     # 0x3327e
movl $0x29, %edx
movq %rax, %rdi
callq 0x32d0
movl 0x3f1e9(%rip), %esi     # 0x432ac
movq %r14, %rdi
callq 0x3400
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rax, %r14
leaq 0x2f1a9(%rip), %rsi     # 0x332a8
movl $0x29, %edx
movq %rax, %rdi
callq 0x32d0
movq %r14, %rdi
movl %r15d, %esi
callq 0x3400
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rax, %r14
leaq 0x2f187(%rip), %rsi     # 0x332d2
movl $0x2f, %edx
movq %rax, %rdi
callq 0x32d0
cvtsi2sdl 0x3f14c(%rip), %xmm0 # 0x432ac
cvtsi2sd %ebx, %xmm1
movsd %xmm1, -0x38(%rbp)
divsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x33a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
leaq 0x2f159(%rip), %rsi     # 0x33302
movl $0x2f, %edx
movq %rax, %rdi
callq 0x32d0
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
divsd -0x38(%rbp), %xmm0
movq %rbx, %rdi
callq 0x33a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
leaq 0x2f133(%rip), %rsi     # 0x33332
movl $0x1d, %edx
movq %rax, %rdi
callq 0x32d0
xorps %xmm0, %xmm0
cvtsi2sdl 0x3f0a5(%rip), %xmm0 # 0x432bc
divsd -0x38(%rbp), %xmm0
movq %rbx, %rdi
callq 0x33a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
leaq 0x2f0f8(%rip), %rsi     # 0x33350
movl $0x10, %edx
movq %rax, %rdi
callq 0x32d0
xorps %xmm1, %xmm1
cvtsi2sdl 0x3efec(%rip), %xmm1 # 0x4325c
movsd -0x30(%rbp), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x33a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x3effe(%rip), %rdi     # 0x432b0
movl $0x4, %esi
callq 0x32b0
movq 0x3efdd(%rip), %rdi     # 0x432a0
movl $0x4, %esi
callq 0x32b0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2f0cc(%rip), %rdi     # 0x333b1
leaq 0x2f0dd(%rip), %rsi     # 0x333c9
leaq 0x2f0de(%rip), %rcx     # 0x333d1
movl $0xd, %edx
callq 0x3190