// File: /workspace/github_c_makefile_star2_O2/ijleesw[P]data-compression/src/lz78/lz78.c
// Function: decompress_code
int decompress_code(lz78_d* o, uint32_t code) {
    uint32_t i;
    int c_in;
    /* Optimization pointers */
    dictionary* d_main = o->main;
    ht_dictionary* d_sec = o->secondary;

    switch(code) {
    case DICT_CODE_EOF:
            o->completed = 1;
            return 0;
    case DICT_CODE_START:
        case DICT_CODE_SIZE:
            d_main->d_next = DICT_SIZE_MAX;
            o->n_bits = 0;
            return 0;
    default:
            /* Initial operations */
            if (d_main->d_next == DICT_SIZE_MAX) {
                //dictionary_destroy(d_main);   /* Modified */
                d_main = dictionary_new(code);
                o->main = d_main;
                if (d_main == NULL)
                    return -1;
                //ht_dictionary_destroy(d_sec);   /* Modified */
                d_sec = ht_dictionary_new(code);
                o->secondary = d_sec;
                if (d_sec == NULL) {
                    //dictionary_destroy(d_main);   /* Modified */
                    o->main = NULL;
                    return -1;
                }
                o->bitbuf = 0;
                o->n_bits = 0;
                return 0;
            }
            break;
    }

    /* Bad compressed file */
    if (d_sec == NULL || d_main == NULL)
        return -2;

    dictionary_update(d_main, code);

    /* Update of secondary if threshold is reached */
    if (d_main->d_next > d_main->d_thr) {
        for (i = 0; i < d_main->n_bytes; ++i) {
            c_in = (uint8_t) d_main->bytebuf[d_main->offset + i];
            ht_dictionary_update(d_sec, c_in);
        }
    }

    /* Dictonaries swap */
    if (d_main->d_next == d_main->d_size) {
        dictionary_reset(d_main);
        d_main->d_min = d_sec->d_next;
        d_main->d_next = d_sec->d_next;
        for (i = 0; i < d_sec->d_size && d_sec->d_next; ++i) {
            if (d_sec->root[i].used) {
                d_main->root[d_sec->root[i].child].parent =
                        d_sec->root[i].parent;
                d_main->root[d_sec->root[i].child].label =
                        d_sec->root[i].label;
                --(d_sec->d_next);
            }
        }
        ht_dictionary_reset(d_sec);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %rbx
movq 0x8(%rdi), %r14
leal -0x101(%r15), %eax
cmpl $0x2, %eax
jae 0x1bf5
movl $0x100000, 0x14(%r14)   # imm = 0x100000
andl $0x0, 0x1c(%rbx)
jmp 0x1c01
cmpl $0x100, %r15d           # imm = 0x100
jne 0x1c10
movb $0x1, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x100000, 0x14(%r14)   # imm = 0x100000
jne 0x1c4a
movl %r15d, %edi
callq 0x1935
movq %rax, 0x8(%rbx)
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x1c03
movl %r15d, %edi
callq 0x17f1
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x1ced
andq $0x0, 0x18(%rbx)
jmp 0x1c01
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
je 0x1c88
movq %r14, %rdi
movl %r15d, %esi
callq 0x19d5
movl 0x14(%r14), %eax
cmpl 0xc(%r14), %eax
jbe 0x1c94
xorl %ebp, %ebp
cmpl 0x18(%r14), %ebp
jae 0x1c90
movl 0x1c(%r14), %eax
addl %ebp, %eax
movzbl 0x20(%r14,%rax), %esi
movq %rbx, %rdi
callq 0x1865
incl %ebp
jmp 0x1c6a
pushq $-0x2
popq %rbp
jmp 0x1c03
movl 0x14(%r14), %eax
xorl %ebp, %ebp
cmpl 0x8(%r14), %eax
jne 0x1c03
movl 0x18(%rbx), %eax
movl %eax, 0x10(%r14)
movl %eax, 0x14(%r14)
movl 0x10(%rbx), %edx
shlq $0x4, %rdx
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0x1cf7
movq (%rbx), %rdi
testl %eax, %eax
je 0x1cfa
cmpb $0x0, (%rdi,%rcx)
je 0x1ce7
movq (%r14), %rsi
movl 0x4(%rdi,%rcx), %r8d
movl 0xc(%rdi,%rcx), %r9d
movl %r8d, (%rsi,%r9,8)
movzwl 0x8(%rdi,%rcx), %edi
movw %di, 0x4(%rsi,%r9,8)
decl %eax
movl %eax, 0x18(%rbx)
addq $0x10, %rcx
jmp 0x1cb4
andq $0x0, 0x8(%rbx)
jmp 0x1c03
movq (%rbx), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x1070
movl $0x104, 0x18(%rbx)      # imm = 0x104
orl $-0x1, 0x8(%rbx)
jmp 0x1c03