// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x22c(%rax)
jne 0x5eee5
cmpl $0x0, -0x14(%rbp)
jl 0x5eee5
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rcx
cmpl 0x18(%rcx), %eax
jl 0x5eef1
movl $0x0, -0x4(%rbp)
jmp 0x5f0b2
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, 0x4c(%rax)
je 0x5ef17
movl $0x0, -0x4(%rbp)
jmp 0x5f0b2
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0x937a4(%rip), %rsi     # 0xf26ec
leaq 0x94a0e(%rip), %rdx     # 0xf395d
callq 0xd9960
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x5ef6b
movl $0x0, -0x4(%rbp)
jmp 0x5f0b2
movq -0x28(%rbp), %rdi
leaq 0x949ea(%rip), %rsi     # 0xf3960
xorl %eax, %eax
movl %eax, %edx
callq 0xdaf50
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x5ef96
movl $0x0, -0x4(%rbp)
jmp 0x5f0b2
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
callq 0xe18c0
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x5efe9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5f0b2
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0xe04d0
leaq -0x60(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xe1630
movq -0x48(%rbp), %rdi
callq 0xe1910
leaq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xe1940
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x3, %rdi
leaq -0x90(%rbp), %rsi
callq 0x4690
cmpl $0x0, %eax
je 0x5f090
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movl $0x1, %edi
leaq 0x95584(%rip), %rsi     # 0xf45e3
leaq 0x9558a(%rip), %rdx     # 0xf45f0
movb $0x0, %al
callq 0x1b030
movl $0x1, %edi
leaq 0x9556a(%rip), %rsi     # 0xf45e3
leaq 0x955a0(%rip), %rdx     # 0xf4620
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5f0b2
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x4c(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop