// File: /workspace/github_c_makefile_star2_O0/fmadio[P]pcap_flow/tcpstream.c
// Function: fTCPStream_PacketAdd
void fTCPStream_PacketAdd(TCPStream_t* S, u64 TS, TCPHeader_t* TCP, s32 Length, u8* Payload, PCAPPacket_t* Pkt)
{
	// raw PCAP output only 
	if (g_OutputPCAP)
	{
		// closed so re-open
		if (!S->File)
		{
			S->File = fFile_Open(S->Path, NULL); 
			if (S->File == NULL)
			{
				fprintf(stderr, "failed to open output file [%s]\n", S->Path);
			}
		}
		fFile_Write(S->File, Pkt, sizeof(PCAPPacket_t) + Pkt->LengthCapture, true);
		return;
	}

	// if length is invalid then drop the packet
	if (Length < 0)
	{
		printf("ERROR: TCP Packet Length Negative!?: %s %s : %i\n", FormatTS(TS), S->Path, Length);
		return;
	}

	//printf("tcp len: %i %08x %08x\n", Length, swap32(TCP->SeqNo), swap32(TCP->AckNo));
	u32 WindowSize 	= swap16( TCP->Window) * S->WindowScale;
	u32 SeqNo 		= swap32( TCP->SeqNo );
	u32 AckNo 		= swap32( TCP->AckNo );

	// last packet TS	
	S->LastTS 		= TS; 

	u32 Flag 		= StreamTCPFlag(TCP->Flags); 
	if (TCP_FLAG_SYN(TCP->Flags))
	{
		if (g_Verbose) printf("[%s] [%s] got syn\n", FormatTS(TS), S->Path);
		S->SeqNo = SeqNo + 1;

		fProfile_Start(9, "TCP PktAdd release");

		// release all reassembly buffer data . assumption is this is now a new tcp stream
		for (int i=0; i < S->BufferListPos; i++)
		{
			TCPBuffer_t* Buffer = S->BufferList[i];

			free(Buffer->Payload);
			Buffer->Payload = NULL;

			free(Buffer);

			s_TCPBufferMemoryTotal  -= sizeof(TCPBuffer_t) + Length;
			s_TCPBufferPacketTotal 	-= 1;
		}
		S->BufferListPos = 0;

		fProfile_Stop(9);

		// parse options
		u32 OLen = (4*swap16(TCP->Flags) >> 12) - 20;
		u8* Option = (u8*)(TCP + 1);
		for (int o=0; o < OLen; o++)
		{
			// end of options
			if (Option[o] == 0) break;

			// nop
			if (Option[o] == 1) continue;

			// MSS
			if ((Option[o+0] == 2) && (Option[o+1] == 4))
			{
				u32 MSS = ((u32)Option[o+2]<< 8) | (u32)Option[o+3];
				if (g_Verbose) printf("TCP MSS: %i\n", MSS);
				o+= 2;
			}
			// Window Scale 
			if ((Option[o+0] == 3) && (Option[o+1] == 3))
			{
				u32 Scale = Option[o+2];
				if (g_Verbose) printf("TCP WindowScale: %i\n", Scale);
				o+= 1;
				S->WindowScale = Scale;
			}
			// Selective Ack 
			if ((Option[o+0] == 4) && (Option[o+1] == 2))
			{
				if (g_Verbose) printf("TCP SelAck\n");
			}
			//printf("tcp offset: [%4i] %02x\n", o, Option[o]);
		}

		// indicate stream reset
		if (g_EnableTCPHeader)
		{
			TCPOutputHeader_t Header;
			Header.TS 		= TS;
			Header.Length 	= 0;
			Header.StreamID	= S->FlowID;
			Header.SeqNo	= 0; 
			Header.AckNo	= 0; 
			Header.Window	= 0; 
			Header.Flag		= Flag | TCPHEADER_FLAG_RESET; 
			Header.CRC		= 0;
			Header.CRC		+= Header.TS;
			Header.CRC		+= Header.Length;
			Header.CRC		+= Header.StreamID;
			Header.CRC		+= Header.SeqNo;
			Header.CRC		+= Header.AckNo;
			Header.CRC		+= Header.Window;
			Header.CRC		+= Header.Flag;

			fTCPStream_OutputHeader(S, &Header);
		}
	}

	if (Length == 0)
	{
		// usuall ack with no payload	
		if (g_EnableTCPHeader)
		{
			TCPOutputHeader_t Header;
			Header.TS 		= TS;
			Header.Length 	= Length;
			Header.StreamID	= S->FlowID;
			Header.SeqNo	= SeqNo; 
			Header.AckNo	= AckNo; 
			Header.Window	= WindowSize; 
			Header.Flag		= Flag; 
			Header.CRC		= 0;
			Header.CRC		+= Header.TS;
			Header.CRC		+= Header.Length;
			Header.CRC		+= Header.StreamID;
			Header.CRC		+= Header.SeqNo;
			Header.CRC		+= Header.AckNo;
			Header.CRC		+= Header.Window;
			Header.CRC		+= Header.Flag;

			fTCPStream_OutputHeader(S, &Header);
		}
	}
	else
	{
		s32 dSeqNo = SeqNo - S->SeqNo;
		if (dSeqNo == 0)
		{
			fTCPStream_OutputPayload(S, TS, Length, Payload, Flag, SeqNo, AckNo, WindowSize);
			if (S->BufferListPos > 0)
			{
				if (g_Verbose) printf("[%s] [%s] resend hit Seq:%08x : %i\n", FormatTS(TS), S->Path, SeqNo, S->BufferListPos);

				// check for reassembly
				fTCPStream_Reassembly(S, TS, Flag);
			}
		}
		else
		{
			fProfile_Start(7, "TCP PktAdd OOO");

			// reassembly packet thats not aligned but close to the current seq no
			s32 dRemain = (SeqNo + Length) - S->SeqNo;
			if ((SeqNo < S->SeqNo) && (dRemain > 0) && (dRemain < 8*1024))
			{
				if (g_Verbose) 
				{
					printf("[%s] [%s] unaligned seq resend: %i [%llx:%llx]\n",
						FormatTS(TS),
						S->Path,
						dRemain,
						S->WritePos,
						S->WritePos + dRemain
					   );
				}

				s32 PayloadOffset = S->SeqNo - SeqNo; 
				if (PayloadOffset <= 0)
				{
					printf("[%s] [%s] ERROR: TCP OOO reassembly PayloadOffset:%i SeqNo:%08x %08x dRemain:%i Length:%i\n", FormatTS(TS), S->Path, PayloadOffset, S->SeqNo, SeqNo, dRemain, Length);
				}
				else
				{
					fTCPStream_OutputPayload(S, TS, dRemain, Payload + PayloadOffset, Flag | TCPHEADER_FLAG_REASSEMBLE, S->SeqNo, 0, 0);

					// check re-assembly buffer 
					fTCPStream_Reassembly(S, TS, Flag);
				}
			}

			// stop processing if too many gaps 
			else if (S->BufferListPos < S->BufferListMax)
			{
				TCPBuffer_t* B = (TCPBuffer_t*)malloc( sizeof(TCPBuffer_t) );
				assert(B != NULL);

				s_TCPBufferMemoryTotal  += sizeof(TCPBuffer_t) + Length;
				s_TCPBufferPacketTotal 	+= 1;
				g_TotalMemory 			+= sizeof(TCPBuffer_t) + Length;
				g_TotalMemoryTCP 		+= sizeof(TCPBuffer_t) + Length;

				memset(B, 0, sizeof(TCPBuffer_t));
				if (Length >= MAX_TCPSEGMENT)
				{
					printf("TCP length overflow: %i %i\n", Length,  MAX_TCPSEGMENT);
					return;
				}
				//assert(Length < MAX_TCPSEGMENT);

				B->TS 		= TS;
				B->SeqNo 	= SeqNo;
				B->Length 	= Length;
				B->Payload	= malloc( Length );

				assert(B->Payload != NULL);
				memcpy(B->Payload, Payload, Length);

				S->BufferList[ S->BufferListPos++ ] = B;	

				if (g_Verbose)
				{
					printf("[%s] [%s] tcp gap Seq:%08x PktSeq:%08x delta %i OOPkts:%i SEnd:%08x\n", 
						FormatTS(TS), 
						S->Path, 
						S->SeqNo, 
						SeqNo, 
						dSeqNo,
						S->BufferListPos,
						SeqNo + Length);
					printf("[%s] TCP Buffer: %lliMB %.fK Pkts\n", FormatTS(TS), s_TCPBufferMemoryTotal / kMB(1), s_TCPBufferPacketTotal / 1e3 ); 
				}

				// special case when capture begins mid-stream
				if (S->SeqNo == 0)
				{
					if (g_Verbose) printf("[%s] %s midstream start Len:%i\n", FormatTS(TS), S->Path, Length); 
					S->SeqNo = swap32(TCP->SeqNo) + Length;
				}
			}
			else
			{
				// no space for re-assembly so drop it
				S->PktDrop++;
			}

			// number of packets out of order
			S->PktOOO++;;

			fProfile_Stop(7);
		}
	}

	// toatl number of packets
	S->PktTotal++;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
movl %ecx, 0xbc(%rsp)
movq %r8, 0xb0(%rsp)
movq %r9, 0xa8(%rsp)
leaq 0xf777(%rip), %rax      # 0x11224
cmpl $0x0, (%rax)
je 0x1b58
movq 0xd0(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1b24
movq 0xd0(%rsp), %rdi
addq $0x2028, %rdi           # imm = 0x2028
xorl %eax, %eax
movl %eax, %esi
callq 0xb7c0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xd0(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1b22
movq 0xe4f6(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
leaq 0xa604(%rip), %rsi      # 0xc11f
movb $0x0, %al
callq 0x1150
jmp 0x1b24
movq 0xd0(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0xa8(%rsp), %rsi
movq 0xa8(%rsp), %rax
movl 0x8(%rax), %eax
addq $0x10, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0xb900
jmp 0x271e
cmpl $0x0, 0xbc(%rsp)
jge 0x1b9b
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
movl 0xbc(%rsp), %ecx
leaq 0xa5b1(%rip), %rdi      # 0xc140
movb $0x0, %al
callq 0x10e0
jmp 0x271e
movq 0xc0(%rsp), %rax
movzwl 0xe(%rax), %edi
callq 0x2880
movzwl %ax, %eax
movq 0xd0(%rsp), %rcx
imull 0x2448(%rcx), %eax
movl %eax, 0xa4(%rsp)
movq 0xc0(%rsp), %rax
movl 0x4(%rax), %edi
callq 0x28b0
movl %eax, 0xa0(%rsp)
movq 0xc0(%rsp), %rax
movl 0x8(%rax), %edi
callq 0x28b0
movl %eax, 0x9c(%rsp)
movq 0xc8(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x2430(%rax)
movq 0xc0(%rsp), %rax
movzwl 0xc(%rax), %edi
callq 0x2900
movl %eax, 0x98(%rsp)
movq 0xc0(%rsp), %rax
movzwl 0xc(%rax), %eax
sarl $0x9, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x203b
leaq 0xf5c4(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x1c76
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
leaq 0xa502(%rip), %rdi      # 0xc171
movb $0x0, %al
callq 0x10e0
movl 0xa0(%rsp), %ecx
addl $0x1, %ecx
movq 0xd0(%rsp), %rax
movl %ecx, 0x18(%rax)
movl $0x9, %edi
leaq 0xa4ed(%rip), %rsi      # 0xc184
callq 0x17f0
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
movq 0xd0(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jae 0x1d4f
movq 0xd0(%rsp), %rax
movslq 0x94(%rsp), %rcx
movq 0x28(%rax,%rcx,8), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1030
movq 0x88(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x88(%rsp), %rdi
callq 0x1030
movslq 0xbc(%rsp), %rcx
addq $0x18, %rcx
movq 0xe493(%rip), %rax      # 0x101b0
subq %rcx, %rax
movq %rax, 0xe489(%rip)      # 0x101b0
movq 0xe48a(%rip), %rax      # 0x101b8
subq $0x1, %rax
movq %rax, 0xe47f(%rip)      # 0x101b8
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x1ca7
movq 0xd0(%rsp), %rax
movl $0x0, 0x1c(%rax)
movl $0x9, %edi
callq 0x1860
movq 0xc0(%rsp), %rax
movzwl 0xc(%rax), %edi
callq 0x2880
movzwl %ax, %eax
shll $0x2, %eax
sarl $0xc, %eax
subl $0x14, %eax
movl %eax, 0x84(%rsp)
movq 0xc0(%rsp), %rax
addq $0x14, %rax
movq %rax, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
cmpl 0x84(%rsp), %eax
jae 0x1f4e
movq 0x78(%rsp), %rax
movslq 0x74(%rsp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1dce
jmp 0x1f4e
movq 0x78(%rsp), %rax
movslq 0x74(%rsp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x1de6
jmp 0x1f3e
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x2, %eax
jne 0x1e6e
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x4, %eax
jne 0x1e6e
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq 0x78(%rsp), %rcx
movl 0x74(%rsp), %edx
addl $0x3, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, 0x70(%rsp)
leaq 0xf3bc(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x1e63
movl 0x70(%rsp), %esi
leaq 0xa33b(%rip), %rdi      # 0xc197
movb $0x0, %al
callq 0x10e0
movl 0x74(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x74(%rsp)
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x3, %eax
jne 0x1ef0
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x3, %eax
jne 0x1ef0
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x6c(%rsp)
leaq 0xf34c(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x1ed3
movl 0x6c(%rsp), %esi
leaq 0xa2d8(%rip), %rdi      # 0xc1a4
movb $0x0, %al
callq 0x10e0
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
movl 0x6c(%rsp), %ecx
movq 0xd0(%rsp), %rax
movl %ecx, 0x2448(%rax)
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x4, %eax
jne 0x1f3c
movq 0x78(%rsp), %rax
movl 0x74(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x2, %eax
jne 0x1f3c
leaq 0xf2e1(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x1f3a
leaq 0xa286(%rip), %rdi      # 0xc1b9
movb $0x0, %al
callq 0x10e0
jmp 0x1f3c
jmp 0x1f3e
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x1da5
leaq 0xf2b7(%rip), %rax      # 0x1120c
cmpl $0x0, (%rax)
je 0x2039
movq 0xc8(%rsp), %rax
movq %rax, 0x48(%rsp)
movw $0x0, 0x50(%rsp)
movq 0xd0(%rsp), %rax
movl 0x10(%rax), %eax
movw %ax, 0x52(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x5c(%rsp)
movl 0x98(%rsp), %eax
orl $0x8000, %eax           # imm = 0x8000
movw %ax, 0x60(%rsp)
movw $0x0, 0x62(%rsp)
movq 0x48(%rsp), %rcx
movzwl 0x62(%rsp), %eax
addq %rcx, %rax
movw %ax, 0x62(%rsp)
movzwl 0x50(%rsp), %ecx
movzwl 0x62(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x62(%rsp)
movzwl 0x52(%rsp), %ecx
movzwl 0x62(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x62(%rsp)
movl 0x54(%rsp), %ecx
movzwl 0x62(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x62(%rsp)
movl 0x58(%rsp), %ecx
movzwl 0x62(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x62(%rsp)
movl 0x5c(%rsp), %ecx
movzwl 0x62(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x62(%rsp)
movzwl 0x60(%rsp), %ecx
movzwl 0x62(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x62(%rsp)
movq 0xd0(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1680
jmp 0x203b
cmpl $0x0, 0xbc(%rsp)
jne 0x2142
leaq 0xf1bc(%rip), %rax      # 0x1120c
cmpl $0x0, (%rax)
je 0x213d
movq 0xc8(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0xbc(%rsp), %eax
movw %ax, 0x30(%rsp)
movq 0xd0(%rsp), %rax
movl 0x10(%rax), %eax
movw %ax, 0x32(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x9c(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0xa4(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x98(%rsp), %eax
movw %ax, 0x40(%rsp)
movw $0x0, 0x42(%rsp)
movq 0x28(%rsp), %rcx
movzwl 0x42(%rsp), %eax
addq %rcx, %rax
movw %ax, 0x42(%rsp)
movzwl 0x30(%rsp), %ecx
movzwl 0x42(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x42(%rsp)
movzwl 0x32(%rsp), %ecx
movzwl 0x42(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x42(%rsp)
movl 0x34(%rsp), %ecx
movzwl 0x42(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x42(%rsp)
movl 0x38(%rsp), %ecx
movzwl 0x42(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x42(%rsp)
movl 0x3c(%rsp), %ecx
movzwl 0x42(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x42(%rsp)
movzwl 0x40(%rsp), %ecx
movzwl 0x42(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x42(%rsp)
movq 0xd0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1680
jmp 0x2707
movl 0xa0(%rsp), %eax
movq 0xd0(%rsp), %rcx
subl 0x18(%rcx), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jne 0x2229
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0xbc(%rsp), %edx
movq 0xb0(%rsp), %rcx
movl 0x98(%rsp), %r8d
movl 0xa0(%rsp), %r9d
movl 0x9c(%rsp), %r10d
movl 0xa4(%rsp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x18a0
movq 0xd0(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x2224
leaq 0xf045(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x2208
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
movl 0xa0(%rsp), %ecx
movq 0xd0(%rsp), %rax
movl 0x1c(%rax), %r8d
leaq 0x9fc4(%rip), %rdi      # 0xc1c5
movb $0x0, %al
callq 0x10e0
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0x98(%rsp), %edx
callq 0x2930
jmp 0x2705
movl $0x7, %edi
leaq 0x9fb4(%rip), %rsi      # 0xc1e9
callq 0x17f0
movl 0xa0(%rsp), %eax
addl 0xbc(%rsp), %eax
movq 0xd0(%rsp), %rcx
subl 0x18(%rcx), %eax
movl %eax, 0x20(%rsp)
movl 0xa0(%rsp), %eax
movq 0xd0(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x23d9
cmpl $0x0, 0x20(%rsp)
jle 0x23d9
cmpl $0x2000, 0x20(%rsp)     # imm = 0x2000
jge 0x23d9
leaq 0xef79(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x22eb
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
movl 0x20(%rsp), %ecx
movq 0xd0(%rsp), %rax
movq 0x2440(%rax), %r8
movq 0xd0(%rsp), %rax
movq 0x2440(%rax), %r9
movslq 0x20(%rsp), %rax
addq %rax, %r9
leaq 0x9f14(%rip), %rdi      # 0xc1f8
movb $0x0, %al
callq 0x10e0
movq 0xd0(%rsp), %rax
movl 0x18(%rax), %eax
subl 0xa0(%rsp), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jg 0x2363
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
movl 0x1c(%rsp), %ecx
movq 0xd0(%rsp), %rax
movl 0x18(%rax), %r8d
movl 0xa0(%rsp), %r9d
movl 0x20(%rsp), %r10d
movl 0xbc(%rsp), %eax
leaq 0x9ed6(%rip), %rdi      # 0xc228
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x10e0
jmp 0x23d4
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0x20(%rsp), %edx
movq 0xb0(%rsp), %rcx
movslq 0x1c(%rsp), %rax
addq %rax, %rcx
movl 0x98(%rsp), %r8d
orl $0x4000, %r8d           # imm = 0x4000
movq 0xd0(%rsp), %rax
movl 0x18(%rax), %r9d
xorl %eax, %eax
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x18a0
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0x98(%rsp), %edx
callq 0x2930
jmp 0x26e4
movq 0xd0(%rsp), %rax
movl 0x1c(%rax), %eax
movq 0xd0(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x26cb
movl $0x18, %edi
callq 0x1190
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x240e
jmp 0x242d
leaq 0x9e6e(%rip), %rdi      # 0xc283
leaq 0x9c48(%rip), %rsi      # 0xc064
movl $0x257, %edx            # imm = 0x257
leaq 0x9e65(%rip), %rcx      # 0xc28d
callq 0x1100
movslq 0xbc(%rsp), %rax
addq $0x18, %rax
addq 0xdd70(%rip), %rax      # 0x101b0
movq %rax, 0xdd69(%rip)      # 0x101b0
movq 0xdd6a(%rip), %rax      # 0x101b8
addq $0x1, %rax
movq %rax, 0xdd5f(%rip)      # 0x101b8
movslq 0xbc(%rsp), %rcx
addq $0x18, %rcx
leaq 0xed8c(%rip), %rax      # 0x111f8
addq (%rax), %rcx
leaq 0xed82(%rip), %rax      # 0x111f8
movq %rcx, (%rax)
movslq 0xbc(%rsp), %rcx
addq $0x18, %rcx
leaq 0xed74(%rip), %rax      # 0x11200
addq (%rax), %rcx
leaq 0xed6a(%rip), %rax      # 0x11200
movq %rcx, (%rax)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x1110
cmpl $0x100000, 0xbc(%rsp) # imm = 0x100000
jl 0x24d6
movl 0xbc(%rsp), %esi
leaq 0x9e20(%rip), %rdi      # 0xc2e5
movl $0x100000, %edx         # imm = 0x100000
movb $0x0, %al
callq 0x10e0
jmp 0x271e
movq 0xc8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movl 0xa0(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x8(%rax)
movl 0xbc(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0xc(%rax)
movslq 0xbc(%rsp), %rdi
callq 0x1190
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x252b
jmp 0x254a
leaq 0x9dcf(%rip), %rdi      # 0xc301
leaq 0x9b2b(%rip), %rsi      # 0xc064
movl $0x26b, %edx            # imm = 0x26B
leaq 0x9d48(%rip), %rcx      # 0xc28d
callq 0x1100
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0xb0(%rsp), %rsi
movslq 0xbc(%rsp), %rdx
callq 0x1170
movq 0x10(%rsp), %rdx
movq 0xd0(%rsp), %rax
movq 0xd0(%rsp), %rsi
movl 0x1c(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x1c(%rsi)
movl %ecx, %ecx
movq %rdx, 0x28(%rax,%rcx,8)
leaq 0xec72(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x2657
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rax
movq %rax, %rdx
addq $0x2028, %rdx           # imm = 0x2028
movl 0xa0(%rsp), %r8d
movl 0x24(%rsp), %r9d
movl 0x18(%rax), %ecx
movl 0x1c(%rax), %edi
movl 0xbc(%rsp), %eax
movl %r8d, %r10d
addl %eax, %r10d
movq %rsp, %rax
movl %r10d, 0x8(%rax)
movl %edi, (%rax)
leaq 0x9d23(%rip), %rdi      # 0xc314
xorl %eax, %eax
callq 0x10e0
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xdba1(%rip), %rdx      # 0x101b0
shrq $0x14, %rdx
movaps 0x9a06(%rip), %xmm1     # 0xc020
movq 0xdb96(%rip), %xmm0     # 0x101b8
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x9a02(%rip), %xmm1     # 0xc030
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x99c3(%rip), %xmm1     # 0xc008
divsd %xmm1, %xmm0
leaq 0x9d09(%rip), %rdi      # 0xc359
movb $0x1, %al
callq 0x10e0
movq 0xd0(%rsp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x26c9
leaq 0xeb9c(%rip), %rax      # 0x11208
cmpl $0x0, (%rax)
je 0x26a5
movq 0xc8(%rsp), %rdi
callq 0x2730
movq %rax, %rsi
movq 0xd0(%rsp), %rdx
addq $0x2028, %rdx           # imm = 0x2028
movl 0xbc(%rsp), %ecx
leaq 0x9cde(%rip), %rdi      # 0xc37c
movb $0x0, %al
callq 0x10e0
movq 0xc0(%rsp), %rax
movl 0x4(%rax), %edi
callq 0x28b0
movl %eax, %ecx
addl 0xbc(%rsp), %ecx
movq 0xd0(%rsp), %rax
movl %ecx, 0x18(%rax)
jmp 0x26e2
movq 0xd0(%rsp), %rax
movl 0x2450(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2450(%rax)
jmp 0x26e4
movq 0xd0(%rsp), %rax
movl 0x2454(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2454(%rax)
movl $0x7, %edi
callq 0x1860
jmp 0x2707
movq 0xd0(%rsp), %rax
movl 0x2458(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2458(%rax)
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)