// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
movl %esi, %r12d
movq %rdi, %r14
movq 0x8(%rdi), %rbx
leal -0x101(%r12), %eax
cmpl $0x2, %eax
jae 0x1cf6
movl $0x100000, 0x14(%rbx)   # imm = 0x100000
movl $0x0, 0x1c(%r14)
jmp 0x1d03
cmpl $0x100, %r12d           # imm = 0x100
jne 0x1d12
movb $0x1, (%r14)
xorl %r15d, %r15d
movl %r15d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x100000, 0x14(%rbx)   # imm = 0x100000
jne 0x1d51
movl %r12d, %edi
callq 0x1a25
movq %rax, 0x8(%r14)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1d06
movl %r12d, %edi
callq 0x18bf
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x1dfe
movq $0x0, 0x18(%r14)
jmp 0x1d03
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x1df3
movq %rbx, %rdi
movl %r12d, %esi
callq 0x1ac9
movl 0x14(%rbx), %eax
cmpl 0xc(%rbx), %eax
jbe 0x1d95
cmpl $0x0, 0x18(%rbx)
je 0x1d95
xorl %ebp, %ebp
movl 0x1c(%rbx), %eax
addl %ebp, %eax
movzbl 0x20(%rbx,%rax), %esi
movq %r14, %rdi
callq 0x1940
incl %ebp
cmpl 0x18(%rbx), %ebp
jb 0x1d79
movl 0x14(%rbx), %eax
xorl %r15d, %r15d
cmpl 0x8(%rbx), %eax
jne 0x1d06
movl 0x18(%r14), %eax
movl %eax, 0x10(%rbx)
movl %eax, 0x14(%rbx)
movl 0x10(%r14), %edx
xorl %r15d, %r15d
testq %rdx, %rdx
je 0x1e0b
shlq $0x4, %rdx
xorl %ecx, %ecx
testl %eax, %eax
je 0x1e0d
movq (%r14), %rsi
cmpb $0x0, (%rsi,%rcx)
je 0x1de8
movq (%rbx), %rdi
movl 0x4(%rsi,%rcx), %r8d
movl 0xc(%rsi,%rcx), %r9d
movl %r8d, (%rdi,%r9,8)
movzwl 0x8(%rsi,%rcx), %esi
movw %si, 0x4(%rdi,%r9,8)
decl %eax
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1dbd
jmp 0x1e0d
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
jmp 0x1d06
movq $0x0, 0x8(%r14)
jmp 0x1d06
xorl %edx, %edx
movq (%r14), %rdi
xorl %esi, %esi
callq 0x1070
movl $0x104, 0x18(%r14)      # imm = 0x104
movl $0xffffffff, 0x8(%r14)  # imm = 0xFFFFFFFF
jmp 0x1d06