// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
xorl %ebx, %ebx
cmpl $0x0, 0xa8(%rdi)
js 0x660ac
movq %rdi, %r14
movq 0xa0(%rdi), %rdi
testq %rdi, %rdi
je 0x660ac
addq $0x20, %rdi
callq 0x4750
movq 0xa0(%r14), %r15
cmpq $0x0, 0x10(%r15)
je 0x65c48
xorl %edi, %edi
callq 0x4450
addq $0x3c, %rax
cmpq 0x10(%r15), %rax
jge 0x65c62
movq 0xa0(%r14), %r15
cmpl $0x0, 0xa8(%r14)
jle 0x6605d
addq $0x20, %r15
movq %r15, %rdi
jmp 0x66092
cmpl $0x0, 0x18(%r15)
jne 0x66099
movq (%r15), %rdi
leaq 0x1cf83(%rip), %rsi     # 0x82bfa
xorl %eax, %eax
callq 0xe19b
testq %rax, %rax
je 0x65e32
movq %rax, %r12
leaq 0x60(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0xd4e0
testq %rax, %rax
js 0x65fc3
leaq 0x60(%rsp), %rdi
pushq $0x7b
popq %rbp
movl %ebp, %esi
movq %rax, %rdx
callq 0x4550
testq %rax, %rax
je 0x65e5c
movl %ebp, 0x4(%rsp)
callq 0x2b13a
movq %rax, %r13
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
pushq $0x69
popq %rax
testq %r13, %r13
je 0x65ef4
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2b3fb
cmpb $0x7b, %al
jne 0x65ef1
movq $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
callq 0x2b3fb
cmpb $0x7d, %al
je 0x66153
movq %r13, %rdi
callq 0x2b145
cmpb $0x73, %al
jne 0x65f82
movq %r13, %rdi
callq 0x2b14d
testq %rax, %rax
je 0x65f89
movq %rax, %rbp
movq %rax, %rdi
leaq 0x1cea0(%rip), %rsi     # 0x82bfd
callq 0x46c0
testl %eax, %eax
je 0x65da3
movq %rbp, %rdi
leaq 0x1ce9a(%rip), %rsi     # 0x82c0a
callq 0x46c0
testl %eax, %eax
je 0x65dc9
movq %rbp, %rdi
leaq 0x1ce92(%rip), %rsi     # 0x82c15
callq 0x46c0
movq %r12, %rdi
testl %eax, %eax
je 0x65def
xorl %esi, %esi
callq 0x2b7f6
cmpb $0x76, %al
je 0x65d17
jmp 0x65f82
movq %r12, %rdi
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
callq 0x2b3fb
cmpb $0x73, %al
jne 0x66232
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
pushq $0x73
jmp 0x65e10
movq %r12, %rdi
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
callq 0x2b3fb
cmpb $0x73, %al
jne 0x66232
movq 0x30(%rsp), %rax
pushq $0x73
popq %rcx
movl %ecx, 0x4(%rsp)
jmp 0x65e1a
movq %r13, %rsi
leaq 0x20(%rsp), %rdx
callq 0x2b3fb
cmpb $0x6e, %al
jne 0x66232
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
pushq $0x6e
popq %rax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
jmp 0x65d17
callq 0x4050
cmpl $0x2, (%rax)
jne 0x65e4f
andq $0x0, 0x10(%r15)
movq 0x8(%r15), %rdi
callq 0x45c0
jmp 0x6600c
movl $0x1, 0x18(%r15)
jmp 0x66099
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq -0x589de(%rip), %rsi    # 0xd4a0
movq %r12, %rdx
callq 0x8fc3
testl %eax, %eax
js 0x65f6c
leaq 0x20(%rsp), %rdi
movq (%rdi), %rsi
addq $0x2, %rsi
callq 0x66254
testl %eax, %eax
js 0x65f6c
movq %r12, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x20(%rsp)
xorl %edx, %edx
movb %dl, (%rcx,%rax)
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
movb %dl, (%rcx,%rax)
movq 0x30(%rsp), %r13
movb (%r13), %r12b
testb %r12b, %r12b
je 0x65f0a
movsbl %r12b, %edi
callq 0x665b1
testl %eax, %eax
je 0x65f0a
incq %r13
jmp 0x65ed6
movsbl %al, %eax
movl %eax, 0x4(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x18(%rsp)
xorl %edi, %edi
jmp 0x65f93
xorl %ebp, %ebp
testb %r12b, %r12b
je 0x65f28
movsbl %r12b, %edi
callq 0x665b1
testl %eax, %eax
jne 0x65f28
movb 0x1(%r13,%rbp), %r12b
incq %rbp
jmp 0x65f0c
movq %r13, %rax
addq %rbp, %rax
cmpq %r13, %rax
jbe 0x65fd8
leaq 0x1cce9(%rip), %rdi     # 0x82c27
leaq 0x40(%rsp), %rsi
callq 0x65b73
testl %eax, %eax
movq 0x18(%rsp), %r12
js 0x65f6c
leaq 0x40(%rsp), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x662a9
testl %eax, %eax
js 0x65f6c
movq 0x50(%rsp), %r12
jmp 0x65fdb
movq 0x30(%rsp), %rdi
callq 0x45c0
movq 0x50(%rsp), %rdi
callq 0x45c0
jmp 0x65fc3
pushq $0x3f
popq %rax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rdi
callq 0x45c0
movq %rbp, %rdi
callq 0x45c0
movq 0x18(%rsp), %rdi
callq 0x45c0
movq 0x30(%rsp), %rdi
callq 0x45c0
movq %r13, %rdi
callq 0x2b148
cmpl $0x76, 0x4(%rsp)
je 0x65ffc
movl $0x1, 0x18(%r15)
movq %r12, %rdi
callq 0xd94c
jmp 0x66099
xorl %r12d, %r12d
movq 0x8(%r15), %rdi
callq 0x45c0
movq %r12, 0x8(%r15)
andq $0x0, 0x10(%r15)
movq 0x30(%rsp), %rdi
callq 0x45c0
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0xd8ee
testl %eax, %eax
js 0x66099
movslq 0xa8(%r14), %r12
movq 0xa0(%r14), %r15
testq %r12, %r12
jle 0x6605d
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x660bd
callq 0x4930
testq %rax, %rax
je 0x66099
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 0x66087
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x66087
leaq 0x80(%r14), %rdi
pushq $0x1
popq %rdx
callq 0x653be
testl %eax, %eax
js 0x66099
movl 0x88(%r14), %eax
movl %eax, 0xa8(%r14)
movq 0xa0(%r14), %rdi
addq $0x20, %rdi
callq 0x4340
jmp 0x660ac
movq 0xa0(%r14), %rdi
addq $0x20, %rdi
callq 0x4340
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x70(%r14), %r15
leaq 0x80(%r14), %r13
movq 0x80(%r14), %rax
movq %r12, %rbp
shlq $0x4, %rbp
movq -0x10(%rax,%rbp), %rdi
callq 0x45c0
movl 0x88(%r14), %eax
cmpq %rax, %r12
jae 0x66117
movq (%r13), %rax
leal -0x1(%r12), %ecx
shlq $0x4, %rcx
movups (%rax,%rbp), %xmm0
movups %xmm0, (%rax,%rcx)
movq (%r13), %rax
leaq (%rax,%rbp), %rdx
movq %rdx, 0x8(%rax,%rcx)
incq %r12
addq $0x10, %rbp
jmp 0x660e0
movl %eax, %ecx
decl %ecx
movl %ecx, 0x88(%r14)
je 0x66129
addl $-0x2, %eax
jmp 0x66136
movl 0x78(%r14), %eax
testl %eax, %eax
je 0x66146
decl %eax
movq %r15, %r13
movq (%r13), %rcx
movl %eax, %eax
shlq $0x4, %rax
andq $0x0, 0x8(%rcx,%rax)
andl $0x0, 0xa8(%r14)
jmp 0x66087
cmpq $0x0, 0x10(%rsp)
je 0x66216
movq 0x8(%rsp), %rbp
testq %rbp, %rbp
je 0x66186
leaq 0x1cab0(%rip), %rsi     # 0x82c20
movq %rbp, %rdi
callq 0x46c0
testl %eax, %eax
je 0x66186
movq 0x10(%rsp), %rdi
jmp 0x6621d
leaq 0x20(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x1ca91(%rip), %rdi     # 0x82c27
callq 0x65b73
pushq $0x6d
popq %rbp
testl %eax, %eax
js 0x66229
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x65b73
testl %eax, %eax
js 0x66229
movq 0x8(%r15), %rdi
callq 0x45c0
movq 0x30(%rsp), %rax
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %rax, 0x8(%r15)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x6623a
pushq $0xa
popq %rdx
xorl %esi, %esi
movq %rdi, 0x18(%rsp)
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)
pushq $0x76
jmp 0x65f84
xorl %edi, %edi
movq 0x8(%rsp), %rbp
pushq $0x69
popq %rax
movl %eax, 0x4(%rsp)
jmp 0x65f93
movl %ebp, 0x4(%rsp)
jmp 0x65f89
movsbl %al, %eax
jmp 0x65f85
andq $0x0, 0x10(%r15)
pushq $0x76
popq %rax
movl %eax, 0x4(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x65f89