// File: /workspace/github_c_makefile_star2_O0/fmadio[P]pcap_flow/main.c
// Function: FlowHash
static u32 FlowHash(u32 Type, u8* Payload, u32 Length)
{
	// generate SHA1
	u32 SHA1State[5] = { 0, 0, 0, 0, 0 };

	// hash the first 64B
	sha1_compress(SHA1State, (u8*)Payload);

	u8* Data8 = (u8*)SHA1State;

	// FNV1a 80b hash 
	const u32 Prime  = 0x01000193; //   16777619
	const u32  Seed  = 0x811C9DC5; // 2166136261

	u32 Hash = Seed;
	Hash = ((u32)Data8[ 0] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 1] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 2] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 3] ^ Hash) * Prime;

	Hash = ((u32)Data8[ 4] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 5] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 6] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 7] ^ Hash) * Prime;

	Hash = ((u32)Data8[ 8] ^ Hash) * Prime;
	Hash = ((u32)Data8[ 9] ^ Hash) * Prime;
	Hash = ((u32)Data8[10] ^ Hash) * Prime;
	Hash = ((u32)Data8[11] ^ Hash) * Prime;

	Hash = ((u32)Data8[12] ^ Hash) * Prime;
	Hash = ((u32)Data8[13] ^ Hash) * Prime;
	Hash = ((u32)Data8[14] ^ Hash) * Prime;
	Hash = ((u32)Data8[15] ^ Hash) * Prime;

	Hash = ((u32)Data8[16] ^ Hash) * Prime;
	Hash = ((u32)Data8[17] ^ Hash) * Prime;
	Hash = ((u32)Data8[18] ^ Hash) * Prime;
	Hash = ((u32)Data8[19] ^ Hash) * Prime;

	/*
	// DEK packets usually have enough entropy for this to be enough 
	u32 Hash = Type; 
	for (int i=0; i < Length; i++)
	{
		Hash = ((Hash << 5ULL) ^ (Hash >> (32-5))) ^ (u64)Payload[i];
	}
	*/

	// reduce to a 32b hash
	return Hash;
}

// Assembly:
subq $0x48, %rsp
movl %edi, 0x44(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x1110
leaq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x8d50
leaq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x1000193, 0x14(%rsp)  # imm = 0x1000193
movl $0x811c9dc5, 0x10(%rsp) # imm = 0x811C9DC5
movl $0x811c9dc5, 0xc(%rsp)  # imm = 0x811C9DC5
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x1(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x2(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x3(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x4(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x5(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x6(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x7(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x8(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x9(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0xa(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0xb(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0xc(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0xd(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0xe(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0xf(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x10(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x11(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x12(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movzbl 0x13(%rax), %eax
xorl 0xc(%rsp), %eax
imull $0x1000193, %eax, %eax  # imm = 0x1000193
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x48, %rsp
retq
nopw (%rax,%rax)