// File: /workspace/github_c_makefile_star2_O3/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, %r12
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xff90
testq %rax, %rax
je 0x1028a
leaq 0x85305(%rip), %rsi     # 0x95534
movl $0x5, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x10279
leaq 0x852f3(%rip), %rsi     # 0x9553a
movl $0xa, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x10279
leaq 0x852e6(%rip), %rsi     # 0x95545
movl $0xb, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x10279
leaq 0x852da(%rip), %rsi     # 0x95551
jmp 0x10280
leaq 0x87d7f(%rip), %rsi     # 0x97fff
movq %r14, %rdi
callq 0x4090
jmp 0x10292
movq %r14, %rdi
callq 0x41d0
movq %rax, %r15
addq %r14, %r15
movq %r15, %r13
testl %ebp, %ebp
je 0x102be
movq %r15, %r13
cmpq %r14, %r13
jbe 0x102bb
movzbl -0x1(%r13), %eax
cmpl $0x2f, %eax
je 0x102bb
decq %r13
cmpl $0x2e, %eax
jne 0x102a2
jmp 0x102be
movq %r15, %r13
movq $0x0, (%rbx)
subq %r14, %r13
movq %r13, %rax
addq $0x2, %rax
je 0x10440
cmpq %rax, 0x8(%rbx)
jae 0x1031e
movq %r12, (%rsp)
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %r12
shrq %r12
xorl %ebp, %ebp
testq %rcx, %rcx
cmovneq %rbp, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x1044d
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq (%rbx), %rdi
movq (%rsp), %r12
jmp 0x10324
movq 0x10(%rbx), %rax
xorl %edi, %edi
addq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x43c0
movq (%rbx), %rax
addq %r13, %rax
movq %rax, (%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
testl %r13d, %r13d
js 0x1044b
testq %r12, %r12
je 0x1045f
movq %r12, %rdi
callq 0x41d0
movq %rax, %r13
movq (%rbx), %rdi
addq %rdi, %rax
addq $0x2, %rax
cmpq %rdi, %rax
jbe 0x10440
cmpq %rax, 0x8(%rbx)
jae 0x103bc
movq %r12, (%rsp)
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %r12
shrq %r12
xorl %ebp, %ebp
testq %rcx, %rcx
cmovneq %rbp, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x1044d
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq (%rbx), %rdi
movq (%rsp), %r12
jmp 0x103c0
movq 0x10(%rbx), %rax
addq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x43c0
movq (%rbx), %rax
addq %r13, %rax
movq %rax, (%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
testl %r13d, %r13d
js 0x1044b
testq %r14, %r14
je 0x1045f
movq %r15, %rdi
callq 0x41d0
movq %rax, %r14
movq (%rbx), %rdi
addq %rdi, %rax
addq $0x2, %rax
cmpq %rdi, %rax
jbe 0x10440
cmpq %rax, 0x8(%rbx)
jae 0x1046c
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %r12
shrq %r12
xorl %ebp, %ebp
testq %rcx, %rcx
cmovneq %rbp, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x1044d
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq (%rbx), %rdi
jmp 0x10470
callq 0x4050
movl $0x4b, (%rax)
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4050
movl $0xe, (%rax)
jmp 0x1044b
movq 0x10(%rbx), %rax
addq %rax, %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 0x1044b
movq 0x10(%rbx), %rbp
jmp 0x1044d