// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/hfile_libcurl.c
// Function: add_auth_header
static int add_auth_header(hFILE_libcurl *fp) {
    int changed = 0;

    if (fp->headers.auth_hdr_num < 0)
        return 0; // Have an Authorization header from open or header callback

    if (!fp->headers.auth)
        return 0; // Nothing to add

    pthread_mutex_lock(&fp->headers.auth->lock);
    if (renew_auth_token(fp->headers.auth, &changed) < 0)
        goto unlock_fail;

    if (!changed && fp->headers.auth_hdr_num > 0) {
        pthread_mutex_unlock(&fp->headers.auth->lock);
        return 0;
    }

    if (fp->headers.auth_hdr_num > 0) {
        // Had a previous header, so swap in the new one
        char *header = fp->headers.auth->token;
        char *header_copy = header ? strdup(header) : NULL;
        int idx = fp->headers.auth_hdr_num - 1;
        if (header && !header_copy)
            goto unlock_fail;

        if (header_copy) {
            free(fp->headers.extra.list[idx].data);
            fp->headers.extra.list[idx].data = header_copy;
        } else {
            unsigned int j;
            // More complicated case - need to get rid of the old header
            // and tidy up linked lists
            free(fp->headers.extra.list[idx].data);
            for (j = idx + 1; j < fp->headers.extra.num; j++) {
                fp->headers.extra.list[j - 1] = fp->headers.extra.list[j];
                fp->headers.extra.list[j - 1].next = &fp->headers.extra.list[j];
            }
            fp->headers.extra.num--;
            if (fp->headers.extra.num > 0) {
                fp->headers.extra.list[fp->headers.extra.num-1].next = NULL;
            } else if (fp->headers.fixed.num > 0) {
                fp->headers.fixed.list[fp->headers.fixed.num - 1].next = NULL;
            }
            fp->headers.auth_hdr_num = 0;
        }
    } else if (fp->headers.auth->token) {
        // Add new header and remember where it is
        if (append_header(&fp->headers.extra,
                          fp->headers.auth->token, 1) < 0) {
            goto unlock_fail;
        }
        fp->headers.auth_hdr_num = fp->headers.extra.num;
    }

    pthread_mutex_unlock(&fp->headers.auth->lock);
    return 0;

 unlock_fail:
    pthread_mutex_unlock(&fp->headers.auth->lock);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
xorl %ebx, %ebx
cmpl $0x0, 0xa8(%rdi)
js 0x80198
movq %rdi, %r14
movq 0xa0(%rdi), %rdi
testq %rdi, %rdi
je 0x80198
addq $0x20, %rdi
callq 0x4750
movq 0xa0(%r14), %r15
cmpq $0x0, 0x10(%r15)
je 0x7ff63
xorl %edi, %edi
callq 0x4450
addq $0x3c, %rax
cmpq 0x10(%r15), %rax
jge 0x7ff7d
movq 0xa0(%r14), %r15
cmpl $0x0, 0xa8(%r14)
jle 0x800e8
addq $0x20, %r15
movq %r15, %rdi
jmp 0x8011f
cmpl $0x0, 0x18(%r15)
jne 0x80183
movq (%r15), %rdi
leaq 0x21378(%rip), %rsi     # 0xa130a
xorl %eax, %eax
callq 0xfe44
testq %rax, %rax
je 0x80046
movq %rax, %r12
leaq 0x50(%rsp), %rsi
movl $0x10, %edx
movq %rax, %rdi
callq 0xf0a9
testq %rax, %rax
js 0x80173
leaq 0x50(%rsp), %rdi
movl $0x7b, %esi
movq %rax, %rdx
callq 0x4550
testq %rax, %rax
je 0x80070
callq 0x34d61
movq %rax, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rax, %rax
je 0x80029
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x350a9
cmpb $0x7b, %al
jne 0x80126
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x350a9
cmpb $0x7d, %al
jne 0x80225
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x69, %r13d
jmp 0x8013c
callq 0x4050
cmpl $0x2, (%rax)
jne 0x80063
movq $0x0, 0x10(%r15)
movq 0x8(%r15), %rdi
callq 0x45c0
jmp 0x80093
movl $0x1, 0x18(%r15)
jmp 0x80183
movq %r15, %rdi
movq %r12, %rsi
callq 0x80862
testl %eax, %eax
js 0x80173
movq %r12, %rdi
callq 0xf4df
testl %eax, %eax
js 0x80183
movslq 0xa8(%r14), %r12
movq 0xa0(%r14), %r15
testq %r12, %r12
jle 0x800e8
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x801a9
callq 0x4930
testq %rax, %rax
je 0x80183
movq %rax, %r15
decl %r12d
movq 0x80(%r14), %rax
shlq $0x4, %r12
movq (%rax,%r12), %rdi
callq 0x45c0
movq 0x80(%r14), %rax
movq %r15, (%rax,%r12)
jmp 0x80114
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x80114
leaq 0x80(%r14), %rdi
movl $0x1, %edx
callq 0x7f2be
testl %eax, %eax
js 0x80183
movl 0x88(%r14), %eax
movl %eax, 0xa8(%r14)
movq 0xa0(%r14), %rdi
addq $0x20, %rdi
callq 0x4340
jmp 0x80198
movsbl %al, %r13d
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
xorl %edi, %edi
callq 0x45c0
movq 0x48(%rsp), %rdi
callq 0x45c0
movq 0x40(%rsp), %rdi
callq 0x45c0
movq 0x20(%rsp), %rdi
callq 0x45c0
movq %rbp, %rdi
callq 0x34d73
cmpl $0x76, %r13d
je 0x80083
movl $0x1, 0x18(%r15)
movq %r12, %rdi
callq 0xf53f
movq 0xa0(%r14), %rdi
addq $0x20, %rdi
callq 0x4340
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x80(%r14), %r15
movq 0x80(%r14), %rax
movq %r12, %r13
shlq $0x4, %r13
movq -0x10(%rax,%r13), %rdi
callq 0x45c0
movl 0x88(%r14), %eax
cmpl %eax, %r12d
jae 0x8020c
movq (%r15), %rcx
leal -0x1(%r12), %eax
shlq $0x4, %rax
movups (%rcx,%r13), %xmm0
movups %xmm0, (%rcx,%rax)
movq 0x80(%r14), %rcx
leaq (%rcx,%r13), %rdx
movq %rdx, 0x8(%rcx,%rax)
incq %r12
movl 0x88(%r14), %eax
addq $0x10, %r13
cmpq %rax, %r12
jb 0x801d7
movl %eax, %ecx
decl %ecx
movl %ecx, 0x88(%r14)
je 0x8040b
addl $-0x2, %eax
jmp 0x80419
movl $0x7b, 0x3c(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq %rbp, 0x30(%rsp)
movl $0x3f, %r13d
movq %rbp, %rdi
callq 0x34d70
cmpb $0x73, %al
jne 0x8044b
movq %rbp, %rdi
callq 0x34d78
testq %rax, %rax
je 0x8043b
movq %rax, %rbp
movq %rax, %rdi
leaq 0x2108c(%rip), %rsi     # 0xa130d
callq 0x46c0
testl %eax, %eax
je 0x802d1
movq %rbp, %rdi
leaq 0x21086(%rip), %rsi     # 0xa131a
callq 0x46c0
testl %eax, %eax
je 0x802fd
movq %rbp, %rdi
leaq 0x2107e(%rip), %rsi     # 0xa1325
callq 0x46c0
movq %r12, %rdi
testl %eax, %eax
je 0x8032e
xorl %esi, %esi
callq 0x3595d
cmpb $0x76, %al
movq 0x30(%rsp), %rbp
movq 0x8(%rsp), %rdi
je 0x80370
jmp 0x8013e
movq %r12, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x350a9
cmpb $0x73, %al
jne 0x80447
movl $0x73, 0x3c(%rsp)
movq 0x20(%rsp), %rdi
jmp 0x8035f
movq %r12, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x350a9
cmpb $0x73, %al
jne 0x80447
movl $0x73, 0x3c(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x8035a
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x350a9
cmpb $0x6e, %al
jne 0x80447
movl $0x6e, 0x3c(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %rdi, 0x8(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x350a9
cmpb $0x7d, %al
jne 0x80253
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x80455
cmpq $0x0, 0x48(%rsp)
je 0x803c1
leaq 0x20f86(%rip), %rsi     # 0xa1330
movq 0x48(%rsp), %rdi
callq 0x46c0
movq 0x8(%rsp), %rdi
testl %eax, %eax
jne 0x80457
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rax
cmpq $0x17, 0x18(%rsp)
ja 0x80462
movl $0x24, %esi
movq %rax, %rdi
callq 0x4840
testq %rax, %rax
je 0x804fe
movq %rax, 0x20(%rsp)
movq $0x24, 0x18(%rsp)
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdi
jmp 0x80464
movl 0x78(%r14), %eax
testl %eax, %eax
je 0x8042b
leaq 0x70(%r14), %r15
decl %eax
movq (%r15), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq $0x0, 0x8(%rcx,%rax)
movl $0x0, 0xa8(%r14)
jmp 0x80114
movl 0x3c(%rsp), %r13d
movq 0x30(%rsp), %rbp
jmp 0x8044b
movsbl %al, %r13d
movq 0x8(%rsp), %rdi
jmp 0x8013e
xorl %edi, %edi
movl $0x69, %r13d
jmp 0x8013e
xorl %ecx, %ecx
movups 0x20ecc(%rip), %xmm0    # 0xa1337
movups %xmm0, (%rax,%rcx)
movabsq $0x2072657261654220, %rdx # imm = 0x2072657261654220
movq %rdx, 0xe(%rax,%rcx)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x16(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x0, 0x16(%rcx,%rax)
callq 0x41d0
movq 0x10(%rsp), %rdi
leaq (%rax,%rdi), %rsi
addq $0x2, %rsi
cmpq %rdi, %rsi
jbe 0x804f3
movq %rax, %r13
cmpq %rsi, 0x18(%rsp)
jae 0x80509
movq %rsi, %rcx
shrq $0x3e, %rcx
movq %rsi, %rdx
shrq %rdx
xorl %ebp, %ebp
testq %rcx, %rcx
cmoveq %rdx, %rbp
addq %rsi, %rbp
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x804fe
movq %rax, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
movq 0x10(%rsp), %rdi
jmp 0x8050e
callq 0x4050
movl $0x4b, (%rax)
movl $0x6d, %r13d
jmp 0x80440
movq 0x20(%rsp), %rax
addq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rbp
movq %r13, %rdx
callq 0x43c0
movq 0x10(%rsp), %rax
addq %r13, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl $0x6d, %r13d
testl %ebp, %ebp
js 0x80440
movq 0x8(%r15), %rdi
callq 0x45c0
movq 0x20(%rsp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %rax, 0x8(%r15)
cmpq $0x0, 0x40(%rsp)
je 0x805a7
xorl %r13d, %r13d
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x46d0
movq %rax, %rbp
testq %rax, %rax
cmovleq %r13, %rbp
xorl %edi, %edi
callq 0x4450
addq %rbp, %rax
movq %rax, 0x10(%r15)
movl $0x76, %r13d
jmp 0x80440
movq $0x0, 0x10(%r15)
movl $0x76, %r13d
movq $0x0, 0x40(%rsp)
jmp 0x80440