// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_decode.c
// Function: cram_decode_slice_header
cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) {
    cram_block_slice_hdr *hdr;
    char *cp;
    char *cp_end;
    int i;

    if (b->method != RAW) {
        /* Spec. says slice header should be RAW, but we can future-proof
	   by trying to decode it if it isn't. */
        if (cram_uncompress_block(b) < 0)
            return NULL;
    }
    cp =  (char *)b->data;
    cp_end = cp + b->uncomp_size;

    if (b->content_type != MAPPED_SLICE &&
	b->content_type != UNMAPPED_SLICE)
	return NULL;

    if (!(hdr  = calloc(1, sizeof(*hdr))))
	return NULL;

    hdr->content_type = b->content_type;

    if (b->content_type == MAPPED_SLICE) {
        cp += safe_itf8_get(cp,  cp_end, &hdr->ref_seq_id);
        cp += safe_itf8_get(cp,  cp_end, &hdr->ref_seq_start);
        cp += safe_itf8_get(cp,  cp_end, &hdr->ref_seq_span);
    }
    cp += safe_itf8_get(cp,  cp_end, &hdr->num_records);
    hdr->record_counter = 0;
    if (CRAM_MAJOR_VERS(fd->version) == 2) {
	int32_t i32 = 0;
	cp += safe_itf8_get(cp, cp_end, &i32);
	hdr->record_counter = i32;
    } else if (CRAM_MAJOR_VERS(fd->version) >= 3) {
	cp += ltf8_get(cp, &hdr->record_counter);
    }

    cp += safe_itf8_get(cp, cp_end, &hdr->num_blocks);

    cp += safe_itf8_get(cp, cp_end, &hdr->num_content_ids);
    if (hdr->num_content_ids < 1 ||
	hdr->num_content_ids >= SIZE_MAX / sizeof(int32_t)) {
        /* Slice must have at least one data block,
	   and malloc'd size shouldn't wrap. */
        free(hdr);
        return NULL;
    }
    hdr->block_content_ids = malloc(hdr->num_content_ids * sizeof(int32_t));
    if (!hdr->block_content_ids) {
	free(hdr);
	return NULL;
    }

    for (i = 0; i < hdr->num_content_ids; i++) {
	int l = safe_itf8_get(cp, cp_end,
			      &hdr->block_content_ids[i]);
	if (l <= 0) {
	    free(hdr->block_content_ids);
	    free(hdr);
	    return NULL;
	}
	cp += l;
    }

    if (b->content_type == MAPPED_SLICE) {
        cp += safe_itf8_get(cp,  cp_end, &hdr->ref_base_id);
    }

    if (CRAM_MAJOR_VERS(fd->version) != 1) {
        if (cp_end - cp < 16) {
            free(hdr->block_content_ids);
            free(hdr);
            return NULL;
        }
	memcpy(hdr->md5, cp, 16);
    } else {
	memset(hdr->md5, 0, 16);
    }

    return hdr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %r12
cmpl $0x0, (%rsi)
je 0x17ace
movq %r14, %rdi
callq 0x28143
testl %eax, %eax
js 0x17ca0
movl 0x8(%r14), %ebp
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x17ca0
movq 0x20(%r14), %r13
movslq 0x14(%r14), %r15
pushq $0x1
popq %rdi
pushq $0x48
popq %rsi
callq 0x4370
testq %rax, %rax
je 0x17ca0
movq %rax, %rbx
addq %r13, %r15
movl %ebp, (%rax)
cmpl $0x2, %ebp
movq %r14, 0x18(%rsp)
jne 0x17b4c
leaq 0x4(%rbx), %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1605f
movl %eax, %r14d
addq %r13, %r14
leaq 0x8(%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1605f
movl %eax, %ebp
addq %r14, %rbp
leaq 0xc(%rbx), %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1605f
movl %eax, %r13d
addq %rbp, %r13
leaq 0x10(%rbx), %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1605f
movl %eax, %ebp
addq %r13, %rbp
andq $0x0, 0x18(%rbx)
leaq 0x18(%rbx), %r13
movl 0xc(%r12), %eax
sarl $0x8, %eax
cmpl $0x2, %eax
jne 0x17b9b
leaq 0x24(%rsp), %r14
andl $0x0, (%r14)
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1605f
movl %eax, %eax
addq %rax, %rbp
movslq (%r14), %rax
movq %rax, (%r13)
jmp 0x17bad
jle 0x17bad
movq %rbp, %rdi
movq %r13, %rsi
callq 0x26b2f
cltq
addq %rax, %rbp
leaq 0x20(%rbx), %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1605f
movl %eax, %r13d
addq %rbp, %r13
leaq 0x24(%rbx), %rbp
movq %r13, %rdi
movq %r15, 0x10(%rsp)
movq %r15, %rsi
movq %rbp, %rdx
callq 0x1605f
movslq 0x24(%rbx), %r15
testq %r15, %r15
jle 0x17c98
movl %eax, %r14d
leaq (,%r15,4), %rdi
callq 0x46f0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x17c98
movq %r12, 0x8(%rsp)
movl %r14d, %eax
addq %rax, %r13
xorl %r14d, %r14d
xorl %r12d, %r12d
movslq %r15d, %rax
cmpq %rax, %r12
jge 0x17c46
movq 0x28(%rbx), %rdx
addq %r14, %rdx
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x1605f
testl %eax, %eax
je 0x17c8f
movl %eax, %eax
addq %rax, %r13
incq %r12
movl (%rbp), %r15d
addq $0x4, %r14
jmp 0x17c14
movq 0x18(%rsp), %rax
cmpl $0x2, 0x8(%rax)
movq 0x10(%rsp), %r14
jne 0x17c6d
movq %rbx, %rdx
addq $0x30, %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x1605f
movl %eax, %eax
addq %rax, %r13
movq 0x8(%rsp), %rcx
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%rcx), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x17c86
xorps %xmm0, %xmm0
jmp 0x17cb9
subq %r13, %r14
cmpq $0xf, %r14
jg 0x17cb4
movq 0x28(%rbx), %rdi
callq 0x4600
movq %rbx, %rdi
callq 0x4600
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movups (%r13), %xmm0
movups %xmm0, 0x34(%rbx)
jmp 0x17ca2