// File: /workspace/github_c_makefile_star2_O1/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 0x94b6
jp 0x94b6
movq %xmm1, %rcx
movq (%rbx), %rax
testq %rcx, %rcx
js 0x9578
subq $-0x3, %rax
jae 0x95e4
cmpq %rax, 0x8(%rbx)
jae 0x9493
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 0x95ef
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x30, (%rcx,%rax)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, 0x1(%rcx,%rax)
jmp 0x95ef
xorl %ebp, %ebp
ucomisd %xmm1, %xmm0
jbe 0x9534
movq (%rbx), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbx)
jae 0x950a
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 0x9527
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x2d, (%rcx,%rax)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
xorpd 0x8e331(%rip), %xmm1    # 0x97860
movl $0x1, %ebp
ucomisd 0x8e334(%rip), %xmm1    # 0x97870
jb 0x95f9
movsd 0x8e32e(%rip), %xmm0    # 0x97878
ucomisd %xmm1, %xmm0
jb 0x95f9
movsd 0x8e324(%rip), %xmm0    # 0x97880
ucomisd %xmm1, %xmm0
jbe 0x968d
leaq 0x13(%rsp), %r14
mulsd 0x8e365(%rip), %xmm1    # 0x978d8
jmp 0x978d
subq $-0x4, %rax
jae 0x9678
cmpq %rax, 0x8(%rbx)
jae 0x95bf
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 0x9683
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movw $0x302d, (%rcx,%rax)    # imm = 0x302D
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x2(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, 0x2(%rcx,%rax)
jmp 0x9683
callq 0x4050
movl $0x4b, (%rax)
movl $0x1, %ebp
jmp 0x9941
movq (%rbx), %rax
addq $0x32, %rax
cmpq %rax, 0x8(%rbx)
jae 0x9649
movapd %xmm1, 0x20(%rsp)
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 0x96cd
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movapd 0x20(%rsp), %xmm1
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdi
addq %rax, %rdi
subq %rax, %rsi
leaq 0x92174(%rip), %rdx     # 0x9b7d5
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x4800
addl %eax, %ebp
cltq
addq %rax, (%rbx)
jmp 0x9941
callq 0x4050
movl $0x4b, (%rax)
movl $0x2, %ebp
jmp 0x9941
movsd 0x8e1f3(%rip), %xmm0    # 0x97888
ucomisd %xmm1, %xmm0
jbe 0x96ad
leaq 0x12(%rsp), %r14
mulsd 0x8e228(%rip), %xmm1    # 0x978d0
jmp 0x978d
movsd 0x8e1db(%rip), %xmm0    # 0x97890
ucomisd %xmm1, %xmm0
jbe 0x96d7
leaq 0x11(%rsp), %r14
mulsd 0x8e200(%rip), %xmm1    # 0x978c8
jmp 0x978d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x9941
movsd 0x8c931(%rip), %xmm0    # 0x96010
ucomisd %xmm1, %xmm0
jbe 0x96f7
leaq 0x10(%rsp), %r14
mulsd 0x8e1ce(%rip), %xmm1    # 0x978c0
jmp 0x978d
movsd 0x8e199(%rip), %xmm0    # 0x97898
ucomisd %xmm1, %xmm0
jbe 0x9714
leaq 0xf(%rsp), %r14
mulsd 0x8e1a6(%rip), %xmm1    # 0x978b8
jmp 0x978d
movsd 0x8e184(%rip), %xmm0    # 0x978a0
ucomisd %xmm1, %xmm0
jbe 0x9731
leaq 0xe(%rsp), %r14
mulsd 0x8e181(%rip), %xmm1    # 0x978b0
jmp 0x978d
movsd 0x8e16f(%rip), %xmm0    # 0x978a8
ucomisd %xmm1, %xmm0
jbe 0x974e
leaq 0xd(%rsp), %r14
mulsd 0x8e15c(%rip), %xmm1    # 0x978a8
jmp 0x978d
movsd 0x8e15a(%rip), %xmm0    # 0x978b0
ucomisd %xmm1, %xmm0
jbe 0x976b
leaq 0xc(%rsp), %r14
mulsd 0x8e137(%rip), %xmm1    # 0x978a0
jmp 0x978d
movsd 0x8e145(%rip), %xmm0    # 0x978b8
ucomisd %xmm1, %xmm0
jbe 0x9788
leaq 0xb(%rsp), %r14
mulsd 0x8e112(%rip), %xmm1    # 0x97898
jmp 0x978d
leaq 0xa(%rsp), %r14
leaq 0x14(%rsp), %r12
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 0x8dfd5(%rip), %rsi     # 0x97790
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 0x9822
imulq $0x431bde83, %rax, %rax # imm = 0x431BDE83
shrq $0x32, %rax
addb $0x30, %al
movb %al, -0x7(%r14)
addq $-0x7, %r14
jmp 0x9826
addq $-0x6, %r14
subl %r14d, %r12d
cmpl $0xa, %r12d
jg 0x986f
movq %r14, %r15
je 0x9862
movl $0x9, %eax
cmovgel %r12d, %eax
leal (%r14,%rax), %edx
movq %rsp, %rax
subl %eax, %edx
addl $-0x14, %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 0x9892
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 0x98ab
cmpq %r15, %r14
movq %rax, %r14
ja 0x9896
leaq 0x1(%rax), %rcx
testl %edx, %edx
je 0x98bf
cmpl $0x2e, %edx
je 0x98bf
addq $0x2, %rax
movq %rax, %rcx
movb $0x0, (%rcx)
subq %r15, %rcx
addl %ecx, %ebp
movslq %ecx, %r14
movq (%rbx), %rcx
leaq (%rcx,%r14), %rax
addq $0x2, %rax
cmpq %rcx, %rax
jbe 0x9936
cmpq %rax, 0x8(%rbx)
jae 0x9913
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 0x9941
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x43c0
addq (%rbx), %r14
movq %r14, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r14)
jmp 0x9941
callq 0x4050
movl $0x4b, (%rax)
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq