// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_index.c
// Function: cram_index_build_multiref
static int cram_index_build_multiref(cram_fd *fd,
                                     cram_container *c,
                                     cram_slice *s,
                                     BGZF *fp,
                                     off_t cpos,
                                     int32_t landmark,
                                     int sz) {
    int i, ref = -2;
    int64_t ref_start = 0, ref_end;
    char buf[1024];

    if (fd->mode != 'w') {
        if (0 != cram_decode_slice(fd, c, s, fd->header))
            return -1;
    }

    ref_end = INT_MIN;

    int32_t last_ref = -9;
    int32_t last_pos = -9;
    for (i = 0; i < s->hdr->num_records; i++) {
        if (s->crecs[i].ref_id == last_ref && s->crecs[i].apos < last_pos) {
            hts_log_error("CRAM file is not sorted by chromosome / position");
            return -2;
        }
        last_ref = s->crecs[i].ref_id;
        last_pos = s->crecs[i].apos;

        if (s->crecs[i].ref_id == ref) {
            if (ref_end < s->crecs[i].aend)
                ref_end = s->crecs[i].aend;
            continue;
        }

        if (ref != -2) {
            snprintf(buf, sizeof(buf),
                     "%d\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%d\t%d\n",
                     ref, ref_start, ref_end - ref_start + 1,
                     (int64_t)cpos, landmark, sz);
            if (bgzf_write(fp, buf, strlen(buf)) < 0)
                return -4;
        }

        ref = s->crecs[i].ref_id;
        ref_start = s->crecs[i].apos;
        ref_end   = s->crecs[i].aend;
    }

    if (ref != -2) {
        snprintf(buf, sizeof(buf),
                 "%d\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%d\t%d\n",
                 ref, ref_start, ref_end - ref_start + 1,
                 (int64_t)cpos, landmark, sz);
        if (bgzf_write(fp, buf, strlen(buf)) < 0)
            return -4;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0xfffffffe, -0x3c(%rbp) # imm = 0xFFFFFFFE
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x77, 0x8(%rax)
je 0x6ba0e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0x51f70
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x6ba0c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6bcf7
jmp 0x6ba0e
movq $-0x80000000, -0x50(%rbp) # imm = 0x80000000
movl $0xfffffff7, -0x454(%rbp) # imm = 0xFFFFFFF7
movl $0xfffffff7, -0x458(%rbp) # imm = 0xFFFFFFF7
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x18(%rcx), %eax
jge 0x6bc55
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x454(%rbp), %eax
jne 0x6bab1
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movslq -0x458(%rbp), %rcx
cmpq %rcx, %rax
jge 0x6bab1
movl $0x1, %edi
leaq 0x89016(%rip), %rsi     # 0xf4aad
leaq 0x88f8d(%rip), %rdx     # 0xf4a2b
movb $0x0, %al
callq 0x1b030
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x6bcf7
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x454(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movl %eax, -0x458(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0x6bb51
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x90, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x78(%rcx), %rax
jge 0x6bb4c
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movq 0x78(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x6bc47
cmpl $-0x2, -0x3c(%rbp)
je 0x6bbef
leaq -0x450(%rbp), %rdi
movl -0x3c(%rbp), %ecx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
subq -0x48(%rbp), %r9
addq $0x1, %r9
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %r10d
movl 0x10(%rbp), %eax
movl $0x400, %esi            # imm = 0x400
leaq 0x88de0(%rip), %rdx     # 0xf496c
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x47e0
movq -0x28(%rbp), %rax
movq %rax, -0x468(%rbp)
leaq -0x450(%rbp), %rax
movq %rax, -0x460(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x41b0
movq -0x468(%rbp), %rdi
movq -0x460(%rbp), %rsi
movq %rax, %rdx
callq 0xffb0
cmpq $0x0, %rax
jge 0x6bbed
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x6bcf7
jmp 0x6bbef
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movq 0x78(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6ba31
cmpl $-0x2, -0x3c(%rbp)
je 0x6bcf0
leaq -0x450(%rbp), %rdi
movl -0x3c(%rbp), %ecx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
subq -0x48(%rbp), %r9
addq $0x1, %r9
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %r10d
movl 0x10(%rbp), %eax
movl $0x400, %esi            # imm = 0x400
leaq 0x88cdc(%rip), %rdx     # 0xf496c
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x47e0
movq -0x28(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x450(%rbp), %rax
movq %rax, -0x470(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x41b0
movq -0x478(%rbp), %rdi
movq -0x470(%rbp), %rsi
movq %rax, %rdx
callq 0xffb0
cmpq $0x0, %rax
jge 0x6bcee
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x6bcf7
jmp 0x6bcf0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nopw %cs:(%rax,%rax)