// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/vcf.c
// Function: bcf_hdr_add_hrec
int bcf_hdr_add_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec)
{
    kstring_t str = {0,0,0};
    bcf_hdr_aux_t *aux = get_hdr_aux(hdr);

    int res;
    if ( !hrec ) return 0;

    bcf_hrec_check(hrec);   // todo: check return status and propagate errors up

    res = bcf_hdr_register_hrec(hdr,hrec);
    if (res < 0) return -1;
    if ( !res )
    {
        // If one of the hashed field, then it is already present
        if ( hrec->type != BCF_HL_GEN )
        {
            bcf_hrec_destroy(hrec);
            return 0;
        }
        // Is one of the generic fields and already present?
        if ( ksprintf(&str, "##%s=%s", hrec->key,hrec->value) < 0 )
        {
            free(str.s);
            return -1;
        }
        khint_t k = kh_get(hdict, aux->gen, str.s);
        if ( k != kh_end(aux->gen) )
        {
            // duplicate record
            bcf_hrec_destroy(hrec);
            free(str.s);
            return 0;
        }
        if (!strcmp(hrec->key, "fileformat")) {
            aux->version = bcf_get_version(NULL, hrec->value);
        }
    }

    int i;
    if ( hrec->type==BCF_HL_STR && (i=bcf_hrec_find_key(hrec,"ID"))>=0 )
    {
        if ( ksprintf(&str, "##%s=<ID=%s>", hrec->key,hrec->vals[i]) < 0 )
        {
            free(str.s);
            return -1;
        }
        khint_t k = kh_get(hdict, aux->gen, str.s);
        if ( k != kh_end(aux->gen) )
        {
            // duplicate record
            bcf_hrec_destroy(hrec);
            free(str.s);
            return 0;
        }
    }

    // New record, needs to be added
    int n = hdr->nhrec + 1;
    bcf_hrec_t **new_hrec = realloc(hdr->hrec, n*sizeof(bcf_hrec_t*));
    if (!new_hrec) {
        free(str.s);
        bcf_hdr_unregister_hrec(hdr, hrec);
        return -1;
    }
    hdr->hrec = new_hrec;

    if ( str.s )
    {
        khint_t k = kh_put(hdict, aux->gen, str.s, &res);
        if ( res<0 )
        {
            free(str.s);
            return -1;
        }
        kh_val(aux->gen,k) = hrec;
    }

    hdr->hrec[hdr->nhrec] = hrec;
    hdr->dirty = 1;
    hdr->nhrec = n;

    return hrec->type==BCF_HL_GEN ? 0 : 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4240
movq -0x10(%rbp), %rdi
callq 0x3b020
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3ce70
movl $0x0, -0x4(%rbp)
jmp 0x3d111
movq -0x18(%rbp), %rdi
callq 0x3d120
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3d420
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x3ce9b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d111
cmpl $0x0, -0x3c(%rbp)
jne 0x3cf75
movq -0x18(%rbp), %rax
cmpl $0x5, (%rax)
je 0x3cec3
movq -0x18(%rbp), %rdi
callq 0x3b040
movl $0x0, -0x4(%rbp)
jmp 0x3d111
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
leaq -0x30(%rbp), %rdi
leaq 0xca8f4(%rip), %rsi     # 0x1077d2
movb $0x0, %al
callq 0xd62e0
cmpl $0x0, %eax
jge 0x3ceff
movq -0x20(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d111
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3df00
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpl (%rcx), %eax
je 0x3cf40
movq -0x18(%rbp), %rdi
callq 0x3b040
movq -0x20(%rbp), %rdi
callq 0x45a0
movl $0x0, -0x4(%rbp)
jmp 0x3d111
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xca88b(%rip), %rsi     # 0x1077da
callq 0x46b0
cmpl $0x0, %eax
jne 0x3cf73
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3cc20
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
jmp 0x3cf75
movq -0x18(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x3d025
movq -0x18(%rbp), %rdi
leaq 0xc900b(%rip), %rsi     # 0x105f98
callq 0x3bb40
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
jl 0x3d025
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq -0x30(%rbp), %rdi
leaq 0xca824(%rip), %rsi     # 0x1077e5
movb $0x0, %al
callq 0xd62e0
cmpl $0x0, %eax
jge 0x3cfe2
movq -0x20(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d111
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3df00
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpl (%rcx), %eax
je 0x3d023
movq -0x18(%rbp), %rdi
callq 0x3b040
movq -0x20(%rbp), %rdi
callq 0x45a0
movl $0x0, -0x4(%rbp)
jmp 0x3d111
jmp 0x3d025
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movslq -0x4c(%rbp), %rsi
shlq $0x3, %rsi
callq 0x4840
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x3d074
movq -0x20(%rbp), %rdi
callq 0x45a0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d111
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x3d0ce
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
callq 0x3c8c0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x3d0b7
movq -0x20(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d111
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x50(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movl $0x1, 0x54(%rax)
movl -0x4c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x5, %edx
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)