// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/cram_codecs.c
// Function: cram_huffman_decode_init
cram_codec *cram_huffman_decode_init(char *data, int size,
				     enum cram_external_type option,
				     int version) {
    int32_t ncodes = 0, i, j;
    char *cp = data, *data_end = &data[size];
    cram_codec *h;
    cram_huffman_code *codes;
    int32_t val, last_len, max_len = 0;
    int l;

    cp += safe_itf8_get(cp, data_end, &ncodes);
    h = calloc(1, sizeof(*h));
    if (!h)
	return NULL;

    h->codec  = E_HUFFMAN;
    h->free   = cram_huffman_decode_free;

    h->huffman.ncodes = ncodes;
    codes = h->huffman.codes = malloc(ncodes * sizeof(*codes));
    if (!codes) {
	free(h);
	return NULL;
    }

    /* Read symbols and bit-lengths */
    for (i = 0, l = 1; i < ncodes && l > 0; i++, cp += l) {
	l = safe_itf8_get(cp, data_end, &codes[i].symbol);
    }

    if (l < 1) {
	fprintf(stderr, "Malformed huffman header stream\n");
	free(h);
	return NULL;
    }
    cp += safe_itf8_get(cp, data_end, &i);
    if (i != ncodes) {
	fprintf(stderr, "Malformed huffman header stream\n");
	free(h);
	return NULL;
    }

    if (ncodes == 0) {
	/* NULL huffman stream.  Ensure it returns an error if
           anything tries to use it. */
        h->decode = cram_huffman_decode_null;
        return h;
    }

    for (i = 0, l = 1; i < ncodes; i++, cp += l) {
        l = safe_itf8_get(cp, data_end, &codes[i].len);
        if (l < 1)
            break;
	if (max_len < codes[i].len)
	    max_len = codes[i].len;
    }
    if (l < 1 || cp - data != size || max_len >= ncodes) {
	fprintf(stderr, "Malformed huffman header stream\n");
	free(h);
	return NULL;
    }

    /* Sort by bit length and then by symbol value */
    qsort(codes, ncodes, sizeof(*codes), code_sort);

    /* Assign canonical codes */
    val = -1, last_len = 0;
    for (i = 0; i < ncodes; i++) {
	val++;
	if (codes[i].len > last_len) {
	    while (codes[i].len > last_len) {
		val <<= 1;
		last_len++;
	    }
	}
	codes[i].code = val;
    }

    /*
     * Compute the next starting point, offset by the i'th value.
     * For example if codes 10, 11, 12, 13 are 30, 31, 32, 33 then
     * codes[10..13].p = 30 - 10.
     */
    last_len = 0;
    for (i = j = 0; i < ncodes; i++) {
	if (codes[i].len > last_len) {
	    j = codes[i].code - i;
	    last_len = codes[i].len;
	}
	codes[i].p = j;
    }

//    puts("==HUFF LEN==");
//    for (i = 0; i <= last_len+1; i++) {
//	printf("len %d=%d prefix %d\n", i, h->huffman.lengths[i], h->huffman.prefix[i]); 
//    }
//    puts("===HUFFMAN CODES===");
//    for (i = 0; i < ncodes; i++) {
//	int j;
//	printf("%d: %d %d %d ", i, codes[i].symbol, codes[i].len, codes[i].code);
//	j = codes[i].len;
//	while (j) {
//	    putchar(codes[i].code & (1 << --j) ? '1' : '0');
//	}
//	printf(" %d\n", codes[i].code);
//    }

    if (option == E_BYTE || option == E_BYTE_ARRAY) {
	if (h->huffman.codes[0].len == 0)
	    h->decode = cram_huffman_decode_char0;
	else
	    h->decode = cram_huffman_decode_char;
    } else if (option == E_BYTE_ARRAY_BLOCK) {
	abort();
    } else {
	if (h->huffman.codes[0].len == 0)
	    h->decode = cram_huffman_decode_int0;
	else
	    h->decode = cram_huffman_decode_int;
    }

    return (cram_codec *)h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0xcd280
movl %eax, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x1, %edi
movl $0x240, %esi            # imm = 0x240
callq 0x6460
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xd02b2
movq $0x0, -0x8(%rbp)
jmp 0xd06a2
movq -0x40(%rbp), %rax
movl $0x3, (%rax)
movq -0x40(%rbp), %rax
leaq -0x557(%rip), %rcx      # 0xcfd70
movq %rcx, 0x10(%rax)
movl -0x20(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x30(%rax)
movslq -0x20(%rbp), %rdi
shlq $0x4, %rdi
callq 0x69c0
movq -0x40(%rbp), %rcx
movq %rax, 0x38(%rcx)
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xd030b
movq -0x40(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xd06a2
movl $0x0, -0x24(%rbp)
movl $0x1, -0x58(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x20(%rbp), %ecx
movb %al, -0x59(%rbp)
jge 0xd0330
cmpl $0x0, -0x58(%rbp)
setg %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0xd0339
jmp 0xd0374
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movslq -0x24(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
callq 0xcd280
movl %eax, -0x58(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x58(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0xd0319
cmpl $0x1, -0x58(%rbp)
jge 0xd03a8
movq 0x34c4f(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x1581c(%rip), %rsi     # 0xe5ba7
movb $0x0, %al
callq 0x6a80
movq -0x40(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xd06a2
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0xcd280
movl %eax, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0xd03ff
movq 0x34bf8(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x157c5(%rip), %rsi     # 0xe5ba7
movb $0x0, %al
callq 0x6a80
movq -0x40(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xd06a2
cmpl $0x0, -0x20(%rbp)
jne 0xd0421
movq -0x40(%rbp), %rax
leaq -0x660(%rip), %rcx      # 0xcfdb0
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xd06a2
movl $0x0, -0x24(%rbp)
movl $0x1, -0x58(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd04ac
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movslq -0x24(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
addq $0xc, %rdx
callq 0xcd280
movl %eax, -0x58(%rbp)
cmpl $0x1, -0x58(%rbp)
jge 0xd0462
jmp 0xd04ac
movl -0x54(%rbp), %eax
movq -0x48(%rbp), %rcx
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jge 0xd048e
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0xd0490
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x58(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0xd042f
cmpl $0x1, -0x58(%rbp)
jl 0xd04ce
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
jne 0xd04ce
movl -0x54(%rbp), %eax
cmpl -0x20(%rbp), %eax
jl 0xd04fc
movq 0x34afb(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x156c8(%rip), %rsi     # 0xe5ba7
movb $0x0, %al
callq 0x6a80
movq -0x40(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xd06a2
movq -0x48(%rbp), %rdi
movslq -0x20(%rbp), %rsi
movl $0x10, %edx
leaq 0x1a0(%rip), %rcx       # 0xd06b0
callq 0x6e50
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x50(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd05a0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
cmpl -0x50(%rbp), %eax
jle 0xd0580
jmp 0xd0554
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
cmpl -0x50(%rbp), %eax
jle 0xd057e
movl -0x4c(%rbp), %eax
shll %eax
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xd0554
jmp 0xd0580
movl -0x4c(%rbp), %ecx
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd052a
movl $0x0, -0x50(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd0621
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
cmpl -0x50(%rbp), %eax
jle 0xd0601
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
subl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x50(%rbp)
movl -0x28(%rbp), %ecx
movq -0x48(%rbp), %rax
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd05b5
cmpl $0x3, -0x18(%rbp)
je 0xd062d
cmpl $0x4, -0x18(%rbp)
jne 0xd065d
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
cmpl $0x0, 0xc(%rax)
jne 0xd064c
movq -0x40(%rbp), %rax
leaq -0x876(%rip), %rcx      # 0xcfdd0
movq %rcx, 0x18(%rax)
jmp 0xd065b
movq -0x40(%rbp), %rax
leaq -0x827(%rip), %rcx      # 0xcfe30
movq %rcx, 0x18(%rax)
jmp 0xd069a
cmpl $0x5, -0x18(%rbp)
jne 0xd0668
callq 0x63b0
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
cmpl $0x0, 0xc(%rax)
jne 0xd0687
movq -0x40(%rbp), %rax
leaq -0x691(%rip), %rcx      # 0xcfff0
movq %rcx, 0x18(%rax)
jmp 0xd0696
movq -0x40(%rbp), %rax
leaq -0x632(%rip), %rcx      # 0xd0060
movq %rcx, 0x18(%rax)
jmp 0xd0698
jmp 0xd069a
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)