// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_encode.c
// Function: validate_md5
static int validate_md5(cram_fd *fd, int ref_id) {
    if (fd->ignore_md5 || ref_id < 0 || ref_id >= fd->refs->nref)
        return 0;

    // Have we already checked this ref?
    if (fd->refs->ref_id[ref_id]->validated_md5)
        return 0;

    // Check if we have the MD5 known.
    // We should, but maybe we're using embedded references?
    sam_hrecs_t *hrecs = fd->header->hrecs;
    sam_hrec_type_t *ty = sam_hrecs_find_type_id(hrecs, "SQ", "SN",
                                                 hrecs->ref[ref_id].name);
    if (!ty)
        return 0;

    sam_hrec_tag_t *m5tag = sam_hrecs_find_key(ty, "M5", NULL);
    if (!m5tag)
        return 0;

    // It's known, so compute md5 on the loaded reference sequence.
    char *ref = fd->refs->ref_id[ref_id]->seq;
    int64_t len = fd->refs->ref_id[ref_id]->length;
    hts_md5_context *md5;
    char unsigned buf[16];
    char buf2[33];

    if (!(md5 = hts_md5_init()))
        return -1;
    hts_md5_update(md5, ref, len);
    hts_md5_final(buf, md5);
    hts_md5_destroy(md5);
    hts_md5_hex(buf2, buf);

    // Compare it to header @SQ M5 tag
    if (strcmp(m5tag->str+3, buf2)) {
        hts_log_error("SQ header M5 tag discrepancy for reference '%s'",
                      hrecs->ref[ref_id].name);
        hts_log_error("Please use the correct reference, or "
                      "consider using embed_ref=2");
        return -1;
    }
    fd->refs->ref_id[ref_id]->validated_md5 = 1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorl %ebx, %ebx
testl %esi, %esi
js 0x48c62
movq %rdi, %r14
cmpl $0x0, 0x22c(%rdi)
jne 0x48c62
movq 0x50(%r14), %rax
cmpl %esi, 0x18(%rax)
jle 0x48c62
movq 0x10(%rax), %rax
movl %esi, %ebp
movq (%rax,%rbp,8), %rax
cmpl $0x0, 0x4c(%rax)
je 0x48c73
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r14), %rax
movq 0x38(%rax), %r15
movq 0x30(%r15), %rax
leaq (,%rbp,2), %r13
addq %rbp, %r13
movq (%rax,%r13,8), %rcx
leaq 0x52526(%rip), %rsi     # 0x9b1bb
leaq 0x536ed(%rip), %rdx     # 0x9c389
movq %r15, %rdi
callq 0x881f0
testq %rax, %rax
je 0x48c62
leaq 0x536dc(%rip), %rsi     # 0x9c38c
xorl %ebx, %ebx
movq %rax, %rdi
xorl %edx, %edx
callq 0x89a0b
testq %rax, %rax
je 0x48c62
movq %rax, %r12
movq %r13, 0x8(%rsp)
movq 0x50(%r14), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x38(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x8e160
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x48c62
movq %rax, %r13
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x8d72b
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x8e039
movq %r13, %rdi
callq 0x8e188
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x8e192
movq 0x8(%r12), %rdi
addq $0x3, %rdi
movq %r13, %rsi
callq 0x46c0
testl %eax, %eax
je 0x48d90
movq 0x30(%r15), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x53f74(%rip), %r14     # 0x9ccd3
leaq 0x53f7a(%rip), %rdx     # 0x9cce0
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x14378
leaq 0x53f94(%rip), %rdx     # 0x9cd10
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x14378
jmp 0x48c62
movq 0x50(%r14), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rax
movl $0x1, 0x4c(%rax)
xorl %ebx, %ebx
jmp 0x48c62