// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_encode.c
// Function: add_read_names
static int add_read_names(cram_fd *fd, cram_container *c, cram_slice *s,
                          int bam_start) {
    int r1, r2;
    int keep_names = !fd->lossy_read_names;

    for (r1 = bam_start, r2 = 0;
         r1 < c->curr_c_rec && r2 < s->hdr->num_records;
         r1++, r2++) {
        cram_record *cr = &s->crecs[r2];
        bam_seq_t *b = c->bams[r1];

        cr->name        = BLOCK_SIZE(s->name_blk);
        if ((cr->cram_flags & CRAM_FLAG_DETACHED) || keep_names) {
            if (CRAM_MAJOR_VERS(fd->version) >= 4
                && (cr->cram_flags & CRAM_FLAG_MATE_DOWNSTREAM)
                && cr->mate_line) {
                // Dedup read names in V4
                BLOCK_APPEND(s->name_blk, "\0", 1);
                cr->name_len    = 1;
            } else {
                BLOCK_APPEND(s->name_blk, bam_name(b), bam_name_len(b));
                cr->name_len    = bam_name_len(b);
            }
        } else {
            // Can only discard duplicate names if not detached
            cr->name_len = 0;
        }

        if (cram_stats_add(c->stats[DS_RN], cr->name_len) < 0)
            goto block_err;
    }

    return 0;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x897c(%rax)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x28(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x70(%rdx), %ecx
movb %al, -0x41(%rbp)
jge 0x61800
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x18(%rcx), %eax
setl %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x6180c
jmp 0x61952
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0xf0(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x6186b
cmpl $0x0, -0x30(%rbp)
je 0x6190f
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x4, %eax
jl 0x618c3
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x618c3
movq -0x38(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x618c3
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rdi
leaq 0x926f2(%rip), %rsi     # 0xf3f94
movl $0x1, %edx
callq 0x5c2b0
cmpl $0x0, %eax
jge 0x618b6
jmp 0x6195b
movq -0x38(%rbp), %rax
movl $0x1, 0x28(%rax)
jmp 0x6190d
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %eax
movq -0x40(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
subl %ecx, %eax
movslq %eax, %rdx
callq 0x5c2b0
cmpl $0x0, %eax
jge 0x618f4
jmp 0x6195b
movq -0x40(%rbp), %rax
movzwl 0x12(%rax), %ecx
movq -0x40(%rbp), %rax
movzbl 0xf(%rax), %eax
subl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x6191a
movq -0x38(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rdi
movq -0x38(%rbp), %rax
movslq 0x28(%rax), %rsi
callq 0x7ec30
cmpl $0x0, %eax
jge 0x61939
jmp 0x6195b
jmp 0x6193b
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x617dc
movl $0x0, -0x4(%rbp)
jmp 0x61962
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)