// File: /workspace/github_cpp_makefile_star2_O1/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 0x4024d(%rip), %r14     # 0x43fd0
leaq 0x30466(%rip), %rsi     # 0x341f0
movl $0x21, %edx
movq %r14, %rdi
callq 0x32d0
movq (%r14), %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
movslq 0x40493(%rip), %rax     # 0x44258
leaq (,%rax,4), %rdi
testq %rax, %rax
movq $-0x1, %rbx
cmovsq %rbx, %rdi
callq 0x3030
movq %rax, 0x404c9(%rip)     # 0x442b0
movslq 0x4046e(%rip), %r15     # 0x4425c
leaq (,%r15,4), %rdi
testq %r15, %r15
cmovsq %rbx, %rdi
callq 0x3030
movq %rax, 0x40497(%rip)     # 0x442a0
movl %r15d, %eax
movq %rsp, %rbx
leaq (%rax,%rax,2), %rax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
testq %r15, %r15
je 0x3e57
leaq (%rbx,%rax,8), %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rbx, %rdx
movq $0x1, (%rdx)
movq $0x0, 0x8(%rdx)
movq %rcx, 0x10(%rdx)
addq $0x18, %rdx
cmpq %rax, %rdx
jne 0x3e3b
movq %rbx, %rdi
callq 0x4305
xorl %edi, %edi
callq 0x3230
movl %eax, %edi
callq 0x3270
movl 0x40445(%rip), %eax     # 0x442b8
cmpl 0x403e3(%rip), %eax     # 0x4425c
jge 0x3f7f
leaq 0x3038c(%rip), %r15     # 0x34212
cmpl $0x0, 0x403cf(%rip)     # 0x4425c
jle 0x3eb0
movq %rbx, %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x366c
incq %r13
movslq 0x403b5(%rip), %rax     # 0x4425c
addq $0x18, %r12
cmpq %rax, %r13
jl 0x3e95
callq 0x4425
cmpl $0x0, 0x403a0(%rip)     # 0x4425c
jle 0x3ee7
movq %rbx, %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x36a2
movq %r12, %rdi
callq 0x36e4
incq %r13
movslq 0x4037e(%rip), %rax     # 0x4425c
addq $0x18, %r12
cmpq %rax, %r13
jl 0x3ec4
cmpl $0x1, 0x4038a(%rip)     # 0x44278
jne 0x3f27
movl $0xb, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x32d0
movq (%r14), %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
movl 0x4034b(%rip), %edi     # 0x44278
movl 0x40385(%rip), %esi     # 0x442b8
movl 0x40383(%rip), %edx     # 0x442bc
callq 0x4471
cmpl $0x0, 0x40313(%rip)     # 0x44258
jle 0x3f66
movq 0x40362(%rip), %rax     # 0x442b0
xorl %ecx, %ecx
movl $0x0, (%rax,%rcx,4)
incq %rcx
movslq 0x402f7(%rip), %rdx     # 0x44258
cmpq %rdx, %rcx
jl 0x3f50
addl $0x5, 0x4030b(%rip)     # 0x44278
movl 0x40345(%rip), %eax     # 0x442b8
cmpl 0x402e3(%rip), %eax     # 0x4425c
jl 0x3e86
movq 0x4004a(%rip), %rdi     # 0x43fd0
leaq 0x30291(%rip), %rsi     # 0x3421e
movl $0xb, %edx
callq 0x32d0
movl 0x402bf(%rip), %eax     # 0x4425c
testl %eax, %eax
jle 0x3fc5
xorl %r14d, %r14d
movq %rbx, %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x45ce
incq %r14
movslq 0x402a0(%rip), %rax     # 0x4425c
addq $0x18, %r15
cmpq %rax, %r14
jl 0x3fa7
testl %eax, %eax
jle 0x400b
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r14d, %r14d
xorl %r15d, %r15d
movl 0x8(%rbx,%rcx), %esi
subl 0x10(%rbx,%rcx), %esi
js 0x42e6
addl 0xc(%rbx,%rcx), %r14d
addl 0x14(%rbx,%rcx), %r15d
addl %esi, %edx
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x3fdd
cvtsi2sd %edx, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x401a
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x3ffcf(%rip), %rbx     # 0x43ff0
leaq 0x30202(%rip), %rsi     # 0x3422a
movl $0xb, %edx
movq %rbx, %rdi
callq 0x32d0
movq %rbx, %rdi
movl %r15d, %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 0x301c5(%rip), %rsi     # 0x34236
movl $0xf, %edx
movq %rbx, %rdi
callq 0x32d0
leaq 0x301c1(%rip), %rsi     # 0x34246
movl $0x17, %edx
movq %rbx, %rdi
callq 0x32d0
movl 0x40224(%rip), %esi     # 0x442bc
movq %rbx, %rdi
callq 0x3400
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 0x3018a(%rip), %rsi     # 0x3425e
movl $0x29, %edx
movq %rax, %rdi
callq 0x32d0
movl 0x401c5(%rip), %esi     # 0x442ac
movq %rbx, %rdi
callq 0x3400
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 0x30165(%rip), %rsi     # 0x34288
movl $0x29, %edx
movq %rax, %rdi
callq 0x32d0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3400
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 0x30143(%rip), %rsi     # 0x342b2
movl $0x2f, %edx
movq %rax, %rdi
callq 0x32d0
cvtsi2sdl 0x40128(%rip), %xmm0 # 0x442ac
cvtsi2sd %r15d, %xmm1
movsd %xmm1, -0x38(%rbp)
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 %rax, %rbx
leaq 0x30114(%rip), %rsi     # 0x342e2
movl $0x2f, %edx
movq %rax, %rdi
callq 0x32d0
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %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 0x300ee(%rip), %rsi     # 0x34312
movl $0x1d, %edx
movq %rax, %rdi
callq 0x32d0
xorps %xmm0, %xmm0
cvtsi2sdl 0x40080(%rip), %xmm0 # 0x442bc
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 0x300b3(%rip), %rsi     # 0x34330
movl $0x10, %edx
movq %rax, %rdi
callq 0x32d0
xorps %xmm1, %xmm1
cvtsi2sdl 0x3ffc7(%rip), %xmm1 # 0x4425c
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
callq 0x3d34
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x300a4(%rip), %rdi     # 0x34391
leaq 0x300b5(%rip), %rsi     # 0x343a9
leaq 0x300b6(%rip), %rcx     # 0x343b1
movl $0xd, %edx
callq 0x3190