// File: /workspace/github_c_makefile_star2_O0/fmadio[P]pcap_flow/main.c
// Function: OpenPCAP
static PCAPFile_t* OpenPCAP(char* Path, bool EnableStdin)
{
	PCAPFile_t* F = (PCAPFile_t*)malloc( sizeof(PCAPFile_t) );
	assert(F != NULL);
	memset(F, 0, sizeof(PCAPFile_t));
	F->Path		= Path;

	if (!EnableStdin)
	{
		F->F = fopen(Path, "r");
		if (F->F == NULL)
		{
			fprintf(stderr, "failed to open buffered file [%s]\n", Path);
			return NULL;
		}

		struct stat fstat;	
		if (stat(Path, &fstat) < 0)
		{
			fprintf(stderr, "failed to get file size [%s]\n", Path);
			return NULL;
		}
		F->Length 	= fstat.st_size;
	}
	else
	{
		F->F 		= stdin;
		F->Length 	= 1e15;		// 1PB limit
	}

	// note always map as read-only 
	PCAPHeader_t Header1;
	PCAPHeader_t* Header = NULL; 
	{
		int ret = fread(&Header1, 1, sizeof(Header1), F->F);
		if (ret != sizeof(PCAPHeader_t))
		{
			fprintf(stderr, "failed to read header %i\n", ret);
			return NULL;
		}

		Header = &Header1;
		F->PacketBuffer	= malloc(32*1024);
		assert(F->PacketBuffer != NULL);
	}

	switch (Header->Magic)
	{
	case PCAPHEADER_MAGIC_USEC: fprintf(stderr, "USec PACP\n"); s_PCAPTimeScale = 1000; break;
	case PCAPHEADER_MAGIC_NANO: fprintf(stderr, "Nano PACP\n"); s_PCAPTimeScale = 1; break;
	default:
		fprintf(stderr, "invalid pcap header %08x\n", Header->Magic);
		return NULL;
	}
	F->ReadPos +=  sizeof(PCAPHeader_t);

	return F;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movl %esi, 0xc4(%rsp)
movl $0xd8, %edi
callq 0x1190
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
je 0x74d5
jmp 0x74f4
leaq 0x633e(%rip), %rdi      # 0xd81a
leaq 0x53ef(%rip), %rsi      # 0xc8d2
movl $0xc4, %edx
leaq 0x6335(%rip), %rcx      # 0xd824
callq 0x1100
movq 0xb8(%rsp), %rdi
xorl %esi, %esi
movl $0xd8, %edx
callq 0x1110
movq 0xc8(%rsp), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, (%rax)
cmpl $0x0, 0xc4(%rsp)
jne 0x75f0
movq 0xc8(%rsp), %rdi
leaq 0x4bcc(%rip), %rsi      # 0xc104
callq 0x11e0
movq %rax, %rcx
movq 0xb8(%rsp), %rax
movq %rcx, 0x88(%rax)
movq 0xb8(%rsp), %rax
cmpq $0x0, 0x88(%rax)
jne 0x7592
movq 0x8a90(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0xc8(%rsp), %rdx
leaq 0x62cd(%rip), %rsi      # 0xd847
movb $0x0, %al
callq 0x1150
movq $0x0, 0xd0(%rsp)
jmp 0x77a3
movq 0xc8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1160
cmpl $0x0, %eax
jge 0x75da
movq 0x8a48(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0xc8(%rsp), %rdx
leaq 0x62a8(%rip), %rsi      # 0xd86a
movb $0x0, %al
callq 0x1150
movq $0x0, 0xd0(%rsp)
jmp 0x77a3
movq 0x58(%rsp), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, 0x98(%rax)
jmp 0x7622
movq 0x89e1(%rip), %rax      # 0xffd8
movq (%rax), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, 0x88(%rax)
movq 0xb8(%rsp), %rax
movabsq $0x38d7ea4c68000, %rcx  # imm = 0x38D7EA4C68000
movq %rcx, 0x98(%rax)
movq $0x0, 0x8(%rsp)
movq 0xb8(%rsp), %rax
movq 0x88(%rax), %rcx
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movl $0x18, %edx
callq 0x10a0
movl %eax, 0x4(%rsp)
movslq 0x4(%rsp), %rax
cmpq $0x18, %rax
je 0x768a
movq 0x8994(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movl 0x4(%rsp), %edx
leaq 0x6216(%rip), %rsi      # 0xd888
movb $0x0, %al
callq 0x1150
movq $0x0, 0xd0(%rsp)
jmp 0x77a3
leaq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x8000, %edi           # imm = 0x8000
callq 0x1190
movq %rax, %rcx
movq 0xb8(%rsp), %rax
movq %rcx, 0xc0(%rax)
movq 0xb8(%rsp), %rax
cmpq $0x0, 0xc0(%rax)
je 0x76c4
jmp 0x76e3
leaq 0x61d7(%rip), %rdi      # 0xd8a2
leaq 0x5200(%rip), %rsi      # 0xc8d2
movl $0xec, %edx
leaq 0x6146(%rip), %rcx      # 0xd824
callq 0x1100
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, (%rsp)
subl $0xa1b23c4d, %eax       # imm = 0xA1B23C4D
je 0x7727
jmp 0x76f6
movl (%rsp), %eax
subl $0xa1b2c3d4, %eax       # imm = 0xA1B2C3D4
jne 0x774c
jmp 0x7702
movq 0x88ef(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x61a7(%rip), %rsi      # 0xd8ba
movb $0x0, %al
callq 0x1150
movq $0x3e8, 0x8a43(%rip) # imm = 0x3E8
jmp 0x7779
movq 0x88ca(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x618d(%rip), %rsi      # 0xd8c5
movb $0x0, %al
callq 0x1150
movq $0x1, 0x8a1e(%rip) # 0x10168
jmp 0x7779
movq 0x88a5(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movl (%rax), %edx
leaq 0x616c(%rip), %rsi      # 0xd8d0
movb $0x0, %al
callq 0x1150
movq $0x0, 0xd0(%rsp)
jmp 0x77a3
movq 0xb8(%rsp), %rax
movq 0xb0(%rax), %rcx
addq $0x18, %rcx
movq %rcx, 0xb0(%rax)
movq 0xb8(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)