// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jge 0xd146c
movl $0x0, -0x4(%rbp)
jmp 0xd1769
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa0(%rax)
jne 0xd1486
movl $0x0, -0x4(%rbp)
jmp 0xd1769
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
addq $0x20, %rdi
callq 0x4730
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
leaq -0x14(%rbp), %rsi
callq 0xd1e30
cmpl $0x0, %eax
jge 0xd14b8
jmp 0xd174e
cmpl $0x0, -0x14(%rbp)
jne 0xd14eb
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jle 0xd14eb
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
addq $0x20, %rdi
callq 0x4330
movl $0x0, -0x4(%rbp)
jmp 0xd1769
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jle 0xd16dd
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xd1525
movq -0x20(%rbp), %rdi
callq 0x4920
movq %rax, -0x38(%rbp)
jmp 0xd152d
xorl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0xd152d
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xd1558
cmpq $0x0, -0x28(%rbp)
jne 0xd1558
jmp 0xd174e
cmpq $0x0, -0x28(%rbp)
je 0xd159f
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x45a0
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
jmp 0xd16db
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x45a0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x88(%rcx), %eax
jae 0xd1653
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rcx
movl -0x30(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
movl -0x30(%rbp), %eax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movl -0x30(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xd15c6
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x88(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x88(%rax)
jbe 0xd169e
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x88(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0xd16cd
movq -0x10(%rbp), %rax
cmpl $0x0, 0x78(%rax)
jbe 0xd16cb
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x78(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0xd16cd
movq -0x10(%rbp), %rax
movl $0x0, 0xa8(%rax)
jmp 0xd1731
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0xd172f
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rax
movq 0x8(%rax), %rsi
movl $0x1, %edx
callq 0xcfc70
cmpl $0x0, %eax
jge 0xd171b
jmp 0xd174e
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xa8(%rax)
jmp 0xd1731
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
addq $0x20, %rdi
callq 0x4330
movl $0x0, -0x4(%rbp)
jmp 0xd1769
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
addq $0x20, %rdi
callq 0x4330
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)