// File: estwings57[P]CasHMC/sources/HMCController.cpp
// Function: CasHMC::HMCController::LinkPowerExitManager()
void HMCController::LinkPowerExitManager()
{
	switch(LINK_POWER) {
		case NO_MANAGEMENT:{
			break;
		}
		case QUIESCE_SLEEP:{
			//Check the current link state (sleep or down)
			int link = 0;
			int linkState = 0;
			for(link=0; link<NUM_LINKS; link++) {
				if(downLinkMasters[link]->currentState == DOWN) {
					linkState = 1;
					break;
				}
				else if(downLinkMasters[link]->currentState == SLEEP) {
					linkState = 2;
					break;
				}
			}
			//Link is already waking up
			for(int l=0; l<NUM_LINKS; l++) {
				if(downLinkMasters[l]->currentState == TRANSITION_TO_RETRAIN
				|| downLinkMasters[l]->currentState == RETRAIN1
				|| downLinkMasters[l]->currentState == RETRAIN2) {
					linkState = 0;
					break;
				}
			}
			
			//If link is on down mode
			if(linkState == 1) {
				if(downBuffers.size() > 0 && currentClockCycle >= staySREF) {
					modeTransition[link] = currentClockCycle + ceil((double)(tPST+tTXD+tPSC)/CPU_CLK_PERIOD);
					downLinkMasters[link]->currentState = TRANSITION_TO_RETRAIN;
					DEBUG(ALI(33)<<header<<"Down) RETRAINING MODE transition after "<<modeTransition[link]<<" cycle (LM_D"<<link<<")");
				}
			}
			//If link is on sleep mode
			else if(linkState == 2) {
				if(downBuffers.size() >= AWAKE_REQ) {
					modeTransition[link] = currentClockCycle + ceil((double)(tPST+tTXD)/CPU_CLK_PERIOD);
					downLinkMasters[link]->currentState = TRANSITION_TO_RETRAIN;
					DEBUG(ALI(33)<<header<<"Down) RETRAINING MODE transition after "<<modeTransition[link]<<" cycle (LM_D"<<link<<")");
				}
			}
			
			//Retraining mode entry
			for(int l=0; l<NUM_LINKS; l++) {
				if(downLinkMasters[l]->currentState == TRANSITION_TO_RETRAIN) {
					if(currentClockCycle >= modeTransition[l]) {
						for(int k=0; k<NUM_LINKS; k++) {
							if(downLinkMasters[k]->currentState == DOWN) {
								downLinkMasters[k]->currentState = SLEEP;
							}
						}
						downLinkMasters[l]->firstNull = true;
						downLinkMasters[l]->currentState = RETRAIN1;
						stayActive[l] = currentClockCycle + ceil((double)tOP/CPU_CLK_PERIOD);
						DE_CR(ALI(33)<<header<<"Down) entering RETRAINING MODE (LM_D"<<l<<")");
					}
				}
			}
			break;
		}
		case MSHR:
		case LINK_MONITOR:
		case AUTONOMOUS:{
			//awake up links as many as sleepLink
			for(int l=0; l<NUM_LINKS-sleepLink; l++) {
				if(downLinkMasters[l]->currentState == SLEEP) {
					//Stagger transition between active mode and sleep modes in order to avoid supply voltage shifts
					if(currentClockCycle >= staggerActive) {
						uint64_t stag = 0;
						uint64_t tran = 0;
						if(staggeringActive[l]) {
							staggeringActive[l] = false;
							stag = ceil((double)tSS/CPU_CLK_PERIOD);
							tran = ceil((double)tTXD/CPU_CLK_PERIOD);
						}
						else {
							stag = ceil((double)(tPST+tSS)/CPU_CLK_PERIOD);
							tran = ceil((double)(tPST+tTXD)/CPU_CLK_PERIOD);
						}
						staggerActive = currentClockCycle + stag;
						modeTransition[l] = currentClockCycle + tran;
						downLinkMasters[l]->currentState = TRANSITION_TO_RETRAIN;
						DEBUG(ALI(33)<<header<<"Down) RETRAINING MODE transition after "<<modeTransition[l]<<" cycle (stagger : "<<staggerActive<<") (LM_D"<<l<<")");
					}
					else {
						staggeringActive[l] = true;
					}
				}
			}
			
			//Retraining mode entry
			for(int l=0; l<NUM_LINKS; l++) {
				if(downLinkMasters[l]->currentState == TRANSITION_TO_RETRAIN) {
					if(currentClockCycle >= modeTransition[l]) {
						for(int k=0; k<NUM_LINKS; k++) {
							if(downLinkMasters[k]->currentState == DOWN) {
								downLinkMasters[k]->currentState = SLEEP;
							}
						}
						downLinkMasters[l]->firstNull = true;
						downLinkMasters[l]->currentState = RETRAIN1;
						stayActive[l] = currentClockCycle + ceil((double)tOP/CPU_CLK_PERIOD);
						DE_CR(ALI(33)<<header<<"Down) entering RETRAINING MODE (LM_D"<<l<<")");
					}
				}
			}
			break;
		}
		default:{
			ERROR(header<<"   == Error - WRONG LINK_POWER parameter  (LINK_POWER : "<<LINK_POWER<<")");
			exit(0);
			break;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq 0x2f887(%rip), %rax     # 0x66588
movl (%rax), %eax
movl %eax, -0x94(%rbp)
testl %eax, %eax
je 0x36d33
jmp 0x36d0f
movl -0x94(%rbp), %eax
subl $0x1, %eax
je 0x36d38
jmp 0x36d1c
movl -0x94(%rbp), %eax
addl $-0x2, %eax
subl $0x3, %eax
jb 0x3750c
jmp 0x37bc2
jmp 0x37c67
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
leaq 0x2f7f1(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x36dc2
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0xc(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x2, 0x200(%rax)
jne 0x36d87
movl $0x1, -0x10(%rbp)
jmp 0x36dc2
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0xc(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x1, 0x200(%rax)
jne 0x36db3
movl $0x2, -0x10(%rbp)
jmp 0x36dc2
jmp 0x36db5
jmp 0x36db7
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x36d4d
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
leaq 0x2f775(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x36e5d
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x14(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x7, 0x200(%rax)
je 0x36e44
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x14(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x3, 0x200(%rax)
je 0x36e44
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x14(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x4, 0x200(%rax)
jne 0x36e4d
movl $0x0, -0x10(%rbp)
jmp 0x36e5d
jmp 0x36e4f
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x36dc9
cmpl $0x1, -0x10(%rbp)
jne 0x3707e
movq -0xa0(%rbp), %rdi
addq $0x1d0, %rdi            # imm = 0x1D0
callq 0x1b4f0
cmpq $0x0, %rax
jbe 0x37079
movq -0xa0(%rbp), %rcx
movq 0x8(%rcx), %rax
cmpq 0x280(%rcx), %rax
jb 0x37079
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %xmm0
movaps 0x1a271(%rip), %xmm1    # 0x51120
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1a275(%rip), %xmm1    # 0x51130
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq 0x2f6e7(%rip), %rax     # 0x665c0
movsd (%rax), %xmm0
leaq 0x2f714(%rip), %rax     # 0x665f8
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
leaq 0x2f71d(%rip), %rax     # 0x66610
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
leaq 0x2f636(%rip), %rax     # 0x66538
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0xa0(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1c2bc(%rip), %xmm1    # 0x531f8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0xa8(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0xc(%rbp), %rsi
callq 0x17df0
movq -0xa8(%rbp), %rcx
movq -0xa0(%rbp), %rdi
movq %rcx, (%rax)
addq $0x208, %rdi            # imm = 0x208
movslq -0xc(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
movl $0x7, 0x200(%rax)
leaq 0x2f591(%rip), %rax     # 0x66528
testb $0x1, (%rax)
je 0x37077
leaq 0x2f582(%rip), %rax     # 0x66529
testb $0x1, (%rax)
jne 0x37077
movl $0x21, %edi
callq 0x177b0
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %esi
movq 0x2f009(%rip), %rdi     # 0x65fd0
callq 0x4440
movq %rax, -0xc0(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0xc0(%rbp), %rdi
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %esi
callq 0x4550
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1c592(%rip), %rsi     # 0x5359f
callq 0x4380
movq -0xa0(%rbp), %rdi
movq %rax, -0xb8(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0xc(%rbp), %rsi
callq 0x17df0
movq -0xb8(%rbp), %rdi
movq (%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1c57e(%rip), %rsi     # 0x535c7
callq 0x4380
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x1d316(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2ef3e(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x37079
jmp 0x37280
cmpl $0x2, -0x10(%rbp)
jne 0x3727e
movq -0xa0(%rbp), %rdi
addq $0x1d0, %rdi            # imm = 0x1D0
callq 0x1b4f0
leaq 0x2f4ea(%rip), %rcx     # 0x6658c
movslq (%rcx), %rcx
cmpq %rcx, %rax
jb 0x3727c
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %xmm0
movaps 0x1a05f(%rip), %xmm1    # 0x51120
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1a063(%rip), %xmm1    # 0x51130
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
leaq 0x2f4d5(%rip), %rax     # 0x665c0
movsd (%rax), %xmm0
leaq 0x2f502(%rip), %rax     # 0x665f8
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
leaq 0x2f433(%rip), %rax     # 0x66538
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0xa0(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1c0b9(%rip), %xmm1    # 0x531f8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0xc8(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0xc(%rbp), %rsi
callq 0x17df0
movq -0xc8(%rbp), %rcx
movq -0xa0(%rbp), %rdi
movq %rcx, (%rax)
addq $0x208, %rdi            # imm = 0x208
movslq -0xc(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
movl $0x7, 0x200(%rax)
leaq 0x2f38e(%rip), %rax     # 0x66528
testb $0x1, (%rax)
je 0x3727a
leaq 0x2f37f(%rip), %rax     # 0x66529
testb $0x1, (%rax)
jne 0x3727a
movl $0x21, %edi
callq 0x177b0
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %esi
movq 0x2ee06(%rip), %rdi     # 0x65fd0
callq 0x4440
movq %rax, -0xe0(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0xe0(%rbp), %rdi
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %esi
callq 0x4550
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1c38f(%rip), %rsi     # 0x5359f
callq 0x4380
movq -0xa0(%rbp), %rdi
movq %rax, -0xd8(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0xc(%rbp), %rsi
callq 0x17df0
movq -0xd8(%rbp), %rdi
movq (%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1c37b(%rip), %rsi     # 0x535c7
callq 0x4380
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x1d113(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2ed3b(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x3727c
jmp 0x3727e
jmp 0x37280
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
leaq 0x2f2b7(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x37507
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x28(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x7, 0x200(%rax)
jne 0x374f7
movq -0xa0(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0xe8(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0x28(%rbp), %rsi
callq 0x17df0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
cmpq (%rcx), %rax
jb 0x374f5
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
leaq 0x2f242(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x3735e
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x2c(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x2, 0x200(%rax)
jne 0x37351
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x2c(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
movl $0x1, 0x200(%rax)
jmp 0x37353
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x372fc
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movq %rdi, -0x100(%rbp)
movslq -0x28(%rbp), %rsi
callq 0x17770
movq -0x100(%rbp), %rdi
movq (%rax), %rax
movb $0x1, 0x268(%rax)
movslq -0x28(%rbp), %rsi
callq 0x17770
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq (%rcx), %rcx
movl $0x3, 0x200(%rcx)
movq 0x8(%rax), %xmm0
movaps 0x19d67(%rip), %xmm1    # 0x51120
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x19d6b(%rip), %xmm1    # 0x51130
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq 0x2f205(%rip), %rax     # 0x665e8
movsd (%rax), %xmm0
leaq 0x2f14a(%rip), %rax     # 0x66538
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0xa0(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0xf8(%rbp), %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1bdd0(%rip), %xmm1    # 0x531f8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0xf0(%rbp)
addq $0x288, %rdi            # imm = 0x288
movslq -0x28(%rbp), %rsi
callq 0x17df0
movq -0xf0(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x2f0c9(%rip), %rax     # 0x66528
testb $0x1, (%rax)
je 0x374f3
movl $0x21, %edi
callq 0x177b0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %esi
movq 0x2eb51(%rip), %rdi     # 0x65fd0
callq 0x4440
movq %rax, -0x108(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0x108(%rbp), %rdi
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %esi
callq 0x4550
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1c10f(%rip), %rsi     # 0x535d4
callq 0x4380
movq %rax, %rdi
movl -0x28(%rbp), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x1ce9a(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2eac2(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x374f5
jmp 0x374f7
jmp 0x374f9
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x37287
jmp 0x37c67
movl $0x0, -0x38(%rbp)
movq -0xa0(%rbp), %rdx
movl -0x38(%rbp), %eax
leaq 0x2f024(%rip), %rcx     # 0x66548
movl (%rcx), %ecx
subl 0x258(%rdx), %ecx
cmpl %ecx, %eax
jae 0x378fa
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x38(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x1, 0x200(%rax)
jne 0x378ea
movq -0xa0(%rbp), %rcx
movq 0x8(%rcx), %rax
cmpq 0x278(%rcx), %rax
jb 0x378bb
movq -0xa0(%rbp), %rdi
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
addq $0x2f8, %rdi            # imm = 0x2F8
movslq -0x38(%rbp), %rsi
callq 0x22820
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x22880
testb $0x1, %al
jne 0x375b4
jmp 0x37684
movq -0xa0(%rbp), %rdi
addq $0x2f8, %rdi            # imm = 0x2F8
movslq -0x38(%rbp), %rsi
callq 0x22820
movq %rax, -0x68(%rbp)
movq %rdx, -0x60(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x22b00
leaq 0x2efeb(%rip), %rax     # 0x665d0
movsd (%rax), %xmm0
leaq 0x2ef48(%rip), %rax     # 0x66538
movq %rax, -0x118(%rbp)
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0x118(%rbp), %rax
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x1bbd6(%rip), %xmm1    # 0x531f8
movsd %xmm1, -0x110(%rbp)
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
movq %rcx, -0x40(%rbp)
leaq 0x2efb4(%rip), %rcx     # 0x665f8
movsd (%rcx), %xmm0
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movsd -0x110(%rbp), %xmm1
movaps %xmm0, %xmm2
cvttsd2si %xmm2, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x3774a
leaq 0x2ef35(%rip), %rax     # 0x665c0
movq %rax, -0x130(%rbp)
movsd (%rax), %xmm0
leaq 0x2ef33(%rip), %rax     # 0x665d0
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
leaq 0x2ee8c(%rip), %rax     # 0x66538
movq %rax, -0x128(%rbp)
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0x130(%rbp), %rcx
movq -0x128(%rbp), %rax
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
movsd 0x1bb13(%rip), %xmm1    # 0x531f8
movsd %xmm1, -0x120(%rbp)
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rsi
andq %rdi, %rsi
orq %rsi, %rdx
movq %rdx, -0x40(%rbp)
movsd (%rcx), %xmm0
leaq 0x2eeed(%rip), %rcx     # 0x665f8
movsd (%rcx), %xmm1
addsd %xmm1, %xmm0
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movsd -0x120(%rbp), %xmm1
movaps %xmm0, %xmm2
cvttsd2si %xmm2, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0xa0(%rbp), %rdi
movq 0x8(%rdi), %rax
addq -0x40(%rbp), %rax
movq %rax, 0x278(%rdi)
movq 0x8(%rdi), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x138(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0x38(%rbp), %rsi
callq 0x17df0
movq -0x138(%rbp), %rcx
movq -0xa0(%rbp), %rdi
movq %rcx, (%rax)
addq $0x208, %rdi            # imm = 0x208
movslq -0x38(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
movl $0x7, 0x200(%rax)
leaq 0x2ed74(%rip), %rax     # 0x66528
testb $0x1, (%rax)
je 0x378b9
leaq 0x2ed65(%rip), %rax     # 0x66529
testb $0x1, (%rax)
jne 0x378b9
movl $0x21, %edi
callq 0x177b0
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %esi
movq 0x2e7ec(%rip), %rdi     # 0x65fd0
callq 0x4440
movq %rax, -0x148(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0x148(%rbp), %rdi
movb %al, -0x6d(%rbp)
movzbl -0x6d(%rbp), %esi
callq 0x4550
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1bd75(%rip), %rsi     # 0x5359f
callq 0x4380
movq -0xa0(%rbp), %rdi
movq %rax, -0x140(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0x38(%rbp), %rsi
callq 0x17df0
movq -0x140(%rbp), %rdi
movq (%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1bc30(%rip), %rsi     # 0x53496
callq 0x4380
movq %rax, %rdi
movq -0xa0(%rbp), %rax
movq 0x278(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x1bc1e(%rip), %rsi     # 0x534a9
callq 0x4380
movq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x1cad4(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2e6fc(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x378e8
movq -0xa0(%rbp), %rdi
addq $0x2f8, %rdi            # imm = 0x2F8
movslq -0x38(%rbp), %rsi
callq 0x22820
movq %rax, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0x22b00
jmp 0x378ea
jmp 0x378ec
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x37513
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
leaq 0x2ec37(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x37bbd
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x84(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x7, 0x200(%rax)
jne 0x37ba7
movq -0xa0(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x150(%rbp)
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0x84(%rbp), %rsi
callq 0x17df0
movq %rax, %rcx
movq -0x150(%rbp), %rax
cmpq (%rcx), %rax
jb 0x37ba5
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
leaq 0x2ebb6(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x379f6
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x88(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
cmpl $0x2, 0x200(%rax)
jne 0x379e3
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x88(%rbp), %rsi
callq 0x17770
movq (%rax), %rax
movl $0x1, 0x200(%rax)
jmp 0x379e5
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x37985
movq -0xa0(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movq %rdi, -0x168(%rbp)
movslq -0x84(%rbp), %rsi
callq 0x17770
movq -0x168(%rbp), %rdi
movq (%rax), %rax
movb $0x1, 0x268(%rax)
movslq -0x84(%rbp), %rsi
callq 0x17770
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq (%rcx), %rcx
movl $0x3, 0x200(%rcx)
movq 0x8(%rax), %xmm0
movaps 0x196c9(%rip), %xmm1    # 0x51120
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x196cd(%rip), %xmm1    # 0x51130
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
leaq 0x2eb67(%rip), %rax     # 0x665e8
movsd (%rax), %xmm0
leaq 0x2eaac(%rip), %rax     # 0x66538
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0xa0(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x160(%rbp), %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1b732(%rip), %xmm1    # 0x531f8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x158(%rbp)
addq $0x288, %rdi            # imm = 0x288
movslq -0x84(%rbp), %rsi
callq 0x17df0
movq -0x158(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x2ea28(%rip), %rax     # 0x66528
testb $0x1, (%rax)
je 0x37ba3
movl $0x21, %edi
callq 0x177b0
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %esi
movq 0x2e4aa(%rip), %rdi     # 0x65fd0
callq 0x4440
movq %rax, -0x170(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0x170(%rbp), %rdi
movb %al, -0x8d(%rbp)
movzbl -0x8d(%rbp), %esi
callq 0x4550
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1ba62(%rip), %rsi     # 0x535d4
callq 0x4380
movq %rax, %rdi
movl -0x84(%rbp), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x1c7ea(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2e412(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x37ba5
jmp 0x37ba7
jmp 0x37ba9
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x37904
jmp 0x37c67
movq 0x2e427(%rip), %rdi     # 0x65ff0
leaq 0x1946a(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x1b728(%rip), %rsi     # 0x53307
callq 0x4380
movq %rax, %rdi
leaq 0x19c47(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x2d0, %esi            # imm = 0x2D0
callq 0x4610
movq %rax, %rdi
leaq 0x1944f(%rip), %rsi     # 0x51059
callq 0x4380
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x1b8c8(%rip), %rsi     # 0x534f4
callq 0x4380
movq %rax, %rdi
leaq 0x2e94d(%rip), %rax     # 0x66588
movl (%rax), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x1c72d(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x2e355(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq