// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hfile_libcurl.c
// Function: get_auth_token
static int get_auth_token(hFILE_libcurl *fp, const char *url) {
    const char *host = NULL, *p, *q;
    kstring_t name = {0, 0, NULL};
    size_t host_len = 0;
    khiter_t idx;
    auth_token *tok = NULL;

    // Nothing to do if:
    //   curl.auth_path has not been set
    //   fp was made by hfile_libcurl (e.g. auth_path is a http:// url)
    //   we already have an Authorization header
    if (!curl.auth_path || fp->is_recursive || fp->headers.auth_hdr_num != 0)
        return 0;

    // Insist on having a secure connection unless the user insists harder
    if (!curl.allow_unencrypted_auth_header && strncmp(url, "https://", 8) != 0)
        return 0;

    host = strstr(url, "://");
    if (host) {
        host += 3;
        host_len = strcspn(host, "/");
    }

    p = curl.auth_path;
    while ((q = strstr(p, "%h")) != NULL) {
        if (q - p > INT_MAX || host_len > INT_MAX) goto error;
        if (kputsn_(p, q - p, &name) < 0) goto error;
        if (kputsn_(host, host_len, &name) < 0) goto error;
        p = q + 2;
    }
    if (kputs(p, &name) < 0) goto error;

    pthread_mutex_lock(&curl.auth_lock);
    idx = kh_get(auth_map, curl.auth_map, name.s);
    if (idx < kh_end(curl.auth_map)) {
        tok = kh_value(curl.auth_map, idx);
    } else {
        tok = calloc(1, sizeof(*tok));
        if (tok && pthread_mutex_init(&tok->lock, NULL) != 0) {
            free(tok);
            tok = NULL;
        }
        if (tok) {
            int ret = -1;
            tok->path = ks_release(&name);
            tok->token = NULL;
            tok->expiry = 1; // Force refresh
            idx = kh_put(auth_map, curl.auth_map, tok->path, &ret);
            if (ret < 0) {
                free_auth(tok);
                tok = NULL;
            }
            kh_value(curl.auth_map, idx) = tok;
        }
    }
    pthread_mutex_unlock(&curl.auth_lock);

    fp->headers.auth = tok;
    free(name.s);

    return add_auth_header(fp);

 error:
    free(name.s);
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4250
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, 0x42860(%rip)     # 0x1128d0
je 0xd0093
movq -0x10(%rbp), %rax
movb 0x64(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xd0093
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
je 0xd009f
movl $0x0, -0x4(%rbp)
jmp 0xd030a
cmpl $0x0, 0x4283a(%rip)     # 0x1128e0
jne 0xd00ce
movq -0x18(%rbp), %rdi
leaq 0x1f665(%rip), %rsi     # 0xef718
movl $0x8, %edx
callq 0x4200
cmpl $0x0, %eax
je 0xd00ce
movl $0x0, -0x4(%rbp)
jmp 0xd030a
movq -0x18(%rbp), %rdi
leaq 0x1f62d(%rip), %rsi     # 0xef706
callq 0x40c0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xd0109
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x1f75c(%rip), %rsi     # 0xef85c
callq 0x4090
movq %rax, -0x50(%rbp)
movq 0x427c0(%rip), %rax     # 0x1128d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x274c4(%rip), %rsi     # 0xf75e3
callq 0x40c0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xd019e
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jg 0xd014b
cmpq $0x7fffffff, -0x50(%rbp) # imm = 0x7FFFFFFF
jbe 0xd0150
jmp 0xd02fa
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
subq %rax, %rsi
leaq -0x48(%rbp), %rdx
callq 0xd0e10
cmpl $0x0, %eax
jge 0xd0172
jmp 0xd02fa
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0xd0e10
cmpl $0x0, %eax
jge 0xd018d
jmp 0xd02fa
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0xd0114
movq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xd0ed0
cmpl $0x0, %eax
jge 0xd01b5
jmp 0xd02fa
leaq 0x426f4(%rip), %rdi     # 0x1128b0
addq $0x38, %rdi
callq 0x4730
movq 0x4270c(%rip), %rdi     # 0x1128d8
movq -0x38(%rbp), %rsi
callq 0xd0f30
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq 0x426f6(%rip), %rcx     # 0x1128d8
cmpl (%rcx), %eax
jae 0xd0201
movq 0x426eb(%rip), %rax     # 0x1128d8
movq 0x20(%rax), %rax
movl -0x54(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
jmp 0xd02c4
movl $0x1, %edi
movl $0x48, %esi
callq 0x42f0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0xd0242
movq -0x60(%rbp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4760
cmpl $0x0, %eax
je 0xd0242
movq -0x60(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0xd02c2
movl $0xffffffff, -0x64(%rbp) # imm = 0xFFFFFFFF
leaq -0x48(%rbp), %rdi
callq 0xd0750
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x60(%rbp), %rax
movq $0x1, 0x10(%rax)
movq 0x42656(%rip), %rdi     # 0x1128d8
movq -0x60(%rbp), %rax
movq (%rax), %rsi
leaq -0x64(%rbp), %rdx
callq 0xd1080
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0xd02ac
movq -0x60(%rbp), %rdi
callq 0xd13e0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rdx
movq 0x42621(%rip), %rax     # 0x1128d8
movq 0x20(%rax), %rax
movl -0x54(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0xd02c4
leaq 0x425e5(%rip), %rdi     # 0x1128b0
addq $0x38, %rdi
callq 0x4330
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x38(%rbp), %rdi
callq 0x45a0
movq -0x10(%rbp), %rdi
callq 0xd1440
movl %eax, -0x4(%rbp)
jmp 0xd030a
movq -0x38(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)