// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: hash_init(Hash*, unsigned int)
static unsigned hash_init(Hash* hash, unsigned windowsize)
{
  unsigned i;
  hash->head = (int*)lodepng_malloc(sizeof(int) * HASH_NUM_VALUES);
  hash->val = (int*)lodepng_malloc(sizeof(int) * windowsize);
  hash->chain = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize);

  hash->zeros = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize);
  hash->headz = (int*)lodepng_malloc(sizeof(int) * (MAX_SUPPORTED_DEFLATE_LENGTH + 1));
  hash->chainz = (unsigned short*)lodepng_malloc(sizeof(unsigned short) * windowsize);

  if(!hash->head || !hash->chain || !hash->val  || !hash->headz|| !hash->chainz || !hash->zeros)
  {
    return 83; /*alloc fail*/
  }

  /*initialize hash table*/
  for(i = 0; i != HASH_NUM_VALUES; ++i) hash->head[i] = -1;
  for(i = 0; i != windowsize; ++i) hash->val[i] = -1;
  for(i = 0; i != windowsize; ++i) hash->chain[i] = i; /*same value as index indicates uninitialized*/

  for(i = 0; i <= MAX_SUPPORTED_DEFLATE_LENGTH; ++i) hash->headz[i] = -1;
  for(i = 0; i != windowsize; ++i) hash->chainz[i] = i; /*same value as index indicates uninitialized*/

  return 0;
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movl $0x40000, %edi          # imm = 0x40000
callq 0x6cd0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movl 0x4(%rsp), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x6cd0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movl 0x4(%rsp), %eax
movl %eax, %edi
shlq %rdi
callq 0x6cd0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movl 0x4(%rsp), %eax
movl %eax, %edi
shlq %rdi
callq 0x6cd0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x28(%rax)
movl $0x40c, %edi            # imm = 0x40C
callq 0x6cd0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movl 0x4(%rsp), %eax
movl %eax, %edi
shlq %rdi
callq 0x6cd0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
je 0x13878
movq 0x8(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x13878
movq 0x8(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13878
movq 0x8(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x13878
movq 0x8(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x13878
movq 0x8(%rsp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x13885
movl $0x53, 0x14(%rsp)
jmp 0x1397a
movl $0x0, (%rsp)
cmpl $0x10000, (%rsp)        # imm = 0x10000
je 0x138b2
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl (%rsp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl (%rsp), %eax
addl $0x1, %eax
movl %eax, (%rsp)
jmp 0x1388c
movl $0x0, (%rsp)
movl (%rsp), %eax
cmpl 0x4(%rsp), %eax
je 0x138e0
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rsp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl (%rsp), %eax
addl $0x1, %eax
movl %eax, (%rsp)
jmp 0x138b9
movl $0x0, (%rsp)
movl (%rsp), %eax
cmpl 0x4(%rsp), %eax
je 0x13911
movl (%rsp), %eax
movw %ax, %dx
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movl (%rsp), %eax
addl $0x1, %eax
movl %eax, (%rsp)
jmp 0x138e7
movl $0x0, (%rsp)
movl (%rsp), %eax
cmpq $0x102, %rax            # imm = 0x102
ja 0x13941
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl (%rsp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl (%rsp), %eax
addl $0x1, %eax
movl %eax, (%rsp)
jmp 0x13918
movl $0x0, (%rsp)
movl (%rsp), %eax
cmpl 0x4(%rsp), %eax
je 0x13972
movl (%rsp), %eax
movw %ax, %dx
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movl (%rsp), %eax
addl $0x1, %eax
movl %eax, (%rsp)
jmp 0x13948
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)