// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x50(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq 0x78(%rcx), %rsi
callq *%rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x68(%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
cltd
idivl -0x48(%rbp)
movl -0x74(%rbp), %eax
subl %edx, %eax
cltd
idivl -0x48(%rbp)
movl %edx, -0x4c(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x60(%rax)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0xe5e3d
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
addq 0x30(%rcx), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq 0x14(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq -0x68(%rbp), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x6c(%rbp), %rdx
callq *%rax
movw %ax, -0x52(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0xe5d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe5e4d
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdx
subq %rdx, %rcx
movq %rcx, 0x30(%rax)
movl -0x48(%rbp), %eax
subl $0x2, %eax
jne 0xe5e0c
jmp 0xe5dad
movzwl -0x52(%rbp), %edi
callq 0xe5e60
movw %ax, -0x6e(%rbp)
movswq -0x6e(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x60(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movswl %ax, %edi
callq 0xe5e80
movw %ax, -0x70(%rbp)
movq -0x38(%rbp), %rdi
movl $0x2, %eax
subl -0x4c(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
leaq -0x70(%rbp), %rsi
callq 0xe2300
cmpl $0x0, %eax
jge 0xe5e03
jmp 0xe5e46
movl $0x0, -0x4c(%rbp)
jmp 0xe5e2d
movq 0x271cd(%rip), %rax     # 0x10cfe0
movq (%rax), %rdi
leaq 0x130e1(%rip), %rsi     # 0xf8efe
movb $0x0, %al
callq 0x46d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe5e4d
jmp 0xe5e2f
movl -0x48(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0xe5d22
movl $0x0, -0x4(%rbp)
jmp 0xe5e4d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)