// File: /workspace/github_c_makefile_star2_O1/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, %r15
movl %esi, %ebp
movq %rdi, %r14
movl $0x410, %edi            # imm = 0x410
callq 0x11a0
movq %rax, %rbx
movl $0x410, %edx            # imm = 0x410
movq %rax, %rdi
xorl %esi, %esi
callq 0x1120
leaq 0xa988(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x38ad
leaq 0x583a(%rip), %rsi      # 0x90d2
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1220
movq %r12, %r14
leaq 0x6574(%rip), %rsi      # 0x9e28
movq %r14, %rdi
callq 0x874c
movq %rax, (%rbx)
testq %rax, %rax
je 0x3a36
movl %ebp, 0x408(%rbx)
movq %r15, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rsi
shrq $0x4, %rsi
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %r15, %rax
mulq %rcx
movq %rdx, %rcx
shrq $0x12, %rcx
movq %r15, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %rdi
shrq $0xb, %rdi
movq %r15, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r11
shrq $0xc, %r11
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %r15, %rax
mulq %rdx
movq %rdx, %r10
shrq $0x29, %r10
imulq $-0x3e8, %rsi, %r12     # imm = 0xFC18
addq %r15, %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 0xa850(%rip), %rax      # 0xe1d0
leal 0x1(%rax), %edx
shlq $0x7, %rax
leaq 0xa042(%rip), %r15      # 0xd9d0
addq %rax, %r15
andl $0xf, %edx
movl %edx, 0xa836(%rip)      # 0xe1d0
movabsq $0xaaaaaaaaaaaaaab, %rdx # imm = 0xAAAAAAAAAAAAAAB
movq %r10, %rax
mulq %rdx
shll $0x3, %edx
leaq (%rdx,%rdx,2), %rax
subq %rax, %r10
leaq 0x5b8c(%rip), %rsi      # 0x9547
movq %r15, %rdi
movq %r10, %rdx
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x1220
addq $0x10, %rsp
leaq 0x5c5c(%rip), %rdi      # 0x9633
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x10f0
leaq 0xa827(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x3a21
movabsq $0x40002a1b23c4d, %rax  # imm = 0x40002A1B23C4D
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movaps 0x5605(%rip), %xmm0     # 0x9010
movups %xmm0, 0x8(%rsi)
movq (%rbx), %rdi
movl $0x18, %edx
movl $0x1, %ecx
callq 0x87fe
movq %rbx, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x95bb(%rip), %rax      # 0xcff8
movq (%rax), %rdi
addq $0x8, %rbx
leaq 0x568f(%rip), %rsi      # 0x90da
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1160
xorl %ebx, %ebx
jmp 0x3a21