// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x4(%rsp)
subl $0x100, %eax            # imm = 0x100
je 0x247a
jmp 0x246a
movl 0x4(%rsp), %eax
addl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
subl $0x2, %eax
jb 0x248f
jmp 0x24b4
movq 0x28(%rsp), %rax
movb $0x1, (%rax)
movl $0x0, 0x34(%rsp)
jmp 0x271f
movq 0x10(%rsp), %rax
movl $0x100000, 0x14(%rax)   # imm = 0x100000
movq 0x28(%rsp), %rax
movl $0x0, 0x1c(%rax)
movl $0x0, 0x34(%rsp)
jmp 0x271f
movq 0x10(%rsp), %rax
cmpl $0x100000, 0x14(%rax)   # imm = 0x100000
jne 0x255a
movl 0x24(%rsp), %edi
callq 0x1f40
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x10(%rsp)
jne 0x24f7
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x271f
movl 0x24(%rsp), %edi
callq 0x1bd0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, 0x8(%rsp)
jne 0x2535
movq 0x28(%rsp), %rax
movq $0x0, 0x8(%rax)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x271f
movq 0x28(%rsp), %rax
movl $0x0, 0x18(%rax)
movq 0x28(%rsp), %rax
movl $0x0, 0x1c(%rax)
movl $0x0, 0x34(%rsp)
jmp 0x271f
jmp 0x255c
cmpq $0x0, 0x8(%rsp)
je 0x256c
cmpq $0x0, 0x10(%rsp)
jne 0x2579
movl $0xfffffffe, 0x34(%rsp) # imm = 0xFFFFFFFE
jmp 0x271f
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x20a0
movq 0x10(%rsp), %rax
movl 0x14(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jbe 0x25eb
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x25e9
movq 0x10(%rsp), %rax
movq 0x10(%rsp), %rcx
movl 0x1c(%rcx), %ecx
addl 0x20(%rsp), %ecx
movl %ecx, %ecx
movzbl 0x20(%rax,%rcx), %eax
movl %eax, 0x1c(%rsp)
movq 0x8(%rsp), %rdi
movl 0x1c(%rsp), %eax
movzwl %ax, %esi
callq 0x1cd0
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x25a1
jmp 0x25eb
movq 0x10(%rsp), %rax
movl 0x14(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x2717
movq 0x10(%rsp), %rdi
callq 0x21f0
movq 0x8(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x8(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x14(%rax)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %ecx
movq 0x8(%rsp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, 0x3(%rsp)
jae 0x2657
movq 0x8(%rsp), %rax
cmpl $0x0, 0x18(%rax)
setne %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
testb $0x1, %al
jne 0x2664
jmp 0x270d
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x20(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x26fb
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x20(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edx
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl 0x20(%rsp), %esi
shlq $0x4, %rsi
addq %rsi, %rcx
movl 0xc(%rcx), %ecx
movl %edx, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x20(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movw 0x8(%rax), %dx
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl 0x20(%rsp), %esi
shlq $0x4, %rsi
addq %rsi, %rcx
movl 0xc(%rcx), %ecx
movw %dx, 0x4(%rax,%rcx,8)
movq 0x8(%rsp), %rax
movl 0x18(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x26fd
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x2633
movq 0x8(%rsp), %rdi
callq 0x1ee0
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopl (%rax,%rax)