// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/kstring.c
// Function: kputd
int kputd(double d, kstring_t *s) {
	int len = 0;
	char buf[21], *cp = buf+20, *ep;
	if (d == 0) {
		if (signbit(d)) {
			kputsn("-0",2,s);
			return 2;
		} else {
			kputsn("0",1,s);
			return 1;
		}
	}

	if (d < 0) {
		kputc('-',s);
		len = 1;
		d=-d;
	}
	if (!(d >= 0.0001 && d <= 999999)) {
		if (ks_resize(s, s->l + 50) < 0)
			return EOF;
		// We let stdio handle the exponent cases
		int s2 = snprintf(s->s + s->l, s->m - s->l, "%g", d);
		len += s2;
		s->l += s2;
		return len;
	}

	// Correction for rounding - rather ugly
	// Optimised for small numbers.

	uint32_t i;
	if (d<0.001)         i = rint(d*1000000000), cp -= 1;
	else if (d < 0.01)   i = rint(d*100000000),  cp -= 2;
	else if (d < 0.1)    i = rint(d*10000000),   cp -= 3;
	else if (d < 1)      i = rint(d*1000000),    cp -= 4;
	else if (d < 10)     i = rint(d*100000),     cp -= 5;
	else if (d < 100)    i = rint(d*10000),      cp -= 6;
	else if (d < 1000)   i = rint(d*1000),       cp -= 7;
	else if (d < 10000)  i = rint(d*100),        cp -= 8;
	else if (d < 100000) i = rint(d*10),         cp -= 9;
	else                 i = rint(d),            cp -= 10;

	// integer i is always 6 digits, so print it 2 at a time.
	static const char kputuw_dig2r[] =
		"00010203040506070809"
		"10111213141516171819"
		"20212223242526272829"
		"30313233343536373839"
		"40414243444546474849"
		"50515253545556575859"
		"60616263646566676869"
		"70717273747576777879"
		"80818283848586878889"
		"90919293949596979899";

	memcpy(cp-=2, &kputuw_dig2r[2*(i%100)], 2); i /= 100;
	memcpy(cp-=2, &kputuw_dig2r[2*(i%100)], 2); i /= 100;
	memcpy(cp-=2, &kputuw_dig2r[2*(i%100)], 2);

	// Except when it rounds up (d=0.009999999 is i=1000000)
	if (i >= 100)
		*--cp = '0' + (i/100);


	int p = buf+20-cp;
	if (p <= 10) { /* d < 1 */
		// 0.00123 is 123, so add leading zeros and 0.
		ep = cp+5; // 6 precision
		while (p < 10) { // aka d < 1
			*--cp = '0';
			p++;
		}
		*--cp = '.';
		*--cp = '0';
	} else {
		// 123.001 is 123001 with p==13, so move 123 down and add "."
		// Equiv to memmove(cp-1, cp, p-10); cp--;
		char *xp = --cp;
		ep = cp+6;
		while (p > 10) {
			xp[0] = xp[1];
			xp++;
			p--;
		}
		xp[0] = '.';
	}

	// Cull trailing zeros
	while (*ep == '0' && ep > cp)
		ep--;

	// End can be 1 out due to the mostly-6 but occasionally 7 (i==1) case.
	// Also code with "123." which should be "123"
	if (*ep && *ep != '.')
		ep++;
	*ep = 0;

	int sl = ep-cp;
	len += sl;
	kputsn(cp, sl, s);
	return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x947e
jp 0x947e
movq %xmm1, %rax
movq (%rbx), %rcx
testq %rax, %rax
js 0x94e6
movq %rcx, %rax
subq $-0x3, %rax
jae 0x9538
cmpq %rax, 0x8(%rbx)
jae 0x9555
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r14d, %r14d
testq %rcx, %rcx
cmoveq %rdx, %r14
addq %rax, %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x4840
testq %rax, %rax
je 0x9570
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
jmp 0x9559
xorl %ebp, %ebp
ucomisd %xmm1, %xmm0
jbe 0x95a1
movq (%rbx), %rcx
leaq 0x2(%rcx), %rax
cmpq %rax, 0x8(%rbx)
jae 0x957a
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r14d, %r14d
testq %rcx, %rcx
cmoveq %rdx, %r14
addq %rax, %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
movapd %xmm1, 0x20(%rsp)
callq 0x4840
movapd 0x20(%rsp), %xmm1
testq %rax, %rax
je 0x9594
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
jmp 0x957e
movq %rcx, %rax
subq $-0x4, %rax
jae 0x9545
cmpq %rax, 0x8(%rbx)
jae 0x9683
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r14d, %r14d
testq %rcx, %rcx
cmoveq %rdx, %r14
addq %rax, %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x4840
testq %rax, %rax
je 0x96a0
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
jmp 0x9687
callq 0x4050
movl $0x4b, (%rax)
jmp 0x9570
callq 0x4050
movl $0x4b, (%rax)
jmp 0x96a0
movq 0x10(%rbx), %rax
movb $0x30, (%rax,%rcx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, 0x1(%rcx,%rax)
movl $0x1, %ebp
jmp 0x9939
movq 0x10(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movb $0x2d, (%rax,%rcx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
xorpd 0x8b2c4(%rip), %xmm1    # 0x94860
movl $0x1, %ebp
ucomisd 0x8b307(%rip), %xmm1    # 0x948b0
jb 0x95dd
movsd 0x8b305(%rip), %xmm0    # 0x948b8
ucomisd %xmm1, %xmm0
jb 0x95dd
movsd 0x8b2ff(%rip), %xmm0    # 0x948c0
ucomisd %xmm1, %xmm0
jbe 0x9663
leaq 0x13(%rsp), %r14
mulsd 0x8b340(%rip), %xmm1    # 0x94918
jmp 0x978a
movq (%rbx), %rax
movq 0x8(%rbx), %r14
leaq 0x32(%rax), %rcx
cmpq %rcx, %r14
jae 0x9638
movapd %xmm1, 0x20(%rsp)
movq %rcx, %rax
shrq $0x3e, %rax
movq %rcx, %rdx
shrq %rdx
xorl %r14d, %r14d
testq %rax, %rax
cmoveq %rdx, %r14
addq %rcx, %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x4840
testq %rax, %rax
je 0x96ca
movq %rax, %rdi
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movapd 0x20(%rsp), %xmm1
jmp 0x963c
movq 0x10(%rbx), %rdi
addq %rax, %rdi
subq %rax, %r14
leaq 0x8f193(%rip), %rdx     # 0x987dc
movq %r14, %rsi
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x4800
addl %eax, %ebp
cltq
addq %rax, (%rbx)
jmp 0x9939
movsd 0x8b25d(%rip), %xmm0    # 0x948c8
ucomisd %xmm1, %xmm0
jbe 0x96aa
leaq 0x12(%rsp), %r14
mulsd 0x8b292(%rip), %xmm1    # 0x94910
jmp 0x978a
movq 0x10(%rbx), %rax
movw $0x302d, (%rax,%rcx)    # imm = 0x302D
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x2(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, 0x2(%rcx,%rax)
movl $0x2, %ebp
jmp 0x9939
movsd 0x8b21e(%rip), %xmm0    # 0x948d0
ucomisd %xmm1, %xmm0
jbe 0x96d4
leaq 0x11(%rsp), %r14
mulsd 0x8b243(%rip), %xmm1    # 0x94908
jmp 0x978a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x9939
movsd 0x89934(%rip), %xmm0    # 0x93010
ucomisd %xmm1, %xmm0
jbe 0x96f4
leaq 0x10(%rsp), %r14
mulsd 0x8b211(%rip), %xmm1    # 0x94900
jmp 0x978a
movsd 0x8b1dc(%rip), %xmm0    # 0x948d8
ucomisd %xmm1, %xmm0
jbe 0x9711
leaq 0xf(%rsp), %r14
mulsd 0x8b1e9(%rip), %xmm1    # 0x948f8
jmp 0x978a
movsd 0x8b1c7(%rip), %xmm0    # 0x948e0
ucomisd %xmm1, %xmm0
jbe 0x972e
leaq 0xe(%rsp), %r14
mulsd 0x8b1c4(%rip), %xmm1    # 0x948f0
jmp 0x978a
movsd 0x8b1b2(%rip), %xmm0    # 0x948e8
ucomisd %xmm1, %xmm0
jbe 0x974b
leaq 0xd(%rsp), %r14
mulsd 0x8b19f(%rip), %xmm1    # 0x948e8
jmp 0x978a
movsd 0x8b19d(%rip), %xmm0    # 0x948f0
ucomisd %xmm1, %xmm0
jbe 0x9768
leaq 0xc(%rsp), %r14
mulsd 0x8b17a(%rip), %xmm1    # 0x948e0
jmp 0x978a
movsd 0x8b188(%rip), %xmm0    # 0x948f8
ucomisd %xmm1, %xmm0
jbe 0x9785
leaq 0xb(%rsp), %r14
mulsd 0x8b155(%rip), %xmm1    # 0x948d8
jmp 0x978a
leaq 0xa(%rsp), %r14
leaq 0x14(%rsp), %r15
movapd %xmm1, %xmm0
callq 0x46f0
cvttsd2si %xmm0, %rcx
movl %ecx, %eax
imulq $0x51eb851f, %rax, %rdx # imm = 0x51EB851F
shrq $0x25, %rdx
imull $0x64, %edx, %esi
movl %ecx, %edi
subl %esi, %edi
leaq 0x8afd8(%rip), %rsi     # 0x94790
movzwl (%rsi,%rdi,2), %edi
movw %di, -0x2(%r14)
imulq $0x28f5c29, %rdx, %rdi  # imm = 0x28F5C29
shrq $0x20, %rdi
imull $0x64, %edi, %edi
subl %edi, %edx
movzwl (%rsi,%rdx,2), %edx
movw %dx, -0x4(%r14)
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rax, %rdx
shrq $0x2d, %rdx
imulq $0x28f5c29, %rdx, %rdi  # imm = 0x28F5C29
shrq $0x20, %rdi
imull $0x64, %edi, %edi
subl %edi, %edx
movzwl (%rsi,%rdx,2), %edx
movw %dx, -0x6(%r14)
cmpl $0xf4240, %ecx          # imm = 0xF4240
jb 0x981f
imulq $0x431bde83, %rax, %rax # imm = 0x431BDE83
shrq $0x32, %rax
addb $0x30, %al
movb %al, -0x7(%r14)
addq $-0x7, %r14
jmp 0x9823
addq $-0x6, %r14
subl %r14d, %r15d
cmpl $0xa, %r15d
jg 0x9862
movq %r14, %r15
je 0x9855
movq %rsp, %rax
movl %r14d, %edx
subl %eax, %edx
addl $-0xb, %edx
movq %rdx, %r15
notq %r15
addq %r14, %r15
incq %rdx
movq %r15, %rdi
movl $0x30, %esi
callq 0x4260
movw $0x2e30, -0x2(%r15)     # imm = 0x2E30
addq $-0x2, %r15
jmp 0x9885
leaq -0x1(%r14), %r15
movq %rsp, %r12
orl $0x9, %r12d
subl %r14d, %r12d
leaq 0x1(%r12), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x4830
movb $0x2e, (%r14,%r12)
addq $0x5, %r14
movzbl (%r14), %edx
leaq -0x1(%r14), %rax
cmpl $0x30, %edx
jne 0x989e
cmpq %r15, %r14
movq %rax, %r14
ja 0x9889
leaq 0x1(%rax), %rcx
testl %edx, %edx
je 0x98b2
cmpl $0x2e, %edx
je 0x98b2
addq $0x2, %rax
movq %rax, %rcx
movb $0x0, (%rcx)
subq %r15, %rcx
addl %ecx, %ebp
movslq %ecx, %r14
movq (%rbx), %rdi
leaq (%rdi,%r14), %rax
addq $0x2, %rax
cmpq %rdi, %rax
jbe 0x990b
cmpq %rax, 0x8(%rbx)
jae 0x9918
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r12d, %r12d
testq %rcx, %rcx
cmoveq %rdx, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x9939
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq (%rbx), %rdi
jmp 0x991c
callq 0x4050
movl $0x4b, (%rax)
jmp 0x9939
movq 0x10(%rbx), %rax
addq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x43c0
addq (%rbx), %r14
movq %r14, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r14)
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq