// File: /workspace/github_c_makefile_star2_O1/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 %ebp, %ebp
cmpl $0x0, 0xa8(%rdi)
js 0x8285b
movq %rdi, %rbx
movq 0xa0(%rdi), %rdi
testq %rdi, %rdi
je 0x8285b
addq $0x20, %rdi
callq 0x4750
movq 0xa0(%rbx), %r15
movb $0x1, %bpl
cmpq $0x0, 0x10(%r15)
je 0x826c3
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x4450
addq $0x3c, %rax
cmpq 0x10(%r15), %rax
jl 0x826c6
movb $0x1, %r14b
cmpl $0x0, 0x18(%r15)
je 0x8248a
movb $0x1, %bpl
jmp 0x826c6
movq (%r15), %rdi
leaq 0x216e6(%rip), %rsi     # 0xa3b7a
xorl %eax, %eax
callq 0x10014
movq %rax, %r12
testq %rax, %rax
je 0x826a2
leaq 0x50(%rsp), %rsi
movl $0x10, %edx
movq %r12, %rdi
callq 0xf24d
testq %rax, %rax
js 0x828d5
leaq 0x50(%rsp), %rdi
movl $0x7b, %esi
movq %rax, %rdx
callq 0x4550
testq %rax, %rax
je 0x827f0
callq 0x36172
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rax, %rax
je 0x8286c
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x364be
cmpb $0x7b, %al
jne 0x82881
movl $0x7b, 0x8(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, %rdi
movq %r13, %rsi
leaq 0x10(%rsp), %rdx
callq 0x364be
cmpb $0x7d, %al
je 0x828f1
movq %r13, %rdi
callq 0x36181
cmpb $0x73, %al
jne 0x825cd
movq %r13, %rdi
movq %rbp, %r13
callq 0x36189
testq %rax, %rax
je 0x825dc
movq %rax, %rbp
movq %rax, %rdi
leaq 0x21604(%rip), %rsi     # 0xa3b7d
callq 0x46c0
testl %eax, %eax
je 0x825e6
movq %rbp, %rdi
leaq 0x215fe(%rip), %rsi     # 0xa3b8a
callq 0x46c0
testl %eax, %eax
je 0x8260f
movq %rbp, %rdi
leaq 0x215f6(%rip), %rsi     # 0xa3b95
callq 0x46c0
movq %r12, %rdi
testl %eax, %eax
je 0x82647
xorl %esi, %esi
callq 0x36d24
cmpb $0x76, %al
sete %al
movl 0x8(%rsp), %ecx
movl $0x3f, %edx
cmovnel %edx, %ecx
movl %ecx, 0x8(%rsp)
jmp 0x825de
movl $0x3f, 0x8(%rsp)
xorl %eax, %eax
jmp 0x82695
xorl %eax, %eax
movq %r13, %rbp
jmp 0x82690
movq %r12, %rdi
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x364be
cmpb $0x73, %al
movq %r13, %rbp
jne 0x82687
movq 0x20(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x8262a
movq %r12, %rdi
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x364be
cmpb $0x73, %al
jne 0x82684
movq 0x20(%rsp), %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x1, %al
movl $0x73, 0x8(%rsp)
jmp 0x82690
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x364be
cmpb $0x6e, %al
movq %r13, %rbp
jne 0x82687
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x1, %al
movl $0x6e, 0x8(%rsp)
jmp 0x82690
movq %r13, %rbp
movsbl %al, %eax
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movq 0x30(%rsp), %r13
testb %al, %al
jne 0x82538
jmp 0x8289c
callq 0x4050
cmpl $0x2, (%rax)
jne 0x828d5
movq $0x0, 0x10(%r15)
movq 0x8(%r15), %rdi
callq 0x45c0
xorl %ebp, %ebp
xorl %r14d, %r14d
testb %r14b, %r14b
je 0x826d5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x8284b
testb %bpl, %bpl
je 0x826e7
cmpl $0x0, 0xa8(%rbx)
jg 0x82849
movslq 0xa8(%rbx), %r12
movq 0xa0(%rbx), %rax
movq 0x8(%rax), %r15
testq %r12, %r12
jle 0x82710
testq %r15, %r15
je 0x82744
movq %r15, %rdi
callq 0x4930
movq %rax, %r14
jmp 0x82747
xorl %ebp, %ebp
testq %r15, %r15
je 0x8284b
leaq 0x80(%rbx), %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x81883
testl %eax, %eax
js 0x826cb
movl 0x88(%rbx), %eax
movl %eax, 0xa8(%rbx)
jmp 0x8284b
xorl %r14d, %r14d
testq %r15, %r15
sete %al
testq %r14, %r14
setne %bpl
orb %al, %bpl
cmpb $0x1, %bpl
jne 0x826cb
leaq -0x1(%r12), %r13
leaq 0x80(%rbx), %r15
movq 0x80(%rbx), %rax
shlq $0x4, %r13
movq (%rax,%r13), %rdi
callq 0x45c0
testq %r14, %r14
je 0x82792
movq (%r15), %rax
movq %r14, (%rax,%r13)
jmp 0x82840
movl 0x88(%rbx), %eax
cmpl %eax, %r12d
jae 0x827df
movl %r12d, %ecx
movq %rcx, %rdx
shlq $0x4, %rdx
movq 0x80(%rbx), %rax
leal -0x1(%rcx), %esi
shlq $0x4, %rsi
movups (%rax,%rdx), %xmm0
movups %xmm0, (%rax,%rsi)
movq 0x80(%rbx), %rax
leaq (%rax,%rdx), %rdi
movq %rdi, 0x8(%rax,%rsi)
incq %rcx
movl 0x88(%rbx), %eax
addq $0x10, %rdx
cmpq %rax, %rcx
jb 0x827a7
movl %eax, %ecx
decl %ecx
movl %ecx, 0x88(%rbx)
je 0x82817
addl $-0x2, %eax
jmp 0x82824
movq %r15, %rdi
movq %r12, %rsi
callq 0x82da9
testl %eax, %eax
js 0x828d5
movq %r12, %rdi
callq 0xf6d0
movl %eax, %r14d
shrl $0x1f, %r14d
jmp 0x828ea
movl 0x78(%rbx), %eax
testl %eax, %eax
je 0x82836
leaq 0x70(%rbx), %r15
decl %eax
movq (%r15), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq $0x0, 0x8(%rcx,%rax)
movl $0x0, 0xa8(%rbx)
testb %bpl, %bpl
je 0x826cb
xorl %ebp, %ebp
movq 0xa0(%rbx), %rdi
addq $0x20, %rdi
callq 0x4340
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
movq $0x0, 0x40(%rsp)
movl $0x69, 0x8(%rsp)
jmp 0x82893
movsbl %al, %eax
movl %eax, 0x8(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rdi
callq 0x45c0
movq %rbp, %rdi
callq 0x45c0
movq 0x40(%rsp), %rdi
callq 0x45c0
movq 0x20(%rsp), %rdi
callq 0x45c0
movq %r13, %rdi
callq 0x36184
cmpl $0x76, 0x8(%rsp)
je 0x82803
movl $0x1, 0x18(%r15)
testq %r12, %r12
je 0x828ea
movq %r12, %rdi
callq 0xf730
xorl %ebp, %ebp
jmp 0x826c6
cmpq $0x0, 0x38(%rsp)
je 0x82911
testq %rbp, %rbp
je 0x8291b
leaq 0x2129b(%rip), %rsi     # 0xa3ba0
movq %rbp, %rdi
callq 0x46c0
testl %eax, %eax
je 0x8291b
movl $0x69, 0x8(%rsp)
jmp 0x8289c
movq $0x0, 0x10(%rsp)
cmpq $0x17, 0x18(%rsp)
ja 0x82952
movq 0x20(%rsp), %rdi
movl $0x24, %esi
callq 0x4840
testq %rax, %rax
je 0x82aa9
movq %rax, 0x20(%rsp)
movq $0x24, 0x18(%rsp)
movq %rbp, 0x48(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movups 0x2123f(%rip), %xmm0    # 0xa3ba7
movups %xmm0, (%rcx,%rax)
movabsq $0x2072657261654220, %rdx # imm = 0x2072657261654220
movq %rdx, 0xe(%rcx,%rax)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x16(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb $0x0, 0x16(%rcx,%rax)
movq 0x38(%rsp), %rdi
callq 0x41d0
movq %rax, %rbp
movq 0x10(%rsp), %rcx
addq %rcx, %rax
addq $0x2, %rax
cmpq %rcx, %rax
jbe 0x82a94
cmpq %rax, 0x18(%rsp)
jae 0x829fc
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %esi, %esi
testq %rcx, %rcx
cmoveq %rdx, %rsi
addq %rax, %rsi
movq 0x20(%rsp), %rdi
movq %rsi, 0x8(%rsp)
callq 0x4840
testq %rax, %rax
je 0x82a9f
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
addq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %rbp, %rdx
callq 0x43c0
movq 0x10(%rsp), %rax
addq %rbp, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl $0x6d, 0x8(%rsp)
testl %ebp, %ebp
js 0x82ac6
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 0x82ab6
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x46d0
movq %rax, %rbp
testq %rax, %rax
movl $0x0, %eax
cmovleq %rax, %rbp
xorl %edi, %edi
callq 0x4450
addq %rbp, %rax
movq %rax, 0x10(%r15)
jmp 0x82abe
callq 0x4050
movl $0x4b, (%rax)
movl $0x6d, 0x8(%rsp)
jmp 0x82ac6
movl $0x6d, 0x8(%rsp)
jmp 0x8289c
movq $0x0, 0x10(%r15)
movl $0x76, 0x8(%rsp)
movq 0x48(%rsp), %rbp
jmp 0x8289c