// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: old_sam_hdr_change_HD
static int old_sam_hdr_change_HD(sam_hdr_t *h, const char *key, const char *val)
{
    char *p, *q, *beg = NULL, *end = NULL, *newtext;
    size_t new_l_text;
    if (!h || !key)
        return -1;

    if (h->l_text > 3) {
        if (strncmp(h->text, "@HD", 3) == 0) { //@HD line exists
            if ((p = strchr(h->text, '\n')) == 0) return -1;
            *p = '\0'; // for strstr call

            char tmp[5] = { '\t', key[0], key[0] ? key[1] : '\0', ':', '\0' };

            if ((q = strstr(h->text, tmp)) != 0) { // key exists
                *p = '\n'; // change back

                // mark the key:val
                beg = q;
                for (q += 4; *q != '\n' && *q != '\t'; ++q);
                end = q;

                if (val && (strncmp(beg + 4, val, end - beg - 4) == 0)
                    && strlen(val) == end - beg - 4)
                     return 0; // val is the same, no need to change

            } else {
                beg = end = p;
                *p = '\n';
            }
        }
    }
    if (beg == NULL) { // no @HD
        new_l_text = h->l_text;
        if (new_l_text > SIZE_MAX - strlen(SAM_FORMAT_VERSION) - 9)
            return -1;
        new_l_text += strlen(SAM_FORMAT_VERSION) + 8;
        if (val) {
            if (new_l_text > SIZE_MAX - strlen(val) - 5)
                return -1;
            new_l_text += strlen(val) + 4;
        }
        newtext = (char*)malloc(new_l_text + 1);
        if (!newtext) return -1;

        if (val)
            snprintf(newtext, new_l_text + 1,
                    "@HD\tVN:%s\t%s:%s\n%s", SAM_FORMAT_VERSION, key, val, h->text);
        else
            snprintf(newtext, new_l_text + 1,
                    "@HD\tVN:%s\n%s", SAM_FORMAT_VERSION, h->text);
    } else { // has @HD but different or no key
        new_l_text = (beg - h->text) + (h->text + h->l_text - end);
        if (val) {
            if (new_l_text > SIZE_MAX - strlen(val) - 5)
                return -1;
            new_l_text += strlen(val) + 4;
        }
        newtext = (char*)malloc(new_l_text + 1);
        if (!newtext) return -1;

        if (val) {
            snprintf(newtext, new_l_text + 1, "%.*s\t%s:%s%s",
                    (int) (beg - h->text), h->text, key, val, end);
        } else { //delete key
            snprintf(newtext, new_l_text + 1, "%.*s%s",
                    (int) (beg - h->text), h->text, end);
        }
    }
    free(h->text);
    h->text = newtext;
    h->l_text = new_l_text;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x39205
cmpq $0x0, -0x18(%rbp)
jne 0x39211
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
movq -0x10(%rbp), %rax
cmpq $0x3, 0x8(%rax)
jbe 0x393a5
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
leaq 0xb97a0(%rip), %rsi     # 0xf29cf
movl $0x3, %edx
callq 0x4200
cmpl $0x0, %eax
jne 0x393a3
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0xa, %esi
callq 0x4170
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x3926a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movb $0x9, -0x55(%rbp)
movq -0x18(%rbp), %rax
movb (%rax), %al
movb %al, -0x54(%rbp)
leaq -0x55(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x392a3
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0x64(%rbp)
jmp 0x392aa
xorl %eax, %eax
movl %eax, -0x64(%rbp)
jmp 0x392aa
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movb %cl, (%rax)
movb $0x3a, -0x52(%rbp)
movb $0x0, -0x51(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
leaq -0x55(%rbp), %rsi
callq 0x40c0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x3938e
movq -0x28(%rbp), %rax
movb $0xa, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x65(%rbp)
je 0x39316
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x9, %eax
setne %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x3931f
jmp 0x3932f
jmp 0x39321
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x392f5
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3938c
movq -0x38(%rbp), %rdi
addq $0x4, %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
subq %rax, %rdx
subq $0x4, %rdx
callq 0x4200
cmpl $0x0, %eax
jne 0x3938c
movq -0x20(%rbp), %rdi
callq 0x41b0
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rdx
subq %rdx, %rcx
subq $0x4, %rcx
cmpq %rcx, %rax
jne 0x3938c
movl $0x0, -0x4(%rbp)
jmp 0x39618
jmp 0x393a1
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movb $0xa, (%rax)
jmp 0x393a3
jmp 0x393a5
cmpq $0x0, -0x38(%rbp)
jne 0x394be
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $-0xd, -0x50(%rbp)
jbe 0x393cf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
movq -0x50(%rbp), %rax
addq $0xb, %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3942e
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0x41b0
movq %rax, %rdx
movq -0x70(%rbp), %rax
movq $-0x1, %rcx
subq %rdx, %rcx
subq $0x5, %rcx
cmpq %rcx, %rax
jbe 0x39419
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
movq -0x20(%rbp), %rdi
callq 0x41b0
addq $0x4, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
addq $0x1, %rdi
callq 0x4650
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x39452
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
cmpq $0x0, -0x20(%rbp)
je 0x39490
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
leaq 0xb9557(%rip), %rdx     # 0xf29d3
leaq 0xb9563(%rip), %rcx     # 0xf29e6
movq %rax, (%rsp)
movb $0x0, %al
callq 0x47e0
jmp 0x394b9
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %r8
leaq 0xb953f(%rip), %rdx     # 0xf29ea
leaq 0xb9534(%rip), %rcx     # 0xf29e6
movb $0x0, %al
callq 0x47e0
jmp 0x395ec
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
addq 0x8(%rdx), %rcx
movq -0x40(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3953e
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
callq 0x41b0
movq %rax, %rdx
movq -0x78(%rbp), %rax
movq $-0x1, %rcx
subq %rdx, %rcx
subq $0x5, %rcx
cmpq %rcx, %rax
jbe 0x39529
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
movq -0x20(%rbp), %rdi
callq 0x41b0
addq $0x4, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
addq $0x1, %rdi
callq 0x4650
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x39562
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x39618
cmpq $0x0, -0x20(%rbp)
je 0x395b3
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %r8
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %r10
movq -0x40(%rbp), %rax
leaq 0xb9456(%rip), %rdx     # 0xf29f7
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x47e0
jmp 0x395ea
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %r8
movq -0x40(%rbp), %r9
leaq 0xb9421(%rip), %rdx     # 0xf2a04
movb $0x0, %al
callq 0x47e0
jmp 0x395ec
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x45a0
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)