// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq 0x8(%rdi), %rbx
leal -0x101(%r15), %eax
cmpl $0x2, %eax
jae 0x1cf7
movl $0x100000, 0x14(%rbx)   # imm = 0x100000
movl $0x0, 0x1c(%r14)
jmp 0x1d04
cmpl $0x100, %r15d           # imm = 0x100
jne 0x1d13
movb $0x1, (%r14)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x100000, 0x14(%rbx)   # imm = 0x100000
jne 0x1d51
movl %r15d, %edi
callq 0x1a25
movq %rax, 0x8(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1d06
movl %r15d, %edi
callq 0x18bf
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x1e37
movq $0x0, 0x18(%r14)
jmp 0x1d04
movq 0x10(%r14), %r14
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jne 0x1d06
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1ac9
movl 0x14(%rbx), %eax
cmpl 0xc(%rbx), %eax
jbe 0x1d9e
cmpl $0x0, 0x18(%rbx)
je 0x1d9e
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 0x1d85
movl 0x14(%rbx), %eax
xorl %ebp, %ebp
cmpl 0x8(%rbx), %eax
jne 0x1d06
movabsq $0x10400000104, %rax    # imm = 0x10400000104
movq %rax, 0x10(%rbx)
movl 0x18(%r14), %eax
movl %eax, 0x10(%rbx)
movl %eax, 0x14(%rbx)
movl 0x10(%r14), %edx
testq %rdx, %rdx
je 0x1e12
movl 0x18(%r14), %eax
movq %rdx, %rcx
shlq $0x4, %rcx
xorl %esi, %esi
testl %eax, %eax
je 0x1e12
movq (%r14), %rdi
cmpb $0x0, (%rdi,%rsi)
je 0x1e09
movq (%rbx), %r8
movl 0x4(%rdi,%rsi), %r9d
movl 0xc(%rdi,%rsi), %r10d
movl %r9d, (%r8,%r10,8)
movzwl 0x8(%rdi,%rsi), %edi
movw %di, 0x4(%r8,%r10,8)
decl %eax
movl %eax, 0x18(%r14)
addq $0x10, %rsi
cmpq %rsi, %rcx
jne 0x1dda
movq (%r14), %rdi
shlq $0x4, %rdx
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x1070
movl $0x104, 0x18(%r14)      # imm = 0x104
movl $0xffffffff, 0x8(%r14)  # imm = 0xFFFFFFFF
jmp 0x1d06
movq $0x0, 0x8(%r14)
jmp 0x1d06