// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xdelta_decode_block
int cram_xdelta_decode_block(cram_slice *slice, cram_codec *c, cram_block *in,
                             char *out_, int *out_size) {
    cram_block *out = (cram_block *)out_;
    cram_block *b = c->u.e_xdelta.sub_codec->get_block(slice, c->u.e_xdelta.sub_codec);
    int i = 0;

    const int w = c->u.xdelta.word_size;
    uint32_t npad = (w - *out_size%w)%w;
    uint32_t out_sz = *out_size + npad;
    c->u.xdelta.last = 0;  // reset for each new array

    for (i = 0; i < out_sz; i += w) {
        uint16_t v;
        // Need better interface
        char *cp = (char *)b->data + b->byte;
        char *cp_end = (char *)b->data + b->uncomp_size;
        int err = 0;
        v = c->vv->varint_get32(&cp, cp_end, &err);
        if (err)
            return -1;
        b->byte = cp - (char *)b->data;

        switch(w) {
        case 2: {
            int16_t d = unzigzag16(v), z;
            c->u.xdelta.last = d + c->u.xdelta.last;
            z = le_int2(c->u.xdelta.last);
            BLOCK_APPEND(out, &z, 2-npad);
            npad = 0;
            break;
        }
        default:
            fprintf(stderr, "Unsupported word size by XDELTA\n");
            return -1;
        }
    }

    return 0;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r12
movq %rcx, %r13
movq %rsi, %r14
movq 0x78(%rsi), %rsi
callq *0x50(%rsi)
movq %rax, %r15
movzbl 0x68(%r14), %ebx
movl (%r12), %ecx
movl %ecx, %eax
cltd
idivl %ebx
movl %ebx, %eax
subl %edx, %eax
cltd
idivl %ebx
movq $0x0, 0x60(%r14)
addl %edx, %ecx
movl %ecx, 0x1c(%rsp)
je 0x9110f
movl %edx, 0xc(%rsp)
xorl %r12d, %r12d
movl %ebx, 0x18(%rsp)
movq 0x20(%r15), %rax
movq 0x30(%r15), %rcx
addq %rax, %rcx
movq %rcx, 0x20(%rsp)
movslq 0x14(%r15), %rsi
addq %rax, %rsi
movl $0x0, 0x14(%rsp)
movq 0x10(%r14), %rax
leaq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rdx
callq *0x18(%rax)
cmpl $0x0, 0x14(%rsp)
je 0x9102e
xorl %ebp, %ebp
jmp 0x910f0
movq 0x20(%rsp), %rcx
subq 0x20(%r15), %rcx
movq %rcx, 0x30(%r15)
cmpb $0x2, %bl
jne 0x91105
movzwl %ax, %ecx
shrl %ecx
andl $0x1, %eax
negl %eax
xorl %ecx, %eax
movswq %ax, %rax
addq 0x60(%r14), %rax
movq %rax, 0x60(%r14)
movw %ax, 0x12(%rsp)
movl $0x2, %ebx
movl 0xc(%rsp), %ecx
subl %ecx, %ebx
movq 0x30(%r13), %rbp
addq %rbx, %rbp
movq 0x28(%r13), %rax
cmpq %rbp, %rax
ja 0x910b4
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbp, %rax
cmovaq %rax, %rbp
movq 0x20(%r13), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x910d7
movq %rbp, 0x28(%r13)
movq %rax, 0x20(%r13)
movl 0xc(%rsp), %ecx
movb $0x1, %bpl
cmpl $0x2, %ecx
je 0x910d9
movq 0x20(%r13), %rdi
addq 0x30(%r13), %rdi
leaq 0x12(%rsp), %rsi
movq %rbx, %rdx
callq 0x43c0
addq %rbx, 0x30(%r13)
jmp 0x910d9
xorl %ebp, %ebp
testb %bpl, %bpl
movl 0xc(%rsp), %eax
movl $0x0, %ecx
cmovnel %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0x18(%rsp), %ebx
testb %bpl, %bpl
je 0x91113
addl %ebx, %r12d
cmpl 0x1c(%rsp), %r12d
jb 0x90ff0
jmp 0x9110f
callq 0x4c53
jmp 0x91027
xorl %eax, %eax
jmp 0x91118
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq