// File: /workspace/github_c_makefile_star2_O3/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
movl $0x1, %edi
movl $0x410, %esi            # imm = 0x410
callq 0x1140
movq %rax, %rbx
leaq 0xaa62(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x37d3
leaq 0x5914(%rip), %rsi      # 0x90d2
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1230
movq %r15, %r14
leaq 0x664e(%rip), %rsi      # 0x9e28
movq %r14, %rdi
callq 0x82e4
movq %rax, (%rbx)
testq %rax, %rax
je 0x3952
movq %rax, %r15
movl %ebp, 0x408(%rbx)
movq %r12, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %r12, %rax
mulq %rdx
movq %rdx, %rsi
shrq $0x4, %rcx
movq %r12, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0x12, %rsi
movq %r12, %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 %r12, %rax
mulq %rdx
shrq $0x29, %rdx
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, %rdx, %rcx
addq %r10, %rcx
movslq 0xa92a(%rip), %rax      # 0xe1d0
leal 0x1(%rax), %esi
shlq $0x7, %rax
leaq 0xa11c(%rip), %r12      # 0xd9d0
addq %rax, %r12
andl $0xf, %esi
movl %esi, 0xa910(%rip)      # 0xe1d0
imulq $0xaaaaaab, %rdx, %rax  # imm = 0xAAAAAAB
shrq $0x20, %rax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
leaq 0x5c6d(%rip), %rsi      # 0x9547
movq %r12, %rdi
xorl %eax, %eax
pushq %r11
pushq %r13
callq 0x1230
addq $0x10, %rsp
leaq 0x5d40(%rip), %rdi      # 0x9633
movq %r12, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x10f0
leaq 0xa90b(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x393d
movabsq $0x40002a1b23c4d, %rax  # imm = 0x40002A1B23C4D
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movaps 0x56e9(%rip), %xmm0     # 0x9010
movups %xmm0, 0x8(%rsi)
movq %r15, %rdi
movl $0x18, %edx
movl $0x1, %ecx
callq 0x836e
movq %rbx, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x969f(%rip), %rax      # 0xcff8
movq (%rax), %rdi
addq $0x8, %rbx
leaq 0x5773(%rip), %rsi      # 0x90da
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1170
xorl %ebx, %ebx
jmp 0x393d