// File: /workspace/github_c_makefile_star2_O2/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 0x3ae99
movq %rdi, %r14
cmpl $0x0, 0x22c(%rdi)
jne 0x3ae99
movq 0x50(%r14), %rax
cmpl %esi, 0x18(%rax)
jle 0x3ae99
movq 0x10(%rax), %rax
movl %esi, %ebp
movq (%rax,%rbp,8), %rax
cmpl $0x0, 0x4c(%rax)
je 0x3aeaa
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
imulq $0x18, %rbp, %r13
movq (%rax,%r13), %rcx
leaq 0x404ad(%rip), %rsi     # 0x7b372
leaq 0x404a9(%rip), %rdx     # 0x7b375
movq %r15, %rdi
callq 0x6a8fd
testq %rax, %rax
je 0x3ae99
leaq 0x40498(%rip), %rsi     # 0x7b378
xorl %ebx, %ebx
movq %rax, %rdi
xorl %edx, %edx
callq 0x6b93e
testq %rax, %rax
je 0x3ae99
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 0x6ecda
pushq $-0x1
popq %rbx
testq %rax, %rax
je 0x3ae99
movq %rax, %r13
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x6e2bd
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x6ebc0
movq %r13, %rdi
callq 0x6ed04
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x6ed09
movq 0x8(%r12), %rdi
addq $0x3, %rdi
movq %r13, %rsi
callq 0x46c0
testl %eax, %eax
je 0x3afbb
movq 0x30(%r15), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rcx
leaq 0x40d1e(%rip), %r14     # 0x7bcab
leaq 0x40d24(%rip), %rdx     # 0x7bcb8
pushq $0x1
popq %rbp
movl %ebp, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x110c6
leaq 0x40d3e(%rip), %rdx     # 0x7bce8
movl %ebp, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x110c6
jmp 0x3ae99
movq 0x50(%r14), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rax
movl $0x1, 0x4c(%rax)
xorl %ebx, %ebx
jmp 0x3ae99