// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/hfile.c
// Function: haddextension
char *haddextension(struct kstring_t *buffer, const char *filename,
                    int replace, const char *new_extension)
{
    const char *trailing, *end;

    if (find_scheme_handler(filename)) {
        // URL, so alter extensions before any trailing query or fragment parts
        // Allow # symbols in s3 URLs
        trailing = filename + ((strncmp(filename, "s3://", 5) && strncmp(filename, "s3+http://", 10) && strncmp(filename, "s3+https://", 11))  ? strcspn(filename, "?#") : strcspn(filename, "?"));
    }
    else {
        // Local path, so alter extensions at the end of the filename
        trailing = strchr(filename, '\0');
    }

    end = replace? strip_extension(filename, trailing) : trailing;

    buffer->l = 0;
    if (kputsn(filename, end - filename, buffer) >= 0 &&
        kputs(new_extension, buffer) >= 0 &&
        kputs(trailing, buffer) >= 0) return buffer->s;
    else return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r13
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x10169
testq %rax, %rax
je 0x1046b
leaq 0x880e4(%rip), %rsi     # 0x984f4
movl $0x5, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x1045a
leaq 0x880d2(%rip), %rsi     # 0x984fa
movl $0xa, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x1045a
leaq 0x880c5(%rip), %rsi     # 0x98505
movl $0xb, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x1045a
leaq 0x880b9(%rip), %rsi     # 0x98511
jmp 0x10461
leaq 0x8ab8b(%rip), %rsi     # 0x9afec
movq %r14, %rdi
callq 0x4090
jmp 0x10473
movq %r14, %rdi
callq 0x41d0
movq %rax, %r15
addq %r14, %r15
movq %r15, %r12
testl %ebp, %ebp
je 0x104a0
movq %r15, %r12
cmpq %r14, %r12
jbe 0x1049d
movzbl -0x1(%r12), %eax
cmpl $0x2f, %eax
je 0x1049d
decq %r12
cmpl $0x2e, %eax
jne 0x10483
jmp 0x104a0
movq %r15, %r12
movq $0x0, (%rbx)
subq %r14, %r12
movq %r12, %rax
addq $0x2, %rax
je 0x1064a
cmpq %rax, 0x8(%rbx)
jae 0x104fc
movq %r13, (%rsp)
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rbp
shrq %rbp
xorl %r13d, %r13d
testq %rcx, %rcx
cmovneq %r13, %rbp
addq %rax, %rbp
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x10658
movq %rax, 0x10(%rbx)
movq %rbp, 0x8(%rbx)
movq (%rsp), %r13
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x43c0
movq (%rbx), %rax
addq %r12, %rax
movq %rax, (%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
testl %r12d, %r12d
js 0x10655
testq %r13, %r13
je 0x1066a
movq %r13, %rdi
callq 0x41d0
movq %rax, %r12
movq (%rbx), %rcx
addq %rcx, %rax
addq $0x2, %rax
cmpq %rcx, %rax
jbe 0x1064a
cmpq %rax, 0x8(%rbx)
jae 0x10594
movq %r13, (%rsp)
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rbp
shrq %rbp
xorl %r13d, %r13d
testq %rcx, %rcx
cmovneq %r13, %rbp
addq %rax, %rbp
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x10658
movq %rax, 0x10(%rbx)
movq %rbp, 0x8(%rbx)
movq (%rsp), %r13
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x43c0
movq (%rbx), %rax
addq %r12, %rax
movq %rax, (%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
testl %r12d, %r12d
js 0x10655
testq %r14, %r14
je 0x1066a
movq %r15, %rdi
callq 0x41d0
movq %rax, %r14
movq (%rbx), %rcx
addq %rcx, %rax
addq $0x2, %rax
cmpq %rcx, %rax
jbe 0x1064a
cmpq %rax, 0x8(%rbx)
jae 0x1061c
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %r12
shrq %r12
xorl %r13d, %r13d
testq %rcx, %rcx
cmovneq %r13, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x10658
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x43c0
movq (%rbx), %rax
addq %r14, %rax
movq %rax, (%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
testl %r14d, %r14d
js 0x10655
movq 0x10(%rbx), %r13
jmp 0x10658
callq 0x4050
movl $0x4b, (%rax)
xorl %r13d, %r13d
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4050
movl $0xe, (%rax)
jmp 0x10655