// File: /workspace/github_c_makefile_star2_O0/ijleesw[P]data-compression/src/lz78/lz78.c
// Function: ht_dictionary_update
int ht_dictionary_update(ht_dictionary* d, uint16_t label) {
    uint8_t i;
    uint32_t key;
    uint32_t hash;
    d->prev_node = d->cur_node;

    if (d->cur_node == -1) {
        d->cur_node = label;
        return -1;
    }

    /* Bernstein hash function */
    key = (label << bitlen(d->d_size)) + d->cur_node;
    hash = 0;
    for (i = 0; i < 4; ++i) {
        hash = ((hash << 5) + hash) + (key & 0xFF);
        key >>= 8;
    }
    hash %= d->d_size;

    /* Search if current sequence is present, else return an empty hash entry
       where insert it */
    while (d->root[hash].used) {
        if (d->root[hash].parent == d->cur_node &&
                d->root[hash].label == label) {
            d->cur_node = d->root[hash].child;
            return -1;
        } else {
            /* Collision (linear search) */
            hash = (hash + 1) % d->d_size;
        }
    }

    /* At this point, in d->prev_node there is the symbol we will send */

    /* Fill out hash entry */
    d->root[hash].used = 1;
    d->root[hash].parent = d->prev_node;
    d->root[hash].label = label;
    d->root[hash].child = d->d_next;
    /* Update current node */
    d->cur_node = label;
    /* Update next symbol */
    ++(d->d_next);

    return 0;
}

// Assembly:
subq $0x28, %rsp
movw %si, %ax
movq %rdi, 0x18(%rsp)
movw %ax, 0x16(%rsp)
movq 0x18(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x18(%rsp), %rax
cmpl $-0x1, 0x8(%rax)
jne 0x1d16
movzwl 0x16(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x1ed2
movzwl 0x16(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rax
movl 0x10(%rax), %edi
callq 0x1ba0
movb %al, %cl
movl 0x8(%rsp), %eax
movzbl %cl, %ecx
shll %cl, %eax
movq 0x18(%rsp), %rcx
addl 0x8(%rcx), %eax
movl %eax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movb $0x0, 0x15(%rsp)
movzbl 0x15(%rsp), %eax
cmpl $0x4, %eax
jge 0x1d8c
movl 0xc(%rsp), %eax
shll $0x5, %eax
addl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
andl $0xff, %ecx
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0x10(%rsp), %eax
shrl $0x8, %eax
movl %eax, 0x10(%rsp)
movb 0x15(%rsp), %al
addb $0x1, %al
movb %al, 0x15(%rsp)
jmp 0x1d50
movq 0x18(%rsp), %rax
movl 0x10(%rax), %ecx
movl 0xc(%rsp), %eax
xorl %edx, %edx
divl %ecx
movl %edx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x1e41
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq 0x18(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x1e27
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x8(%rax), %eax
movzwl 0x16(%rsp), %ecx
cmpl %ecx, %eax
jne 0x1e27
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x1ed2
movl 0xc(%rsp), %eax
addl $0x1, %eax
movq 0x18(%rsp), %rcx
xorl %edx, %edx
divl 0x10(%rcx)
movl %edx, 0xc(%rsp)
jmp 0x1da0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movb $0x1, (%rax)
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movw 0x16(%rsp), %cx
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x8(%rax)
movq 0x18(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rsp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movzwl 0x16(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x18(%rsp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopl (%rax,%rax)