// File: /workspace/github_c_makefile_star2_O0/fmadio[P]pcap_flow/tcpstream.c
// Function: fTCPStream_OutputPayload
void fTCPStream_OutputPayload(TCPStream_t* S, u64 TS, u32 Length, u8* Payload, u32 Flag, u32 SeqNo, u32 AckNo, u32 WindowSize)
{

	// ensure file is open 
	fTCPStream_Open(S);	

	fProfile_Start(12, "TCP PktAdd OutputPayload");
	S->SeqNo += Length;

	int rlen;
	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;

		//rlen = write(S->fd, &Header, sizeof(Header));
		//rlen = fwrite(&Header, sizeof(Header), 1, S->File);
		fFile_Write(S->File, &Header, sizeof(TCPOutputHeader_t), false);

		S->WritePos += sizeof(TCPOutputHeader_t);
	}

	/*
	if (S->IsTrace)
	{
		for (int i=0; i < Length; i++)
		{
			if (i % 16 == 0) printf("\n");
			printf("%02x ", Payload[i]);
		}
		printf("\n");
	}
	*/


	//rlen = write(S->fd, Payload, Length);
	//rlen = fwrite(Payload, Length, 1, S->File);
	fFile_Write(S->File, Payload, Length, true);

	S->WritePos += Length; 

	S->LastTSC = rdtsc();

	// total TCP bytes output
	s_TotalByte += Length;
	s_TotalPkt	+= 1;

	fProfile_Stop(12);
}

// Assembly:
subq $0x58, %rsp
movl 0x68(%rsp), %eax
movl 0x60(%rsp), %eax
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movq %rcx, 0x38(%rsp)
movl %r8d, 0x34(%rsp)
movl %r9d, 0x30(%rsp)
movq 0x50(%rsp), %rdi
callq 0x1700
movl $0xc, %edi
leaq 0xa827(%rip), %rsi      # 0xc106
callq 0x17f0
movl 0x44(%rsp), %ecx
movq 0x50(%rsp), %rax
addl 0x18(%rax), %ecx
movl %ecx, 0x18(%rax)
leaq 0xf912(%rip), %rax      # 0x1120c
cmpl $0x0, (%rax)
je 0x19f1
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x44(%rsp), %eax
movw %ax, 0x10(%rsp)
movq 0x50(%rsp), %rax
movl 0x10(%rax), %eax
movw %ax, 0x12(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x34(%rsp), %eax
movw %ax, 0x20(%rsp)
movw $0x0, 0x22(%rsp)
movq 0x8(%rsp), %rcx
movzwl 0x22(%rsp), %eax
addq %rcx, %rax
movw %ax, 0x22(%rsp)
movzwl 0x10(%rsp), %ecx
movzwl 0x22(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x22(%rsp)
movzwl 0x12(%rsp), %ecx
movzwl 0x22(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x22(%rsp)
movl 0x14(%rsp), %ecx
movzwl 0x22(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x22(%rsp)
movl 0x18(%rsp), %ecx
movzwl 0x22(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x22(%rsp)
movl 0x1c(%rsp), %ecx
movzwl 0x22(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x22(%rsp)
movzwl 0x20(%rsp), %ecx
movzwl 0x22(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x22(%rsp)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x8(%rsp), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq 0xb900
movq 0x50(%rsp), %rax
movq 0x2440(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x2440(%rax)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x38(%rsp), %rsi
movl 0x44(%rsp), %edx
movl $0x1, %ecx
callq 0xb900
movl 0x44(%rsp), %eax
movl %eax, %ecx
movq 0x50(%rsp), %rax
addq 0x2440(%rax), %rcx
movq %rcx, 0x2440(%rax)
callq 0x1840
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x2428(%rax)
movl 0x44(%rsp), %eax
addq 0xe75b(%rip), %rax      # 0x101a0
movq %rax, 0xe754(%rip)      # 0x101a0
movq 0xe755(%rip), %rax      # 0x101a8
addq $0x1, %rax
movq %rax, 0xe74a(%rip)      # 0x101a8
movl $0xc, %edi
callq 0x1860
addq $0x58, %rsp
retq
nopl (%rax)