// File: mouda[P]LTE_random_access-simulate/End.cpp
// Function: End::settime()
void End::settime()
{
    if (_setTime != _time)
	return;
    if(preamble[_preamble] == 1) {
	id();// case for success
    }
    else if (preamble[_preamble] > 1){
	int Fwait = rand() % 5 + 1;
	_collision++;
	_setTime += _CountCeil(/*lte::firstWaiting*/ (Fwait + 3) + lte::secondWaiting + rand()%lte::RandomBackoffIndex);
	_index++;
	if(_index > lte::MAX) {
	    _setTime = -2;
	    _finish = _time + (Fwait + 3) + lte::secondWaiting;
	    _count++;
	}
    }else {
	_setTime += _CountCeil(lte::firstWaiting + rand()%lte::RandomBackoffIndex);
	//set the next preamble transmission time
	_index++;
	if(_index > lte::MAX){
	    _count++;
	    _setTime = -2;
	    _finish = _time + lte::firstWaiting;
	}
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl (%rax), %eax
leaq 0x61a33(%rip), %rcx     # 0x652e0
cmpl (%rcx), %eax
je 0x38b6
jmp 0x3a2b
movq -0x18(%rbp), %rcx
leaq 0x61f3f(%rip), %rax     # 0x65800
movq (%rax), %rax
movslq 0x4(%rcx), %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x38dc
movq -0x18(%rbp), %rdi
callq 0x3a40
jmp 0x3a2b
movq -0x18(%rbp), %rcx
leaq 0x61f19(%rip), %rax     # 0x65800
movq (%rax), %rax
movslq 0x4(%rcx), %rcx
cmpl $0x1, (%rax,%rcx,4)
jle 0x39a9
callq 0x30b0
movl $0x5, %ecx
cltd
idivl %ecx
movq -0x18(%rbp), %rax
addl $0x1, %edx
movl %edx, -0xc(%rbp)
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movl -0xc(%rbp), %eax
addl $0x3, %eax
leaq 0x619b3(%rip), %rcx     # 0x652d8
addl (%rcx), %eax
movl %eax, -0x1c(%rbp)
callq 0x30b0
movl -0x1c(%rbp), %esi
movq -0x18(%rbp), %rdi
leaq 0x61993(%rip), %rcx     # 0x652d0
cltd
idivl (%rcx)
addl %edx, %esi
callq 0x3b70
movl %eax, %ecx
movq -0x18(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movl 0x14(%rax), %eax
leaq 0x61968(%rip), %rcx     # 0x652cc
cmpl (%rcx), %eax
jle 0x39a4
movq -0x18(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
leaq 0x61967(%rip), %rcx     # 0x652e0
movl (%rcx), %ecx
movl -0xc(%rbp), %edx
addl $0x3, %edx
addl %edx, %ecx
leaq 0x6194e(%rip), %rdx     # 0x652d8
addl (%rdx), %ecx
movl %ecx, 0x8(%rax)
leaq 0x61e72(%rip), %rax     # 0x65808
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x61e66(%rip), %rax     # 0x65808
movl %ecx, (%rax)
jmp 0x3a29
leaq 0x61924(%rip), %rax     # 0x652d4
movl (%rax), %eax
movl %eax, -0x20(%rbp)
callq 0x30b0
movl -0x20(%rbp), %esi
movq -0x18(%rbp), %rdi
leaq 0x61908(%rip), %rcx     # 0x652d0
cltd
idivl (%rcx)
addl %edx, %esi
callq 0x3b70
movl %eax, %ecx
movq -0x18(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movl 0x14(%rax), %eax
leaq 0x618dd(%rip), %rcx     # 0x652cc
cmpl (%rcx), %eax
jle 0x3a27
movq -0x18(%rbp), %rax
leaq 0x61e0a(%rip), %rcx     # 0x65808
movl (%rcx), %edx
addl $0x1, %edx
leaq 0x61dfe(%rip), %rcx     # 0x65808
movl %edx, (%rcx)
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
leaq 0x618c7(%rip), %rcx     # 0x652e0
movl (%rcx), %ecx
leaq 0x618b2(%rip), %rdx     # 0x652d4
addl (%rdx), %ecx
movl %ecx, 0x8(%rax)
jmp 0x3a29
jmp 0x3a2b
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)