// File: 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
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x3c40
movq 0x60f24(%rip), %rdi     # 0x64fd0
leaq 0x5112d(%rip), %rsi     # 0x551e0
callq 0x32e0
movq %rax, %rdi
movq 0x60efe(%rip), %rsi     # 0x64fc0
callq 0x3310
movslq 0x611f2(%rip), %rax     # 0x652c0
movl $0x4, %ecx
movq %rcx, -0x60(%rbp)
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
movq %rax, -0x58(%rbp)
cmovoq %rax, %rdi
callq 0x3030
movq -0x60(%rbp), %rcx
movq %rax, 0x61704(%rip)     # 0x65800
movslq 0x611c1(%rip), %rax     # 0x652c4
mulq %rcx
movq %rax, %rdi
movq -0x58(%rbp), %rax
cmovoq %rax, %rdi
callq 0x3030
movq %rax, 0x616d3(%rip)     # 0x657f0
movl 0x611a1(%rip), %eax     # 0x652c4
movq %rax, -0x50(%rbp)
movq %rsp, %rcx
movq %rcx, -0x18(%rbp)
leaq (%rax,%rax,2), %rcx
leaq 0xf(,%rcx,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x4191
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x4c90
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x68(%rbp)
jne 0x416f
movq -0x48(%rbp), %rdi
callq 0x4540
xorl %eax, %eax
movl %eax, %edi
callq 0x3280
movl %eax, %edi
callq 0x32d0
movl 0x61658(%rip), %eax     # 0x65808
cmpl 0x6110e(%rip), %eax     # 0x652c4
jge 0x42be
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x610f8(%rip), %eax     # 0x652c4
jge 0x41ed
movq -0x48(%rbp), %rdi
movslq -0x24(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x37c0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x41c3
callq 0x4640
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl 0x610c2(%rip), %eax     # 0x652c4
jge 0x4237
movq -0x48(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x3820
movq -0x48(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x3890
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x41f9
cmpl $0x1, 0x610a2(%rip)     # 0x652e0
jne 0x4262
movq 0x60d89(%rip), %rdi     # 0x64fd0
leaq 0x50fb4(%rip), %rsi     # 0x55202
callq 0x32e0
movq %rax, %rdi
movq 0x60d63(%rip), %rsi     # 0x64fc0
callq 0x3310
movl 0x61078(%rip), %edi     # 0x652e0
movl 0x6159a(%rip), %esi     # 0x65808
movl 0x61598(%rip), %edx     # 0x6580c
callq 0x46b0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x61037(%rip), %eax     # 0x652c0
jge 0x42a8
movq 0x6156e(%rip), %rax     # 0x65800
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4280
jmp 0x42aa
movl 0x61030(%rip), %eax     # 0x652e0
addl $0x5, %eax
movl %eax, 0x61027(%rip)     # 0x652e0
jmp 0x41aa
movq 0x60d0b(%rip), %rdi     # 0x64fd0
leaq 0x50f42(%rip), %rsi     # 0x5520e
callq 0x32e0
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl 0x60fe3(%rip), %eax     # 0x652c4
jge 0x4305
movq -0x48(%rbp), %rdi
movslq -0x30(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x47d0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x42d8
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl 0x60f9a(%rip), %eax     # 0x652c4
jge 0x4385
movq -0x48(%rbp), %rdi
movslq -0x40(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4cd0
movq -0x48(%rbp), %rdi
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movslq -0x40(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4cf0
movq -0x48(%rbp), %rdi
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movslq -0x40(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4d10
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4321
movq 0x60c64(%rip), %rdi     # 0x64ff0
leaq 0x50e87(%rip), %rsi     # 0x5521a
callq 0x32e0
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x34a0
movq %rax, %rdi
movq 0x60c13(%rip), %rsi     # 0x64fc0
callq 0x3310
movq 0x60c37(%rip), %rdi     # 0x64ff0
leaq 0x50e66(%rip), %rsi     # 0x55226
callq 0x32e0
movq 0x60c24(%rip), %rdi     # 0x64ff0
leaq 0x50e63(%rip), %rsi     # 0x55236
callq 0x32e0
movq %rax, %rdi
movl 0x6142b(%rip), %esi     # 0x6580c
callq 0x34a0
movq %rax, %rdi
movq 0x60bd0(%rip), %rsi     # 0x64fc0
callq 0x3310
movq %rax, %rdi
leaq 0x50e4f(%rip), %rsi     # 0x5524e
callq 0x32e0
movq %rax, %rdi
movl 0x613ef(%rip), %esi     # 0x657fc
callq 0x34a0
movq %rax, %rdi
movq 0x60ba4(%rip), %rsi     # 0x64fc0
callq 0x3310
movq %rax, %rdi
leaq 0x50e4d(%rip), %rsi     # 0x55278
callq 0x32e0
movq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x34a0
movq %rax, %rdi
movq 0x60b7b(%rip), %rsi     # 0x64fc0
callq 0x3310
movq %rax, %rdi
leaq 0x50e4e(%rip), %rsi     # 0x552a2
callq 0x32e0
movq %rax, %rdi
cvtsi2sdl 0x61398(%rip), %xmm0 # 0x657fc
cvtsi2sdl -0x34(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x3520
movq %rax, %rdi
movq 0x60b44(%rip), %rsi     # 0x64fc0
callq 0x3310
movq %rax, %rdi
leaq 0x50e47(%rip), %rsi     # 0x552d2
callq 0x32e0
movq %rax, %rdi
cvtsi2sdl -0x38(%rbp), %xmm0
cvtsi2sdl -0x34(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x3520
movq %rax, %rdi
movq 0x60b10(%rip), %rsi     # 0x64fc0
callq 0x3310
movq %rax, %rdi
leaq 0x50e43(%rip), %rsi     # 0x55302
callq 0x32e0
movq %rax, %rdi
cvtsi2sdl 0x6133d(%rip), %xmm0 # 0x6580c
cvtsi2sdl -0x34(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x3520
movq %rax, %rdi
movq 0x60ad9(%rip), %rsi     # 0x64fc0
callq 0x3310
movq %rax, %rdi
leaq 0x50e2a(%rip), %rsi     # 0x55320
callq 0x32e0
movq %rax, %rdi
cvtsi2sdl -0x3c(%rbp), %xmm0
cvtsi2sdl 0x60db9(%rip), %xmm1 # 0x652c4
divsd %xmm1, %xmm0
callq 0x3520
movq %rax, %rdi
movq 0x60aa2(%rip), %rsi     # 0x64fc0
callq 0x3310
callq 0x4030
movl $0x0, -0x4(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nop