// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/fqzcomp_qual.c
// Function: uncompress_block_fqz2f
static
unsigned char *uncompress_block_fqz2f(fqz_slice *s,
                                      unsigned char *in,
                                      size_t in_size,
                                      size_t *out_size,
                                      int *lengths,
                                      int nlengths) {
    fqz_gparams gp;
    fqz_param *pm;
    char *rev_a = NULL;
    int *len_a = NULL;
    memset(&gp, 0, sizeof(gp));

    uint32_t len;
    ssize_t i, rec = 0, in_idx;
    in_idx = var_get_u32(in, in+in_size, &len);
    *out_size = len;

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    if (len > 100000)
        return NULL;
#endif

    unsigned char *uncomp = NULL;
    RangeCoder rc;
    unsigned int last = 0;

    // Decode parameter blocks
    if ((i = fqz_read_parameters(&gp, in+in_idx, in_size-in_idx)) < 0)
        return NULL;
    //dump_params(&gp);
    in_idx += i;

    // Optimisations to remove shifts from main loop
    for (i = 0; i < gp.nparam; i++) {
        int j;
        pm = &gp.p[i];
        for (j = 0; j < 1024; j++)
            pm->ptab[j] <<= pm->ploc;
        for (j = 0; j < 256; j++)
            pm->dtab[j] <<= pm->dloc;
    }

    // Initialise models and entropy coder
    fqz_model model;
    if (fqz_create_models(&model, &gp) < 0)
        return NULL;

    RC_SetInput(&rc, (char *)in+in_idx, (char *)in+in_size);
    RC_StartDecode(&rc);


    // Allocate buffers
    uncomp = (unsigned char *)malloc(*out_size);
    if (!uncomp)
        goto err;

    int nrec = 1000;
    rev_a = malloc(nrec);
    len_a = malloc(nrec * sizeof(int));
    if (!rev_a || !len_a)
        goto err;

    // Main decode loop
    fqz_state state;
    state.delta = 0;
    state.prevq = 0;
    state.qctx = 0;
    state.p = 0;
    state.s = 0;
    state.first_len = 1;
    state.last_len = 0;
    state.rec = 0;
    state.ctx = last;

    int rev = 0;
    int x = 0;
    pm = &gp.p[x];
    for (i = 0; i < len; ) {
        if (state.rec >= nrec) {
            nrec *= 2;
            rev_a = realloc(rev_a, nrec);
            len_a = realloc(len_a, nrec*sizeof(int));
            if (!rev_a || !len_a)
                goto err;
        }

        if (state.p == 0) {
            int r = decompress_new_read(s, &state, &gp, pm, &model, &rc,
                                        in, &i, uncomp, out_size,
                                        &rev, rev_a, len_a,
                                        lengths, nlengths);
            if (r < 0)
                goto err;
            if (r > 0)
                continue;
            last = state.ctx;
        }

        // Decode and update context
        do {
            unsigned char Q = SIMPLE_MODEL(QMAX,_decodeSymbol)
                (&model.qual[last], &rc);

            last = fqz_update_ctx(pm, &state, Q);
            uncomp[i++] = pm->qmap[Q];
        } while (state.p != 0 && i < len);
    }

    rec = state.rec;
    if (rec >= nrec) {
        nrec *= 2;
        rev_a = realloc(rev_a, nrec);
        len_a = realloc(len_a, nrec*sizeof(int));
        if (!rev_a || !len_a)
            goto err;
    }
    rev_a[rec] = rev;
    len_a[rec] = len;

    if (gp.gflags & GFLAG_DO_REV) {
        for (i = rec = 0; i < len && rec < nrec; i += len_a[rec++]) {
            if (!rev_a[rec])
                continue;

            int I, J;
            unsigned char *cp = uncomp+i;
            for (I = 0, J = len_a[rec]-1; I < J; I++, J--) {
                unsigned char c;
                c = cp[I];
                cp[I] = cp[J];
                cp[J] = c;
            }
        }
    }

    if (RC_FinishDecode(&rc) < 0)
        goto err;

    fqz_destroy_models(&model);
    free(rev_a);
    free(len_a);
    fqz_free_parameters(&gp);

#ifdef TEST_MAIN
    s->num_records = rec;
#endif

    return uncomp;

 err:
    fqz_destroy_models(&model);
    free(rev_a);
    free(len_a);
    fqz_free_parameters(&gp);
    free(uncomp);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a38, %rsp           # imm = 0x1A38
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movl %r9d, -0x5c(%rbp)
movq $0x0, -0x490(%rbp)
movq $0x0, -0x498(%rbp)
leaq -0x480(%rbp), %rdi
xorl %esi, %esi
movl $0x420, %edx            # imm = 0x420
callq 0x4250
movq $0x0, -0x4b0(%rbp)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq -0x48(%rbp), %rsi
leaq -0x49c(%rbp), %rdx
callq 0x8b980
cltq
movq %rax, -0x4b8(%rbp)
movl -0x49c(%rbp), %eax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x4c0(%rbp)
movl $0x0, -0x504(%rbp)
movq -0x40(%rbp), %rsi
addq -0x4b8(%rbp), %rsi
movq -0x48(%rbp), %rdx
subq -0x4b8(%rbp), %rdx
leaq -0x480(%rbp), %rdi
callq 0x8bad0
cltq
movq %rax, -0x4a8(%rbp)
cmpq $0x0, %rax
jge 0x88fe3
movq $0x0, -0x30(%rbp)
jmp 0x8972c
movq -0x4a8(%rbp), %rax
addq -0x4b8(%rbp), %rax
movq %rax, -0x4b8(%rbp)
movq $0x0, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rax
movslq -0x478(%rbp), %rcx
cmpq %rcx, %rax
jge 0x89106
movq -0x68(%rbp), %rax
imulq $0x1c64, -0x4a8(%rbp), %rcx # imm = 0x1C64
addq %rcx, %rax
movq %rax, -0x488(%rbp)
movl $0x0, -0x508(%rbp)
cmpl $0x400, -0x508(%rbp)    # imm = 0x400
jge 0x89090
movq -0x488(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x488(%rbp), %rax
movslq -0x508(%rbp), %rdx
movq %rdx, -0x1a00(%rbp)
movl 0x848(%rax,%rdx,4), %edx
shll %cl, %edx
movq -0x1a00(%rbp), %rcx
movl %edx, 0x848(%rax,%rcx,4)
movl -0x508(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x508(%rbp)
jmp 0x8903d
movl $0x0, -0x508(%rbp)
cmpl $0x100, -0x508(%rbp)    # imm = 0x100
jge 0x890ed
movq -0x488(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x488(%rbp), %rax
movslq -0x508(%rbp), %rdx
movq %rdx, -0x1a08(%rbp)
movl 0x1848(%rax,%rdx,4), %edx
shll %cl, %edx
movq -0x1a08(%rbp), %rcx
movl %edx, 0x1848(%rax,%rcx,4)
movl -0x508(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x508(%rbp)
jmp 0x8909a
jmp 0x890ef
movq -0x4a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a8(%rbp)
jmp 0x89003
leaq -0x1990(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0x8a6d0
cmpl $0x0, %eax
jge 0x8912b
movq $0x0, -0x30(%rbp)
jmp 0x8972c
movq -0x40(%rbp), %rsi
addq -0x4b8(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq -0x48(%rbp), %rdx
leaq -0x500(%rbp), %rdi
callq 0x8bdf0
leaq -0x500(%rbp), %rdi
callq 0x8be30
movq -0x50(%rbp), %rax
movq (%rax), %rdi
callq 0x4650
movq %rax, -0x4c0(%rbp)
cmpq $0x0, -0x4c0(%rbp)
jne 0x89178
jmp 0x896e8
movl $0x3e8, -0x1994(%rbp)   # imm = 0x3E8
movslq -0x1994(%rbp), %rdi
callq 0x4650
movq %rax, -0x490(%rbp)
movslq -0x1994(%rbp), %rdi
shlq $0x2, %rdi
callq 0x4650
movq %rax, -0x498(%rbp)
cmpq $0x0, -0x490(%rbp)
je 0x891c0
cmpq $0x0, -0x498(%rbp)
jne 0x891c5
jmp 0x896e8
movl $0x0, -0x19c8(%rbp)
movl $0x0, -0x19c4(%rbp)
movl $0x0, -0x19d0(%rbp)
movl $0x0, -0x19cc(%rbp)
movl $0x0, -0x19c0(%rbp)
movl $0x1, -0x19b4(%rbp)
movl $0x0, -0x19b0(%rbp)
movq $0x0, -0x19a8(%rbp)
movl -0x504(%rbp), %eax
movl %eax, -0x19a0(%rbp)
movl $0x0, -0x19d4(%rbp)
movl $0x0, -0x19d8(%rbp)
movq -0x68(%rbp), %rax
movslq -0x19d8(%rbp), %rcx
imulq $0x1c64, %rcx, %rcx     # imm = 0x1C64
addq %rcx, %rax
movq %rax, -0x488(%rbp)
movq $0x0, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rax
movl -0x49c(%rbp), %ecx
cmpq %rcx, %rax
jge 0x89472
movq -0x19a8(%rbp), %rax
movslq -0x1994(%rbp), %rcx
cmpq %rcx, %rax
jl 0x892e7
movl -0x1994(%rbp), %eax
shll %eax
movl %eax, -0x1994(%rbp)
movq -0x490(%rbp), %rdi
movslq -0x1994(%rbp), %rsi
callq 0x4820
movq %rax, -0x490(%rbp)
movq -0x498(%rbp), %rdi
movslq -0x1994(%rbp), %rsi
shlq $0x2, %rsi
callq 0x4820
movq %rax, -0x498(%rbp)
cmpq $0x0, -0x490(%rbp)
je 0x892e0
cmpq $0x0, -0x498(%rbp)
jne 0x892e5
jmp 0x896e8
jmp 0x892e7
cmpl $0x0, -0x19cc(%rbp)
jne 0x893b7
movq -0x38(%rbp), %rdi
movq -0x488(%rbp), %rcx
movq -0x40(%rbp), %rax
movq -0x4c0(%rbp), %r12
movq -0x50(%rbp), %r15
movq -0x490(%rbp), %rbx
movq -0x498(%rbp), %r11
movq -0x58(%rbp), %r10
movl -0x5c(%rbp), %edx
movl %edx, -0x1a0c(%rbp)
leaq -0x19d0(%rbp), %rsi
leaq -0x480(%rbp), %rdx
leaq -0x1990(%rbp), %r8
leaq -0x500(%rbp), %r9
leaq -0x4a8(%rbp), %r13
leaq -0x19d4(%rbp), %r14
movq %rax, (%rsp)
movl -0x1a0c(%rbp), %eax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movl %eax, 0x40(%rsp)
callq 0x8bef0
movl %eax, -0x19dc(%rbp)
cmpl $0x0, -0x19dc(%rbp)
jge 0x8939d
jmp 0x896e8
cmpl $0x0, -0x19dc(%rbp)
jle 0x893ab
jmp 0x8925d
movl -0x19a0(%rbp), %eax
movl %eax, -0x504(%rbp)
jmp 0x893b9
movq -0x1990(%rbp), %rdi
movl -0x504(%rbp), %eax
imulq $0x410, %rax, %rax      # imm = 0x410
addq %rax, %rdi
leaq -0x500(%rbp), %rsi
callq 0x8c270
movb %al, -0x19dd(%rbp)
movq -0x488(%rbp), %rdi
movzbl -0x19dd(%rbp), %edx
leaq -0x19d0(%rbp), %rsi
callq 0x8ac10
movl %eax, -0x504(%rbp)
movq -0x488(%rbp), %rax
movzbl -0x19dd(%rbp), %ecx
movl 0x48(%rax,%rcx,4), %eax
movb %al, %dl
movq -0x4c0(%rbp), %rax
movq -0x4a8(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x4a8(%rbp)
movb %dl, (%rax,%rcx)
xorl %eax, %eax
cmpl $0x0, -0x19cc(%rbp)
movb %al, -0x1a0d(%rbp)
je 0x8945f
movq -0x4a8(%rbp), %rax
movl -0x49c(%rbp), %ecx
cmpq %rcx, %rax
setl %al
movb %al, -0x1a0d(%rbp)
movb -0x1a0d(%rbp), %al
testb $0x1, %al
jne 0x893b9
jmp 0x8925d
movq -0x19a8(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movq -0x4b0(%rbp), %rax
movslq -0x1994(%rbp), %rcx
cmpq %rcx, %rax
jl 0x894f4
movl -0x1994(%rbp), %eax
shll %eax
movl %eax, -0x1994(%rbp)
movq -0x490(%rbp), %rdi
movslq -0x1994(%rbp), %rsi
callq 0x4820
movq %rax, -0x490(%rbp)
movq -0x498(%rbp), %rdi
movslq -0x1994(%rbp), %rsi
shlq $0x2, %rsi
callq 0x4820
movq %rax, -0x498(%rbp)
cmpq $0x0, -0x490(%rbp)
je 0x894ed
cmpq $0x0, -0x498(%rbp)
jne 0x894f2
jmp 0x896e8
jmp 0x894f4
movl -0x19d4(%rbp), %eax
movb %al, %dl
movq -0x490(%rbp), %rax
movq -0x4b0(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x49c(%rbp), %edx
movq -0x498(%rbp), %rax
movq -0x4b0(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x47c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x89698
movq $0x0, -0x4b0(%rbp)
movq $0x0, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rcx
movl -0x49c(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x1a0e(%rbp)
jge 0x89582
movq -0x4b0(%rbp), %rax
movslq -0x1994(%rbp), %rcx
cmpq %rcx, %rax
setl %al
movb %al, -0x1a0e(%rbp)
movb -0x1a0e(%rbp), %al
testb $0x1, %al
jne 0x89591
jmp 0x89696
movq -0x490(%rbp), %rax
movq -0x4b0(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x895aa
jmp 0x89663
movq -0x4c0(%rbp), %rax
addq -0x4a8(%rbp), %rax
movq %rax, -0x19f0(%rbp)
movl $0x0, -0x19e4(%rbp)
movq -0x498(%rbp), %rax
movq -0x4b0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, -0x19e8(%rbp)
movl -0x19e4(%rbp), %eax
cmpl -0x19e8(%rbp), %eax
jge 0x89661
movq -0x19f0(%rbp), %rax
movslq -0x19e4(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x19f1(%rbp)
movq -0x19f0(%rbp), %rax
movslq -0x19e8(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x19f0(%rbp), %rax
movslq -0x19e4(%rbp), %rcx
movb %dl, (%rax,%rcx)
movb -0x19f1(%rbp), %dl
movq -0x19f0(%rbp), %rax
movslq -0x19e8(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x19e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19e4(%rbp)
movl -0x19e8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x19e8(%rbp)
jmp 0x895e3
jmp 0x89663
movq -0x498(%rbp), %rax
movq -0x4b0(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x4b0(%rbp)
movslq (%rax,%rcx,4), %rax
addq -0x4a8(%rbp), %rax
movq %rax, -0x4a8(%rbp)
jmp 0x8954c
jmp 0x89698
leaq -0x500(%rbp), %rdi
callq 0x8c3b0
cmpl $0x0, %eax
jge 0x896ab
jmp 0x896e8
leaq -0x1990(%rbp), %rdi
callq 0x8ae90
movq -0x490(%rbp), %rdi
callq 0x45a0
movq -0x498(%rbp), %rdi
callq 0x45a0
leaq -0x480(%rbp), %rdi
callq 0x8aeb0
movq -0x4c0(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x8972c
leaq -0x1990(%rbp), %rdi
callq 0x8ae90
movq -0x490(%rbp), %rdi
callq 0x45a0
movq -0x498(%rbp), %rdi
callq 0x45a0
leaq -0x480(%rbp), %rdi
callq 0x8aeb0
movq -0x4c0(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x1a38, %rsp           # imm = 0x1A38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)