// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hfile_libcurl.c
// Function: add_callback_headers
static int add_callback_headers(hFILE_libcurl *fp) {
    char **hdrs = NULL, **hdr;

    if (!fp->headers.callback)
        return 0;

    // Get the headers from the callback
    if (fp->headers.callback(fp->headers.callback_data, &hdrs) != 0) {
        return -1;
    }

    if (!hdrs) // No change
        return 0;

    // Remove any old callback headers
    if (fp->headers.fixed.num > 0) {
        // Unlink lists
        fp->headers.fixed.list[fp->headers.fixed.num - 1].next = NULL;
    }
    free_headers(&fp->headers.extra, 0);

    if (fp->headers.auth_hdr_num > 0 || fp->headers.auth_hdr_num == -2)
        fp->headers.auth_hdr_num = 0; // Just removed it...

    // Convert to libcurl-suitable form
    for (hdr = hdrs; *hdr; hdr++) {
        if (append_header(&fp->headers.extra, *hdr, 0) < 0) {
            goto cleanup;
        }
        if (is_authorization(*hdr) && !fp->headers.auth_hdr_num)
            fp->headers.auth_hdr_num = -2;
    }
    for (hdr = hdrs; *hdr; hdr++) *hdr = NULL;

    if (fp->headers.fixed.num > 0 && fp->headers.extra.num > 0) {
        // Relink lists
        fp->headers.fixed.list[fp->headers.fixed.num - 1].next
            = &fp->headers.extra.list[0];
    }
    return 0;

 cleanup:
    while (hdr && *hdr) {
        free(*hdr);
        *hdr = NULL;
    }
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0xcfe4e
movl $0x0, -0x4(%rbp)
jmp 0xd0022
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rdi
leaq -0x18(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0xcfe7b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd0022
cmpq $0x0, -0x18(%rbp)
jne 0xcfe8e
movl $0x0, -0x4(%rbp)
jmp 0xd0022
movq -0x10(%rbp), %rax
cmpl $0x0, 0x78(%rax)
jbe 0xcfebb
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)
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
addq $0x10, %rdi
xorl %esi, %esi
callq 0xd0d20
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jg 0xcfee8
movq -0x10(%rbp), %rax
cmpl $-0x2, 0xa8(%rax)
jne 0xcfef6
movq -0x10(%rbp), %rax
movl $0x0, 0xa8(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0xcff68
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
xorl %edx, %edx
callq 0xcfc70
cmpl $0x0, %eax
jge 0xcff2c
jmp 0xcffdd
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xd0dd0
cmpl $0x0, %eax
je 0xcff58
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0xcff58
movq -0x10(%rbp), %rax
movl $0xfffffffe, 0xa8(%rax) # imm = 0xFFFFFFFE
jmp 0xcff5a
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
jmp 0xcfefe
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0xcff93
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
jmp 0xcff70
movq -0x10(%rbp), %rax
cmpl $0x0, 0x78(%rax)
jbe 0xcffd4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x88(%rax)
jbe 0xcffd4
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rdx
movl 0x78(%rdx), %edx
subl $0x1, %edx
movl %edx, %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xd0022
jmp 0xcffdf
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x21(%rbp)
je 0xcfff9
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
setne %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0xd0002
jmp 0xd001b
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x45a0
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0xcffdf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)