// File: /workspace/github_c_makefile_star2_O0/ijleesw[P]data-compression/src/lz78/lz78.c
// Function: lz78_new
lz78_instance* lz78_new(uint8_t cmode, uint32_t dsize) {
    lz78_instance* i;
    lz78_c* c;
    lz78_d* d;

    int max_dim = (sizeof(lz78_c) > sizeof(lz78_d)) ? sizeof(lz78_c) : sizeof(lz78_d);
    i = malloc(sizeof(lz78_instance) + max_dim);
    if (i == NULL)
        return NULL;
    i->mode = cmode;

    switch (cmode) {
        case LZ78_MODE_COMPRESS:
            c = (lz78_c*)&i->state; 
            dsize = (dsize == 0) ? DICT_SIZE_DEFAULT : dsize;
            c->d_size = DICT_LIMIT(dsize);
            c->completed = 0;
            c->main = ht_dictionary_new(c->d_size);
            if (c->main == NULL) {
                free(i);
                return NULL;
            }
            c->secondary = ht_dictionary_new(c->d_size);
            if (c->secondary == NULL) {
                ht_dictionary_destroy(c->main);
                free(i);
                return NULL;
            }
            c->bitbuf = DICT_CODE_START;
            c->n_bits = bitlen(DICT_SIZE_MIN);
            c->main->cur_node = DICT_CODE_START;
            return i;

        case LZ78_MODE_DECOMPRESS:
            d = (lz78_d*)&i->state; 
            d->completed = 0;
            d->main = dictionary_new(DICT_SIZE_MIN);
            if (d->main == NULL) {
                free(i);
                return NULL;
            }
            return i;

        default:
            return NULL;
    }
}

// Assembly:
subq $0x48, %rsp
movb %dil, %al
movb %al, 0x3f(%rsp)
movl %esi, 0x38(%rsp)
movl $0x20, 0x1c(%rsp)
movslq 0x1c(%rsp), %rdi
addq $0x1, %rdi
callq 0x10f0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x2770
movq $0x0, 0x40(%rsp)
jmp 0x2941
movb 0x3f(%rsp), %cl
movq 0x30(%rsp), %rax
movb %cl, (%rax)
movzbl 0x3f(%rsp), %eax
movl %eax, 0x18(%rsp)
testl %eax, %eax
je 0x279c
jmp 0x278a
movl 0x18(%rsp), %eax
subl $0x1, %eax
je 0x28df
jmp 0x2938
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x38(%rsp)
jne 0x27bc
movl $0x1000, %eax           # imm = 0x1000
movl %eax, 0x14(%rsp)
jmp 0x27c4
movl 0x38(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x38(%rsp)
cmpl $0x105, 0x38(%rsp)      # imm = 0x105
jae 0x27e1
movl $0x105, %eax            # imm = 0x105
movl %eax, 0x10(%rsp)
jmp 0x2806
cmpl $0x100000, 0x38(%rsp)   # imm = 0x100000
jbe 0x27f6
movl $0x100000, %eax         # imm = 0x100000
movl %eax, 0xc(%rsp)
jmp 0x27fe
movl 0x38(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x28(%rsp), %rax
movb $0x0, (%rax)
movq 0x28(%rsp), %rax
movl 0x4(%rax), %edi
callq 0x1bd0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2857
movq 0x30(%rsp), %rdi
callq 0x1030
movq $0x0, 0x40(%rsp)
jmp 0x2941
movq 0x28(%rsp), %rax
movl 0x4(%rax), %edi
callq 0x1bd0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x28a2
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1f20
movq 0x30(%rsp), %rdi
callq 0x1030
movq $0x0, 0x40(%rsp)
jmp 0x2941
movq 0x28(%rsp), %rax
movl $0x102, 0x18(%rax)      # imm = 0x102
movl $0x104, %edi            # imm = 0x104
callq 0x1ba0
movzbl %al, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movl $0x102, 0x8(%rax)       # imm = 0x102
movq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x2941
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movb $0x0, (%rax)
movl $0x104, %edi            # imm = 0x104
callq 0x1f40
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x292c
movq 0x30(%rsp), %rdi
callq 0x1030
movq $0x0, 0x40(%rsp)
jmp 0x2941
movq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x2941
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopl (%rax,%rax)