// File: /workspace/github_c_makefile_star2_O2/fmadio[P]pcap_flow/udpstream.c
// Function: fUDPStream_Init
UDPStream_t* fUDPStream_Init(char* FileName, u32 FlowID, u64 TS)
{
	UDPStream_t* Stream = malloc(sizeof(UDPStream_t));
	memset(Stream, 0, sizeof(UDPStream_t));

	// append .pcap
	u8 FilenamePCAP[2048];
	if (g_OutputPCAP)
	{
		sprintf(FilenamePCAP, "%s.pcap", FileName);
		FileName = FilenamePCAP;
	}

	Stream->F = fFile_Open(FileName, "w");
	if (!Stream->F)
	{
		fprintf(stderr, "failed to create file [%s]\n", Stream->FileName);
		return 0;
	}
	Stream->FlowID = FlowID;
	printf("[%s] FlowID:%i UDP Stream: [%s]\n", FormatTS(TS), FlowID, FileName);

	// if PCAP then write pcap header
	if (g_OutputPCAP)
	{
		PCAPHeader_t Header;
		Header.Magic 	= PCAPHEADER_MAGIC_NANO;
		Header.Major 	= PCAPHEADER_MAJOR;
		Header.Minor 	= PCAPHEADER_MINOR;
		Header.TimeZone = 0;
		Header.SigFlag 	= 0;
		Header.SnapLen 	= 0;
		Header.Link		= PCAPHEADER_LINK_ETHERNET;

		fFile_Write(Stream->F, &Header, sizeof(Header), true);
	}

	return Stream;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x828, %rsp            # imm = 0x828
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r14
pushq $0x1
popq %rdi
movl $0x410, %esi            # imm = 0x410
callq 0x1140
movq %rax, %rbx
leaq 0xad40(%rip), %rax      # 0xd214
cmpl $0x0, (%rax)
je 0x24f5
leaq 0x5bf2(%rip), %rsi      # 0x80d2
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1230
movq %r15, %r14
leaq 0x693c(%rip), %rsi      # 0x8e38
movq %r14, %rdi
callq 0x6e34
movq %rax, (%rbx)
testq %rax, %rax
je 0x263d
movq %rax, %r15
movl %ebp, 0x408(%rbx)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movl $0xf4240, %esi          # imm = 0xF4240
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %rsi
movl $0x3b9aca00, %edi       # imm = 0x3B9ACA00
movq %r12, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rdi
movabsq $0xdf8475800, %r8       # imm = 0xDF8475800
movq %r12, %rax
xorl %edx, %edx
divq %r8
movq %rax, %r10
movabsq $0x34630b8a000, %r8     # imm = 0x34630B8A000
movq %r12, %rax
xorl %edx, %edx
divq %r8
imulq $-0x3e8, %rcx, %r11     # imm = 0xFC18
addq %r12, %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, %rax, %rcx
addq %r10, %rcx
movslq 0xac2d(%rip), %rdx      # 0xd1d0
leal 0x1(%rdx), %esi
shlq $0x7, %rdx
leaq 0xa41f(%rip), %r12      # 0xc9d0
addq %rdx, %r12
andl $0xf, %esi
movl %esi, 0xac13(%rip)      # 0xd1d0
pushq $0x18
popq %rsi
xorl %edx, %edx
divl %esi
leaq 0x5f7c(%rip), %rsi      # 0x8547
movq %r12, %rdi
xorl %eax, %eax
pushq %r11
pushq %r13
callq 0x1230
popq %rcx
popq %rdx
leaq 0x6051(%rip), %rdi      # 0x8633
movq %r12, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x10f0
leaq 0xac1c(%rip), %rax      # 0xd214
cmpl $0x0, (%rax)
je 0x2628
movabsq $0x40002a1b23c4d, %rax  # imm = 0x40002A1B23C4D
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movaps 0x59fa(%rip), %xmm0     # 0x8010
movups %xmm0, 0x8(%rsi)
pushq $0x18
popq %rdx
pushq $0x1
popq %rcx
movq %r15, %rdi
callq 0x6ec0
movq %rbx, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x99b4(%rip), %rax      # 0xbff8
movq (%rax), %rdi
addq $0x8, %rbx
leaq 0x5a88(%rip), %rsi      # 0x80da
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1170
xorl %ebx, %ebx
jmp 0x2628