// File: /workspace/github_cpp_makefile_star2_O1/estwings57[P]CasHMC/sources/Packet.cpp
// Function: CasHMC::Packet::GetCRC()
unsigned long Packet::GetCRC()
{
	uint64_t packetData[LNG*2];

	if(packetType == REQUEST) {
		packetData[0] <<= 3;	packetData[0] |= (CUB&0x7);
		packetData[0] <<= 3;	packetData[0] |= (RES&0x7);
		packetData[0] <<= 34;	packetData[0] |= (ADRS&0x3FFFFFFFF);
		packetData[0] <<= 1;	packetData[0] |= (RES&0x1);
		packetData[0] <<= 11;	packetData[0] |= (TAG&0x7FF);
		packetData[0] <<= 5;	packetData[0] |= (LNG&0x1F);
		packetData[0] <<= 7;	packetData[0] |= (CMD&0x7F);
	}
	else {
		packetData[0] <<= 3;	packetData[0] |= (CUB&0x7);
		packetData[0] <<= 19;	packetData[0] |= (RES&0x7FFFF);
		packetData[0] <<= 3;	packetData[0] |= (SLID&0x7);
		packetData[0] <<= 5;	packetData[0] |= (RES&0x1F);
		packetData[0] <<= 1;	packetData[0] |= (AF&0x1);
		packetData[0] <<= 10;	packetData[0] |= (RES&0x3FF);
		packetData[0] <<= 11;	packetData[0] |= (TAG&0x7FF);
		packetData[0] <<= 5;	packetData[0] |= (LNG&0x1F);
		packetData[0] <<= 7;	packetData[0] |= (CMD&0x7F);
	}
	
	for(int i=1; i<=(LNG-1)*2; i++){
		packetData[i]=DATA[i-1];
	}
	
	if(packetType == REQUEST) {
		packetData[LNG*2-1] <<= 32;		packetData[LNG*2-1] |= (0&0xFFFFFFFF);	//CRC initial value is '0' before CRC calculation
		packetData[LNG*2-1] <<= 3;		packetData[LNG*2-1] |= (RTC&0x7);
		packetData[LNG*2-1] <<= 3;		packetData[LNG*2-1] |= (SLID&0x7);
		packetData[LNG*2-1] <<= 4;		packetData[LNG*2-1] |= (RES&0xF);
		packetData[LNG*2-1] <<= 1;		packetData[LNG*2-1] |= (Pb&0x1);
		packetData[LNG*2-1] <<= 3;		packetData[LNG*2-1] |= (SEQ&0x7);
		packetData[LNG*2-1] <<= 9;		packetData[LNG*2-1] |= (FRP&0x1FF);
		packetData[LNG*2-1] <<= 9;		packetData[LNG*2-1] |= (RRP&0x1FF);
	}
	else {
		packetData[LNG*2-1] <<= 32;		packetData[LNG*2-1] |= (0&0xFFFFFFFF);	//CRC initial value is '0' before CRC calculation
		packetData[LNG*2-1] <<= 3;		packetData[LNG*2-1] |= (RTC&0x7);
		packetData[LNG*2-1] <<= 7;		packetData[LNG*2-1] |= (ERRSTAT&0x7F);
		packetData[LNG*2-1] <<= 1;		packetData[LNG*2-1] |= (DINV&0x1);
		packetData[LNG*2-1] <<= 3;		packetData[LNG*2-1] |= (SEQ&0x7);
		packetData[LNG*2-1] <<= 9;		packetData[LNG*2-1] |= (FRP&0x1FF);
		packetData[LNG*2-1] <<= 9;		packetData[LNG*2-1] |= (RRP&0x1FF);
	}
	
	unsigned char buf[8];
	uint32_t crc = 0;
	
	for(int j=0; j<LNG*2; j++){
		for(int i=0; i<8; i++){
			buf[i] = packetData[j];
			packetData[j] >>= 8;
		}
		crc = CalcCRC(buf, 8, crc, CRCtable);
	}
	return crc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x430(%rdi), %eax
leal (%rax,%rax), %r15d
movq %rsp, %rcx
leaq (,%r15,8), %rdx
movq %rcx, %r14
subq %rdx, %r14
movq %r14, %rsp
negq %rdx
movl 0x10(%rdi), %r12d
movq (%r14), %rsi
leaq (,%rsi,8), %rdi
movq %rdi, (%rcx,%rdx)
movl 0x428(%rbx), %ecx
andl $0x7, %ecx
leaq (%rcx,%rsi,8), %rcx
testl %r12d, %r12d
je 0x289ff
shlq $0x16, %rcx
movq %rcx, (%r14)
movl 0x440(%rbx), %edx
andl $0x7, %edx
orq %rcx, %rdx
shlq $0x6, %rdx
movq %rdx, (%r14)
movl 0x45c(%rbx), %ecx
andl $0x1, %ecx
orq %rdx, %rcx
shlq $0x15, %rcx
movq %rcx, (%r14)
movl 0x42c(%rbx), %edx
andl $0x7ff, %edx            # imm = 0x7FF
orq %rcx, %rdx
shlq $0xc, %rdx
andl $0x1f, %eax
shll $0x7, %eax
orq %rdx, %rax
jmp 0x28a3d
shlq $0x25, %rcx
movq %rcx, (%r14)
movabsq $0x3ffffffff, %rdx      # imm = 0x3FFFFFFFF
andq 0x450(%rbx), %rdx
orq %rcx, %rdx
shlq $0xc, %rdx
movq %rdx, (%r14)
movl 0x42c(%rbx), %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
orq %rdx, %rcx
shlq $0xc, %rcx
andl $0x1f, %eax
shll $0x7, %eax
orq %rcx, %rax
movq %rax, (%r14)
movl 0x434(%rbx), %ecx
andl $0x7f, %ecx
orq %rax, %rcx
movq %rcx, (%r14)
movl %r15d, %eax
addl $-0x2, %eax
je 0x28a6a
movq 0x18(%rbx), %rsi
leaq 0x8(%r14), %rdi
movl %eax, %edx
shlq $0x3, %rdx
callq 0x4260
leal -0x1(%r15), %eax
movq (%r14,%rax,8), %rcx
shlq $0x23, %rcx
movq %rcx, (%r14,%rax,8)
movl 0x43c(%rbx), %edx
andl $0x7, %edx
orq %rcx, %rdx
testl %r12d, %r12d
je 0x28aaf
shlq $0x7, %rdx
movq %rdx, (%r14,%rax,8)
movl 0x460(%rbx), %ecx
andl $0x7f, %ecx
orq %rdx, %rcx
addq %rcx, %rcx
movq %rcx, (%r14,%rax,8)
leaq 0x464(%rbx), %rdx
jmp 0x28ad7
leaq (,%rdx,8), %rcx
movq %rcx, (%r14,%rax,8)
movl 0x440(%rbx), %ecx
andl $0x7, %ecx
leaq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
movq %rcx, (%r14,%rax,8)
leaq 0x458(%rbx), %rdx
movl (%rdx), %edx
andl $0x1, %edx
orq %rcx, %rdx
leaq (,%rdx,8), %rcx
movq %rcx, (%r14,%rax,8)
movl 0x444(%rbx), %ecx
andl $0x7, %ecx
leaq (%rcx,%rdx,8), %rcx
shlq $0x9, %rcx
movq %rcx, (%r14,%rax,8)
movl 0x448(%rbx), %edx
movl $0x1ff, %esi            # imm = 0x1FF
andq %rsi, %rdx
orq %rcx, %rdx
shlq $0x9, %rdx
movq %rdx, (%r14,%rax,8)
movl 0x44c(%rbx), %ecx
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, (%r14,%rax,8)
testl %r15d, %r15d
je 0x28b7d
movl %r15d, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %edx, %edx
movq (%r14,%rdx,8), %rsi
xorl %edi, %edi
movb %sil, -0x28(%rbp,%rdi)
shrq $0x8, %rsi
incq %rdi
cmpq $0x8, %rdi
jne 0x28b3e
movq %rsi, (%r14,%rdx,8)
xorl %esi, %esi
movb -0x28(%rbp,%rsi), %dil
xorb %al, %dil
movzbl %dil, %edi
shrl $0x8, %eax
xorl 0x20(%rbx,%rdi,4), %eax
incq %rsi
cmpl $0x8, %esi
jne 0x28b56
incq %rdx
cmpq %rcx, %rdx
jne 0x28b38
notl %eax
jmp 0x28b7f
xorl %eax, %eax
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq