// File: /workspace/github_c_makefile_star2_O3/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 0x464fa
movq %rdi, %r14
cmpl $0x0, 0x22c(%rdi)
jne 0x464fa
movq 0x50(%r14), %rax
cmpl %esi, 0x18(%rax)
jle 0x464fa
movq 0x10(%rax), %rax
movl %esi, %ebp
movq (%rax,%rbp,8), %rax
cmpl $0x0, 0x4c(%rax)
je 0x4650b
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 0x52ed5(%rip), %rsi     # 0x99402
leaq 0x52ed1(%rip), %rdx     # 0x99405
movq %r15, %rdi
callq 0x85b55
testq %rax, %rax
je 0x464fa
leaq 0x52ec0(%rip), %rsi     # 0x99408
xorl %ebx, %ebx
movq %rax, %rdi
xorl %edx, %edx
callq 0x872e1
testq %rax, %rax
je 0x464fa
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 0x8b777
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x464fa
movq %rax, %r13
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x8ad49
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x8b650
movq %r13, %rdi
callq 0x8b7a1
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x8b7ab
movq 0x8(%r12), %rdi
addq $0x3, %rdi
movq %r13, %rsi
callq 0x46c0
testl %eax, %eax
je 0x46628
movq 0x30(%r15), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x5373c(%rip), %r14     # 0x99d33
leaq 0x53742(%rip), %rdx     # 0x99d40
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x13de5
leaq 0x5375c(%rip), %rdx     # 0x99d70
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x13de5
jmp 0x464fa
movq 0x50(%r14), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rax
movl $0x1, 0x4c(%rax)
xorl %ebx, %ebx
jmp 0x464fa