// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0xbc81(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x25e8
movq %r9, %r12
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
jne 0x25c5
leaq 0x2028(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x82e4
movq %rax, %rdi
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x3035
movl 0x8(%r12), %edx
addl $0x10, %edx
movq %r12, %rsi
movl $0x1, %ecx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x836e
movl %ecx, %ebp
movq %rsi, %r15
testl %ecx, %ecx
js 0x2b1a
movq %rdx, %r13
movq %r8, 0x30(%rsp)
movzwl 0xe(%rdx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
imull 0x2448(%rbx), %eax
movq %rax, 0x8(%rsp)
movl 0x4(%rdx), %r14d
movl 0x8(%rdx), %ecx
bswapl %r14d
movq %r15, 0x2430(%rbx)
movzwl 0xc(%rdx), %eax
movl %eax, %r12d
shrl $0x8, %r12d
btl $0x9, %eax
movq %rbp, 0x10(%rsp)
jae 0x298d
movq %rcx, 0x28(%rsp)
movq %r12, 0x18(%rsp)
leaq 0xbba8(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2765
movq %r15, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %r15, %rax
mulq %rdx
movq %rdx, %rsi
shrq $0x4, %rcx
movq %r15, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0x12, %rsi
movq %r15, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r10
shrq $0xb, %rdi
shrq $0xc, %r10
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r15, %rax
mulq %rdx
shrq $0x29, %rdx
imulq $-0x3e8, %rcx, %r11     # imm = 0xFC18
addq %r15, %r11
imulq $-0x3e8, %rsi, %rbp     # imm = 0xFC18
addq %rcx, %rbp
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rsi, %r9
imulq $-0x3c, %r10, %r8
addq %rdi, %r8
imulq $-0x3c, %rdx, %rcx
addq %r10, %rcx
movslq 0xb2b8(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %esi
shlq $0x7, %rax
leaq 0xaaaa(%rip), %r12      # 0xd1c0
addq %rax, %r12
andl $0xf, %esi
movl %esi, 0xb29e(%rip)      # 0xd9c0
imulq $0xaaaaaab, %rdx, %rax  # imm = 0xAAAAAAB
shrq $0x20, %rax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
leaq 0x6e0b(%rip), %rsi      # 0x9547
movq %r12, %rdi
xorl %eax, %eax
pushq %r11
pushq %rbp
callq 0x1230
addq $0x10, %rsp
leaq 0x2028(%rbx), %rdx
leaq 0x6a1e(%rip), %rdi      # 0x9179
movq %r12, %rsi
xorl %eax, %eax
callq 0x10f0
movq %r14, 0x20(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0x18(%rbx)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
orq %rdx, %rax
leaq 0xc62d(%rip), %rsi      # 0xedb0
movq %rax, 0x48(%rsi)
leaq 0x69fe(%rip), %rax      # 0x918c
leaq 0xc91b(%rip), %rcx      # 0xf0b0
movq %rax, 0x48(%rcx)
cmpl $0x0, 0x1c(%rbx)
je 0x2809
movq %r15, 0x40(%rsp)
movq 0xa9fd(%rip), %rax      # 0xd1a8
movq %rax, 0x38(%rsp)
movq 0xa9e9(%rip), %r15      # 0xd1a0
movq 0x10(%rsp), %rax
leal 0x18(%rax), %ebp
xorl %r14d, %r14d
subq %rbp, %r15
movq 0x28(%rbx,%r14,8), %r12
movq 0x10(%r12), %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
incq %r14
movl 0x1c(%rbx), %eax
cmpq %rax, %r14
jb 0x27c2
movq %r15, 0xa9b2(%rip)      # 0xd1a0
movq 0x38(%rsp), %rax
subq %r14, %rax
movq %rax, 0xa9ab(%rip)      # 0xd1a8
movq 0x40(%rsp), %r15
leaq 0xc5a7(%rip), %rsi      # 0xedb0
movl $0x0, 0x1c(%rbx)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
leaq 0xc791(%rip), %rcx      # 0xefb0
subq 0x48(%rsi), %rax
addq 0x48(%rcx), %rax
addq %rdx, %rax
movq %rax, 0x48(%rcx)
movzwl 0xc(%r13), %r12d
shrl $0x2, %r12d
andl $0x3f, %r12d
addl $-0x14, %r12d
je 0x291f
xorl %ebp, %ebp
movslq %ebp, %rax
movzbl 0x14(%r13,%rax), %ecx
cmpl $0x1, %ecx
je 0x2914
cmpl $0x2, %ecx
je 0x2867
testl %ecx, %ecx
jne 0x28a4
jmp 0x291f
cmpb $0x4, 0x15(%r13,%rax)
jne 0x28a4
movslq %ebp, %rbp
addq $0x2, %rbp
leaq 0xb97b(%rip), %rcx      # 0xe1f8
cmpl $0x0, (%rcx)
je 0x28a1
movzbl 0x14(%r13,%rbp), %ecx
shll $0x8, %ecx
movzbl 0x17(%r13,%rax), %esi
orl %ecx, %esi
leaq 0x6905(%rip), %rdi      # 0x919f
xorl %eax, %eax
callq 0x10f0
movq %rbp, %rax
movb 0x14(%r13,%rax), %cl
cmpb $0x3, %cl
jne 0x28ef
movslq %ebp, %r14
cmpb $0x3, 0x15(%r13,%r14)
jne 0x2914
movzbl 0x16(%r13,%rax), %ebp
leaq 0xb932(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x28db
leaq 0x68da(%rip), %rdi      # 0x91ac
movl %ebp, %esi
xorl %eax, %eax
callq 0x10f0
incq %r14
movl %ebp, 0x2448(%rbx)
movb 0x14(%r13,%r14), %cl
movq %r14, %rax
movl %r14d, %ebp
cmpb $0x4, %cl
jne 0x2914
cmpb $0x2, 0x15(%r13,%rax)
jne 0x2914
leaq 0xb8f5(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2914
leaq 0x6d19(%rip), %rdi      # 0x9628
callq 0x1090
incl %ebp
cmpl %r12d, %ebp
jb 0x2847
leaq 0xb8d6(%rip), %rax      # 0xe1fc
cmpl $0x0, (%rax)
movq 0x10(%rsp), %rbp
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r12
movq 0x28(%rsp), %rcx
je 0x298d
leaq 0x48(%rsp), %rsi
movq %r15, (%rsi)
movw $0x0, 0x8(%rsi)
movl 0x10(%rbx), %eax
movw %ax, 0xa(%rsi)
movq $0x0, 0xc(%rsi)
movl $0x0, 0x14(%rsi)
movzwl %r12w, %ecx
leal 0x8000(%rcx), %edx
movw %dx, 0x18(%rsi)
addl %r15d, %ecx
addl $0x8000, %ecx           # imm = 0x8000
addl %eax, %ecx
movw %cx, 0x1a(%rsi)
movq %rbx, %rdi
callq 0x2319
movq 0x28(%rsp), %rcx
bswapl %ecx
testl %ebp, %ebp
je 0x2c3a
movl %r14d, %ebp
subl 0x18(%rbx), %ebp
jne 0x2c9b
movq %rbx, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
movq %rcx, %rax
movq 0x30(%rsp), %rcx
movl %r12d, %r8d
movl %r14d, %r9d
pushq 0x8(%rsp)
pushq %rax
callq 0x2459
addq $0x10, %rsp
cmpl $0x0, 0x1c(%rbx)
je 0x30b9
leaq 0xb81d(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2b07
movq %r15, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %r15, %rax
mulq %rdx
movq %rdx, %rsi
shrq $0x4, %rcx
movq %r15, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0x12, %rsi
movq %r15, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r10
shrq $0xb, %rdi
shrq $0xc, %r10
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r15, %rax
mulq %rdx
shrq $0x29, %rdx
imulq $-0x3e8, %rcx, %r11     # imm = 0xFC18
addq %r15, %r11
movq %r14, %r13
movq %r12, %rbp
imulq $-0x3e8, %rsi, %r12     # imm = 0xFC18
addq %rcx, %r12
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rsi, %r9
imulq $-0x3c, %r10, %r8
addq %rdi, %r8
imulq $-0x3c, %rdx, %rcx
addq %r10, %rcx
movslq 0xaf27(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %esi
shlq $0x7, %rax
movq %r15, %r14
leaq 0xa716(%rip), %r15      # 0xd1c0
addq %rax, %r15
andl $0xf, %esi
movl %esi, 0xaf0a(%rip)      # 0xd9c0
imulq $0xaaaaaab, %rdx, %rax  # imm = 0xAAAAAAB
shrq $0x20, %rax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
leaq 0x6a77(%rip), %rsi      # 0x9547
movq %r15, %rdi
xorl %eax, %eax
pushq %r11
pushq %r12
movq %rbp, %r12
callq 0x1230
addq $0x10, %rsp
leaq 0x2028(%rbx), %rdx
movl 0x1c(%rbx), %r8d
leaq 0x66ca(%rip), %rdi      # 0x91c1
movq %r15, %rsi
movq %r14, %r15
movl %r13d, %ecx
xorl %eax, %eax
callq 0x10f0
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x3224
jmp 0x30b9
movq %r15, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %r15, %rax
mulq %rdx
movq %rdx, %rsi
shrq $0x4, %rcx
movq %r15, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0x12, %rsi
movq %r15, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r10
shrq $0xb, %rdi
shrq $0xc, %r10
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r15, %rax
mulq %rdx
shrq $0x29, %rdx
imulq $-0x3e8, %rcx, %r11     # imm = 0xFC18
addq %r15, %r11
imulq $-0x3e8, %rsi, %r12     # imm = 0xFC18
addq %rcx, %r12
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rsi, %r9
imulq $-0x3c, %r10, %r8
addq %rdi, %r8
imulq $-0x3c, %rdx, %rcx
addq %r10, %rcx
movslq 0xadf7(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %esi
shlq $0x7, %rax
leaq 0xa5e9(%rip), %r14      # 0xd1c0
addq %rax, %r14
andl $0xf, %esi
movl %esi, 0xaddd(%rip)      # 0xd9c0
imulq $0xaaaaaab, %rdx, %rax  # imm = 0xAAAAAAB
shrq $0x20, %rax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
leaq 0x694a(%rip), %rsi      # 0x9547
movq %r14, %rdi
xorl %eax, %eax
pushq %r11
pushq %r12
callq 0x1230
addq $0x10, %rsp
addq $0x2028, %rbx           # imm = 0x2028
leaq 0x652b(%rip), %rdi      # 0x9148
movq %r14, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10f0
leaq 0xb5bb(%rip), %rax      # 0xe1fc
cmpl $0x0, (%rax)
je 0x30b9
leaq 0x48(%rsp), %rsi
movq %r15, (%rsi)
movw $0x0, 0x8(%rsi)
movl 0x10(%rbx), %eax
movw %ax, 0xa(%rsi)
movl %r14d, 0xc(%rsi)
movl %ecx, 0x10(%rsi)
movq 0x8(%rsp), %rdx
movl %edx, 0x14(%rsi)
movw %r12w, 0x18(%rsi)
movq %rcx, %rdi
movzwl %r12w, %ecx
addl %r14d, %r15d
addl %edi, %r15d
addl %ecx, %r15d
addl %eax, %r15d
addl %edx, %r15d
movw %r15w, 0x1a(%rsi)
movq %rbx, %rdi
callq 0x2319
jmp 0x30b9
movq %r12, 0x18(%rsp)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
orq %rdx, %rax
leaq 0xc0fe(%rip), %rsi      # 0xedb0
movq %rax, 0x38(%rsi)
leaq 0x6528(%rip), %rax      # 0x91e5
leaq 0xc3ec(%rip), %rcx      # 0xf0b0
movq %rax, 0x38(%rcx)
movq 0x10(%rsp), %rax
leal (%r14,%rax), %edi
movl 0x18(%rbx), %r12d
movl %edi, %edx
subl %r12d, %edx
movq %r14, 0x20(%rsp)
cmpl %r12d, %r14d
setae %al
leal -0x1(%rdx), %ecx
cmpl $0x1fff, %ecx           # imm = 0x1FFF
setae %cl
orb %al, %cl
jne 0x2e88
movq %rdx, 0x8(%rsp)
leaq 0xb4f3(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2e31
movq %r15, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %r15, %rax
mulq %rdx
movq %rdx, %rsi
shrq $0x4, %rcx
movq %r15, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0x12, %rsi
movq %r15, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r10
shrq $0xb, %rdi
shrq $0xc, %r10
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r15, %rax
mulq %rdx
shrq $0x29, %rdx
imulq $-0x3e8, %rcx, %r11     # imm = 0xFC18
addq %r15, %r11
imulq $-0x3e8, %rsi, %r13     # imm = 0xFC18
addq %rcx, %r13
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rsi, %r9
imulq $-0x3c, %r10, %r8
addq %rdi, %r8
imulq $-0x3c, %rdx, %rcx
addq %r10, %rcx
movslq 0xac03(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %esi
shlq $0x7, %rax
leaq 0xa3f5(%rip), %r12      # 0xd1c0
addq %rax, %r12
andl $0xf, %esi
movl %esi, 0xabe9(%rip)      # 0xd9c0
imulq $0xaaaaaab, %rdx, %rax  # imm = 0xAAAAAAB
shrq $0x20, %rax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
leaq 0x6756(%rip), %rsi      # 0x9547
movq %r12, %rdi
xorl %eax, %eax
pushq %r11
pushq %r13
callq 0x1230
addq $0x10, %rsp
leaq 0x2028(%rbx), %rdx
movq 0x2440(%rbx), %r8
movq 0x8(%rsp), %rcx
movl %ecx, %r9d
addq %r8, %r9
leaq 0x63d1(%rip), %rdi      # 0x91f4
movq %r12, %rsi
xorl %eax, %eax
callq 0x10f0
movl 0x18(%rbx), %r12d
movl %r12d, %ebp
movq 0x20(%rsp), %r14
subl %r14d, %ebp
testl %ebp, %ebp
jle 0x3059
movl %ebp, %eax
movq 0x30(%rsp), %rcx
addq %rax, %rcx
movq 0x18(%rsp), %r14
leal 0x4000(%r14), %r8d
xorl %eax, %eax
movq %rbx, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
movl %r12d, %r9d
pushq %rax
pushq %rax
callq 0x2459
addq $0x10, %rsp
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x3224
jmp 0x308e
movl 0x1c(%rbx), %eax
cmpl 0x20(%rbx), %eax
jae 0x302d
movq %rax, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x1140
testq %rax, %rax
je 0x30e3
movq 0x10(%rsp), %rsi
movl %esi, %edi
leaq 0x18(%rdi), %rdx
addq %rdx, 0xa2d8(%rip)      # 0xd1a0
incq 0xa2d9(%rip)            # 0xd1a8
leaq 0xb312(%rip), %rcx      # 0xe1e8
addq %rdx, (%rcx)
leaq 0xb310(%rip), %rcx      # 0xe1f0
addq %rdx, (%rcx)
cmpl $0xfffff, %esi          # imm = 0xFFFFF
jg 0x30ce
movq %r15, (%rax)
movq 0x20(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %esi, 0xc(%rax)
movq %rdi, 0x28(%rsp)
movq %rax, %r14
callq 0x11b0
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x3102
movq %rax, %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x1190
movq 0x8(%rsp), %rcx
leal 0x1(%rcx), %eax
movl %eax, 0x1c(%rbx)
movq %r14, 0x28(%rbx,%rcx,8)
leaq 0xb2b8(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2fdb
movq %r15, %rdi
movq %rax, %r12
callq 0x3121
leaq 0x2028(%rbx), %rdx
movl 0x18(%rbx), %ecx
movl 0x1c(%rbx), %r10d
leaq 0x63a7(%rip), %rdi      # 0x9310
movq %rax, %rsi
movq 0x20(%rsp), %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq 0x18(%rsp)
pushq %r10
callq 0x10f0
addq $0x10, %rsp
movq %r15, %rdi
callq 0x3121
movq 0xa20c(%rip), %rdx      # 0xd1a0
movsd 0xa20c(%rip), %xmm1     # 0xd1a8
unpcklps 0x607d(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
shrq $0x14, %rdx
subpd 0x6081(%rip), %xmm1     # 0x9030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x607d(%rip), %xmm0     # 0x9040
leaq 0x638b(%rip), %rdi      # 0x9355
movq %rax, %rsi
movb $0x1, %al
callq 0x10f0
movq %r12, %rax
movl 0x18(%rbx), %r12d
testl %r12d, %r12d
leaq 0xbdcb(%rip), %rsi      # 0xedb0
jne 0x3095
cmpl $0x0, (%rax)
movq 0x10(%rsp), %r14
je 0x301f
movq %r15, %rdi
callq 0x3121
leaq 0x2028(%rbx), %rdx
leaq 0x636d(%rip), %rdi      # 0x9378
movq %rax, %rsi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x10f0
leaq 0xbd91(%rip), %rsi      # 0xedb0
movl 0x4(%r13), %eax
bswapl %eax
addl %r14d, %eax
movl %eax, 0x18(%rbx)
jmp 0x3095
incl 0x2450(%rbx)
jmp 0x3095
movq 0x9fbc(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x60e1(%rip), %rsi      # 0x9127
movq %r14, %rdx
xorl %eax, %eax
callq 0x1170
movq 0x8(%rbx), %rdi
jmp 0x25c5
movq %r15, %rdi
callq 0x3121
leaq 0x2028(%rbx), %rdx
movl 0x18(%rbx), %r8d
leaq 0x61b1(%rip), %rdi      # 0x9224
movq %rax, %rsi
movl %ebp, %ecx
movl %r14d, %r9d
xorl %eax, %eax
pushq 0x10(%rsp)
pushq 0x10(%rsp)
callq 0x10f0
addq $0x10, %rsp
leaq 0xbd1b(%rip), %rsi      # 0xedb0
incl 0x2454(%rbx)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
leaq 0xbf06(%rip), %rcx      # 0xefb0
subq 0x38(%rsi), %rax
addq 0x38(%rcx), %rax
addq %rdx, %rax
movq %rax, 0x38(%rcx)
incl 0x2458(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x620c(%rip), %rdi      # 0x92e1
movl $0x100000, %edx         # imm = 0x100000
xorl %eax, %eax
callq 0x10f0
jmp 0x30bf
leaq 0x6195(%rip), %rdi      # 0x927f
leaq 0x5f7b(%rip), %rsi      # 0x906c
leaq 0x6191(%rip), %rcx      # 0x9289
movl $0x257, %edx            # imm = 0x257
callq 0x1110
leaq 0x61f4(%rip), %rdi      # 0x92fd
leaq 0x5f5c(%rip), %rsi      # 0x906c
leaq 0x6172(%rip), %rcx      # 0x9289
movl $0x26b, %edx            # imm = 0x26B
callq 0x1110