// File: /workspace/github_c_makefile_star2_O1/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 0xbc48(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x2620
movq %r9, %r12
cmpq $0x0, 0x8(%rbx)
jne 0x25f9
leaq 0x2028(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x874c
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x309a
movq 0x8(%rbx), %rdi
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 0x87fe
movl %ecx, %r15d
movq %rsi, %r14
testl %ecx, %ecx
js 0x2b59
movq %rdx, %r13
movzwl 0xe(%rdx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
imull 0x2448(%rbx), %eax
movq %rax, 0x30(%rsp)
movl 0x4(%rdx), %r12d
movl 0x8(%rdx), %eax
movq %rax, 0x28(%rsp)
bswapl %r12d
movq %r14, 0x2430(%rbx)
movzwl 0xc(%rdx), %eax
movl %eax, %ecx
shrl $0x8, %ecx
movq %rcx, 0x8(%rsp)
btl $0x9, %eax
movq %r8, 0x20(%rsp)
jae 0x29c7
movq %r15, 0x10(%rsp)
leaq 0xbb71(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
movq %r12, 0x18(%rsp)
je 0x27b3
movq %r14, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rsi
shrq $0x4, %rsi
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r14, %rax
mulq %rcx
movq %rdx, %rcx
shrq $0x12, %rcx
movq %r14, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0xb, %rdi
movq %r14, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r11
shrq $0xc, %r11
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r14, %rax
mulq %rdx
movq %rdx, %r10
shrq $0x29, %r10
imulq $-0x3e8, %rsi, %r15     # imm = 0xFC18
addq %r14, %r15
imulq $-0x3e8, %rcx, %rbp     # imm = 0xFC18
addq %rsi, %rbp
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rcx, %r9
imulq $-0x3c, %r11, %r8
addq %rdi, %r8
imulq $-0x3c, %r10, %rcx
addq %r11, %rcx
movslq 0xb279(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %edx
shlq $0x7, %rax
leaq 0xaa6b(%rip), %r12      # 0xd1c0
addq %rax, %r12
andl $0xf, %edx
movl %edx, 0xb25f(%rip)      # 0xd9c0
movabsq $0xaaaaaaaaaaaaaab, %rdx # imm = 0xAAAAAAAAAAAAAAB
movq %r10, %rax
mulq %rdx
shll $0x3, %edx
leaq (%rdx,%rdx,2), %rax
subq %rax, %r10
leaq 0x6dc5(%rip), %rsi      # 0x9547
movq %r12, %rdi
movq %r10, %rdx
xorl %eax, %eax
pushq %r15
pushq %rbp
callq 0x1220
addq $0x10, %rsp
leaq 0x2028(%rbx), %rdx
leaq 0x69d5(%rip), %rdi      # 0x9179
movq %r12, %rsi
movq 0x18(%rsp), %r12
xorl %eax, %eax
callq 0x10f0
leal 0x1(%r12), %eax
movl %eax, 0x18(%rbx)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
orq %rdx, %rax
leaq 0xc5e3(%rip), %rsi      # 0xedb0
movq %rax, 0x48(%rsi)
leaq 0x69b4(%rip), %rax      # 0x918c
leaq 0xc8d1(%rip), %rcx      # 0xf0b0
movq %rax, 0x48(%rcx)
cmpl $0x0, 0x1c(%rbx)
je 0x285c
movq %r14, 0x40(%rsp)
movq 0xa9b3(%rip), %rax      # 0xd1a8
movq %rax, 0x38(%rsp)
movq 0xa99f(%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 $0x0, 0x10(%r12)
movq %r12, %rdi
callq 0x1030
incq %r14
movl 0x1c(%rbx), %eax
cmpq %rax, %r14
jb 0x280c
movq %r15, 0xa95f(%rip)      # 0xd1a0
movq 0x38(%rsp), %rax
subq %r14, %rax
movq %rax, 0xa958(%rip)      # 0xd1a8
movq 0x40(%rsp), %r14
leaq 0xc554(%rip), %rsi      # 0xedb0
movl $0x0, 0x1c(%rbx)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
leaq 0xc73e(%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 0x2967
xorl %r15d, %r15d
movslq %r15d, %rax
movzbl 0x14(%r13,%rax), %ecx
cmpl $0x1, %ecx
je 0x295b
cmpl $0x2, %ecx
je 0x28bb
testl %ecx, %ecx
jne 0x28f2
jmp 0x2967
cmpb $0x4, 0x15(%r13,%rax)
jne 0x28f2
leaq 0x2(%rax), %r15
leaq 0xb92a(%rip), %rcx      # 0xe1f8
cmpl $0x0, (%rcx)
je 0x28f2
movzbl 0x14(%r13,%r15), %ecx
shll $0x8, %ecx
movzbl 0x17(%r13,%rax), %esi
orl %ecx, %esi
leaq 0x68b4(%rip), %rdi      # 0x919f
xorl %eax, %eax
callq 0x10f0
movslq %r15d, %rax
cmpb $0x3, 0x14(%r13,%rax)
jne 0x2930
cmpb $0x3, 0x15(%r13,%rax)
jne 0x2930
movzbl 0x16(%r13,%rax), %ebp
leaq 0xb8e6(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2927
leaq 0x688e(%rip), %rdi      # 0x91ac
movl %ebp, %esi
xorl %eax, %eax
callq 0x10f0
incl %r15d
movl %ebp, 0x2448(%rbx)
movslq %r15d, %rax
cmpb $0x4, 0x14(%r13,%rax)
jne 0x295b
cmpb $0x2, 0x15(%r13,%rax)
jne 0x295b
leaq 0xb8ae(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x295b
leaq 0x6cd2(%rip), %rdi      # 0x9628
callq 0x1090
incl %r15d
cmpl %r12d, %r15d
jb 0x289b
leaq 0xb88e(%rip), %rax      # 0xe1fc
cmpl $0x0, (%rax)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
je 0x29c7
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movw $0x0, 0x8(%rsi)
movl 0x10(%rbx), %eax
movw %ax, 0xa(%rsi)
movq $0x0, 0xc(%rsi)
movl $0x0, 0x14(%rsi)
movzwl 0x8(%rsp), %ecx
leal 0x8000(%rcx), %edx
movw %dx, 0x18(%rsi)
addl %r14d, %ecx
addl $0x8000, %ecx           # imm = 0x8000
addl %eax, %ecx
movw %cx, 0x1a(%rsi)
movq %rbx, %rdi
callq 0x2352
movq 0x28(%rsp), %rax
bswapl %eax
testl %r15d, %r15d
je 0x2c8a
movl %r12d, %ebp
subl 0x18(%rbx), %ebp
jne 0x2cf1
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq 0x20(%rsp), %rcx
movq 0x8(%rsp), %r8
movl %r12d, %r9d
pushq 0x30(%rsp)
pushq %rax
callq 0x2492
addq $0x10, %rsp
cmpl $0x0, 0x1c(%rbx)
je 0x3118
leaq 0xb7e0(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2b44
movq %r14, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rsi
shrq $0x4, %rsi
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r14, %rax
mulq %rcx
movq %rdx, %rcx
shrq $0x12, %rcx
movq %r14, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0xb, %rdi
movq %r14, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r11
shrq $0xc, %r11
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r14, %rax
mulq %rdx
movq %rdx, %r10
shrq $0x29, %r10
movq %r12, %rbp
imulq $-0x3e8, %rsi, %r12     # imm = 0xFC18
addq %r14, %r12
imulq $-0x3e8, %rcx, %r13     # imm = 0xFC18
addq %rsi, %r13
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rcx, %r9
imulq $-0x3c, %r11, %r8
addq %rdi, %r8
imulq $-0x3c, %r10, %rcx
addq %r11, %rcx
movslq 0xaeea(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %edx
shlq $0x7, %rax
leaq 0xa6dc(%rip), %r15      # 0xd1c0
addq %rax, %r15
andl $0xf, %edx
movl %edx, 0xaed0(%rip)      # 0xd9c0
movabsq $0xaaaaaaaaaaaaaab, %rdx # imm = 0xAAAAAAAAAAAAAAB
movq %r10, %rax
mulq %rdx
shll $0x3, %edx
leaq (%rdx,%rdx,2), %rax
subq %rax, %r10
leaq 0x6a36(%rip), %rsi      # 0x9547
movq %r15, %rdi
movq %r10, %rdx
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x1220
addq $0x10, %rsp
leaq 0x2028(%rbx), %rdx
movl 0x1c(%rbx), %r8d
leaq 0x6689(%rip), %rdi      # 0x91c1
movq %r15, %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x10f0
movq %rbx, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
callq 0x32a3
jmp 0x3118
movq %r14, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rsi
shrq $0x4, %rsi
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r14, %rax
mulq %rcx
movq %rdx, %rcx
shrq $0x12, %rcx
movq %r14, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0xb, %rdi
movq %r14, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r11
shrq $0xc, %r11
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r14, %rax
mulq %rdx
movq %rdx, %r10
shrq $0x29, %r10
movq %r15, %r13
imulq $-0x3e8, %rsi, %r15     # imm = 0xFC18
addq %r14, %r15
imulq $-0x3e8, %rcx, %r12     # imm = 0xFC18
addq %rsi, %r12
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rcx, %r9
imulq $-0x3c, %r11, %r8
addq %rdi, %r8
imulq $-0x3c, %r10, %rcx
addq %r11, %rcx
movslq 0xadb2(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %edx
shlq $0x7, %rax
leaq 0xa5a4(%rip), %r14      # 0xd1c0
addq %rax, %r14
andl $0xf, %edx
movl %edx, 0xad98(%rip)      # 0xd9c0
movabsq $0xaaaaaaaaaaaaaab, %rdx # imm = 0xAAAAAAAAAAAAAAB
movq %r10, %rax
mulq %rdx
shll $0x3, %edx
leaq (%rdx,%rdx,2), %rax
subq %rax, %r10
leaq 0x68fe(%rip), %rsi      # 0x9547
movq %r14, %rdi
movq %r10, %rdx
xorl %eax, %eax
pushq %r15
pushq %r12
callq 0x1220
addq $0x10, %rsp
addq $0x2028, %rbx           # imm = 0x2028
leaq 0x64dc(%rip), %rdi      # 0x9148
movq %r14, %rsi
movq %rbx, %rdx
movl %r13d, %ecx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10f0
movq %rax, %rcx
leaq 0xb568(%rip), %rax      # 0xe1fc
cmpl $0x0, (%rax)
je 0x3118
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movw $0x0, 0x8(%rsi)
movl 0x10(%rbx), %eax
movw %ax, 0xa(%rsi)
movl %r12d, 0xc(%rsi)
movq %rcx, %rdi
movl %edi, 0x10(%rsi)
movq 0x30(%rsp), %rdx
movl %edx, 0x14(%rsi)
movq 0x8(%rsp), %rcx
movw %cx, 0x18(%rsi)
movzwl %cx, %ecx
addl %r12d, %r14d
addl %edi, %r14d
addl %ecx, %r14d
addl %eax, %r14d
addl %edx, %r14d
movw %r14w, 0x1a(%rsi)
movq %rbx, %rdi
callq 0x2352
jmp 0x3118
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
orq %rdx, %rax
leaq 0xc0ad(%rip), %rsi      # 0xedb0
movq %rax, 0x38(%rsi)
leaq 0x64d7(%rip), %rax      # 0x91e5
leaq 0xc39b(%rip), %rcx      # 0xf0b0
movq %rax, 0x38(%rcx)
movq %r15, 0x10(%rsp)
leal (%r12,%r15), %edx
movl 0x18(%rbx), %eax
movq %r12, %rcx
movl %edx, %r12d
subl %eax, %r12d
movq %rcx, 0x18(%rsp)
cmpl %eax, %ecx
setae %al
leal -0x1(%r12), %ecx
cmpl $0x1fff, %ecx           # imm = 0x1FFF
setae %cl
orb %al, %cl
jne 0x2edd
leaq 0xb4a3(%rip), %rax      # 0xe1f8
cmpl $0x0, (%rax)
je 0x2e87
movq %r14, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rsi
shrq $0x4, %rsi
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r14, %rax
mulq %rcx
movq %rdx, %rcx
shrq $0x12, %rcx
movq %r14, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0xb, %rdi
movq %r14, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r11
shrq $0xc, %r11
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r14, %rax
mulq %rdx
movq %rdx, %r10
shrq $0x29, %r10
imulq $-0x3e8, %rsi, %r15     # imm = 0xFC18
addq %r14, %r15
imulq $-0x3e8, %rcx, %rbp     # imm = 0xFC18
addq %rsi, %rbp
imulq $-0x3e8, %rdi, %r9      # imm = 0xFC18
addq %rcx, %r9
imulq $-0x3c, %r11, %r8
addq %rdi, %r8
imulq $-0x3c, %r10, %rcx
addq %r11, %rcx
movslq 0xabb0(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %edx
shlq $0x7, %rax
leaq 0xa3a2(%rip), %r13      # 0xd1c0
addq %rax, %r13
andl $0xf, %edx
movl %edx, 0xab96(%rip)      # 0xd9c0
movabsq $0xaaaaaaaaaaaaaab, %rdx # imm = 0xAAAAAAAAAAAAAAB
movq %r10, %rax
mulq %rdx
shll $0x3, %edx
leaq (%rdx,%rdx,2), %rax
subq %rax, %r10
leaq 0x66fc(%rip), %rsi      # 0x9547
movq %r13, %rdi
movq %r10, %rdx
xorl %eax, %eax
pushq %r15
pushq %rbp
callq 0x1220
addq $0x10, %rsp
leaq 0x2028(%rbx), %rdx
movq 0x2440(%rbx), %r8
movl %r12d, %r9d
addq %r8, %r9
leaq 0x637a(%rip), %rdi      # 0x91f4
movq %r13, %rsi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x10f0
movl 0x18(%rbx), %r9d
movl %r9d, %ebp
movq 0x18(%rsp), %r15
subl %r15d, %ebp
testl %ebp, %ebp
jle 0x30ba
movl %ebp, %eax
movq 0x20(%rsp), %rcx
addq %rax, %rcx
movq 0x8(%rsp), %r15
leal 0x4000(%r15), %r8d
xorl %eax, %eax
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
pushq %rax
pushq %rax
callq 0x2492
addq $0x10, %rsp
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x32a3
jmp 0x30ed
movl 0x1c(%rbx), %eax
cmpl 0x20(%rbx), %eax
jae 0x3092
movq %rax, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
movl $0x18, %edi
callq 0x11a0
testq %rax, %rax
je 0x3155
movq %rax, %r12
movq 0x10(%rsp), %r15
movl %r15d, %edi
leaq 0x18(%rdi), %rax
addq %rax, 0xa284(%rip)      # 0xd1a0
incq 0xa285(%rip)            # 0xd1a8
leaq 0xb2be(%rip), %rcx      # 0xe1e8
addq %rax, (%rcx)
leaq 0xb2bc(%rip), %rcx      # 0xe1f0
addq %rax, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r12)
movq $0x0, 0x10(%r12)
cmpl $0x100000, %r15d        # imm = 0x100000
jge 0x312d
movq %r14, (%r12)
movq 0x18(%rsp), %rax
movl %eax, 0x8(%r12)
movl %r15d, 0xc(%r12)
movq %rdi, %r15
callq 0x11a0
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x3174
movq %rax, %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x1180
movq 0x8(%rsp), %rcx
leal 0x1(%rcx), %eax
movl %eax, 0x1c(%rbx)
movq %r12, 0x28(%rbx,%rcx,8)
leaq 0xb251(%rip), %r12      # 0xe1f8
cmpl $0x0, (%r12)
je 0x303a
movq %r14, %rdi
callq 0x3193
leaq 0x2028(%rbx), %rdx
movl 0x18(%rbx), %ecx
movl 0x1c(%rbx), %r10d
leaq 0x6341(%rip), %rdi      # 0x9310
movq %rax, %rsi
movq 0x18(%rsp), %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq 0x28(%rsp)
pushq %r10
callq 0x10f0
addq $0x10, %rsp
movq %r14, %rdi
callq 0x3193
movq 0xa1a6(%rip), %rdx      # 0xd1a0
movsd 0xa1a6(%rip), %xmm1     # 0xd1a8
unpcklps 0x6017(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
shrq $0x14, %rdx
subpd 0x601b(%rip), %xmm1     # 0x9030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x6017(%rip), %xmm0     # 0x9040
leaq 0x6325(%rip), %rdi      # 0x9355
movq %rax, %rsi
movb $0x1, %al
callq 0x10f0
cmpl $0x0, 0x18(%rbx)
movq 0x10(%rsp), %r15
leaq 0xbd66(%rip), %rsi      # 0xedb0
jne 0x314a
cmpl $0x0, (%r12)
je 0x3081
movq %r14, %rdi
callq 0x3193
leaq 0x2028(%rbx), %rdx
leaq 0x630b(%rip), %rdi      # 0x9378
movq %rax, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x10f0
leaq 0xbd2f(%rip), %rsi      # 0xedb0
movl 0x4(%r13), %eax
bswapl %eax
addl %r15d, %eax
movl %eax, 0x18(%rbx)
jmp 0x314a
incl 0x2450(%rbx)
jmp 0x30f4
movq 0x9f57(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x607c(%rip), %rsi      # 0x9127
movq %r14, %rdx
xorl %eax, %eax
callq 0x1160
jmp 0x25f9
movq %r14, %rdi
callq 0x3193
leaq 0x2028(%rbx), %rdx
movl 0x18(%rbx), %r8d
leaq 0x6150(%rip), %rdi      # 0x9224
movq %rax, %rsi
movl %ebp, %ecx
movl %r15d, %r9d
xorl %eax, %eax
pushq 0x10(%rsp)
pushq %r12
callq 0x10f0
addq $0x10, %rsp
leaq 0xbcbc(%rip), %rsi      # 0xedb0
incl 0x2454(%rbx)
rdtsc
shlq $0x20, %rdx
movl %eax, %eax
leaq 0xbea7(%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 0x61ad(%rip), %rdi      # 0x92e1
movl %r15d, %esi
movl $0x100000, %edx         # imm = 0x100000
xorl %eax, %eax
callq 0x10f0
leaq 0xbc66(%rip), %rsi      # 0xedb0
cmpl $0x100000, %r15d        # imm = 0x100000
jge 0x311e
jmp 0x30f4
leaq 0x6123(%rip), %rdi      # 0x927f
leaq 0x5f09(%rip), %rsi      # 0x906c
leaq 0x611f(%rip), %rcx      # 0x9289
movl $0x257, %edx            # imm = 0x257
callq 0x1110
leaq 0x6182(%rip), %rdi      # 0x92fd
leaq 0x5eea(%rip), %rsi      # 0x906c
leaq 0x6100(%rip), %rcx      # 0x9289
movl $0x26b, %edx            # imm = 0x26B
callq 0x1110