// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x879c
jp 0x879c
movq %xmm1, %rax
testq %rax, %rax
js 0x8823
leaq 0x7017b(%rip), %rdi     # 0x78905
pushq $0x1
popq %rsi
movq %rbx, %rdx
callq 0x8a88
pushq $0x1
jmp 0x88a5
xorl %ebp, %ebp
ucomisd %xmm1, %xmm0
jbe 0x87eb
movapd %xmm1, 0x20(%rsp)
movq (%rbx), %rsi
addq $0x2, %rsi
movq %rbx, %rdi
callq 0x8ae5
testl %eax, %eax
js 0x87da
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)
pushq $0x1
popq %rbp
movapd 0x20(%rsp), %xmm1
xorpd 0x6e075(%rip), %xmm1    # 0x76860
ucomisd 0x6e07d(%rip), %xmm1    # 0x76870
jb 0x8839
movsd 0x6e07b(%rip), %xmm0    # 0x76878
ucomisd %xmm1, %xmm0
jb 0x8839
movsd 0x6e075(%rip), %xmm0    # 0x76880
ucomisd %xmm1, %xmm0
jbe 0x8883
leaq 0x13(%rsp), %r14
mulsd 0x6e0ba(%rip), %xmm1    # 0x768d8
jmp 0x8981
leaq 0x6e0b6(%rip), %rdi     # 0x768e0
pushq $0x2
popq %rsi
movq %rbx, %rdx
callq 0x8a88
pushq $0x2
jmp 0x88a5
movapd %xmm1, 0x20(%rsp)
movq (%rbx), %rsi
addq $0x32, %rsi
movq %rbx, %rdi
callq 0x8ae5
testl %eax, %eax
js 0x88a3
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdi
addq %rax, %rdi
subq %rax, %rsi
leaq 0x71ed9(%rip), %rdx     # 0x7a743
movapd 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x4800
addl %eax, %ebp
cltq
addq %rax, (%rbx)
jmp 0x8a7b
movsd 0x6dffd(%rip), %xmm0    # 0x76888
ucomisd %xmm1, %xmm0
jbe 0x88ab
leaq 0x12(%rsp), %r14
mulsd 0x6e032(%rip), %xmm1    # 0x768d0
jmp 0x8981
pushq $-0x1
popq %rbp
jmp 0x8a7b
movsd 0x6dfdd(%rip), %xmm0    # 0x76890
ucomisd %xmm1, %xmm0
jbe 0x88cb
leaq 0x11(%rsp), %r14
mulsd 0x6e002(%rip), %xmm1    # 0x768c8
jmp 0x8981
movsd 0x6c73d(%rip), %xmm0    # 0x75010
ucomisd %xmm1, %xmm0
jbe 0x88eb
leaq 0x10(%rsp), %r14
mulsd 0x6dfda(%rip), %xmm1    # 0x768c0
jmp 0x8981
movsd 0x6dfa5(%rip), %xmm0    # 0x76898
ucomisd %xmm1, %xmm0
jbe 0x8908
leaq 0xf(%rsp), %r14
mulsd 0x6dfb2(%rip), %xmm1    # 0x768b8
jmp 0x8981
movsd 0x6df90(%rip), %xmm0    # 0x768a0
ucomisd %xmm1, %xmm0
jbe 0x8925
leaq 0xe(%rsp), %r14
mulsd 0x6df8d(%rip), %xmm1    # 0x768b0
jmp 0x8981
movsd 0x6df7b(%rip), %xmm0    # 0x768a8
ucomisd %xmm1, %xmm0
jbe 0x8942
leaq 0xd(%rsp), %r14
mulsd 0x6df68(%rip), %xmm1    # 0x768a8
jmp 0x8981
movsd 0x6df66(%rip), %xmm0    # 0x768b0
ucomisd %xmm1, %xmm0
jbe 0x895f
leaq 0xc(%rsp), %r14
mulsd 0x6df43(%rip), %xmm1    # 0x768a0
jmp 0x8981
movsd 0x6df51(%rip), %xmm0    # 0x768b8
ucomisd %xmm1, %xmm0
jbe 0x897c
leaq 0xb(%rsp), %r14
mulsd 0x6df1e(%rip), %xmm1    # 0x76898
jmp 0x8981
leaq 0xa(%rsp), %r14
leaq 0x14(%rsp), %r15
movapd %xmm1, %xmm0
callq 0x46f0
cvttsd2si %xmm0, %rcx
pushq $0x64
popq %rsi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
leaq 0x6ddec(%rip), %rdi     # 0x76790
movzwl (%rdi,%rdx,2), %edx
movw %dx, -0x2(%r14)
xorl %edx, %edx
divl %esi
movzwl (%rdi,%rdx,2), %eax
movw %ax, -0x4(%r14)
movl $0x2710, %r8d           # imm = 0x2710
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
xorl %edx, %edx
divl %esi
movzwl (%rdi,%rdx,2), %eax
movw %ax, -0x6(%r14)
cmpl $0xf4240, %ecx          # imm = 0xF4240
jb 0x89f3
movl $0xf4240, %esi          # imm = 0xF4240
movl %ecx, %eax
xorl %edx, %edx
divl %esi
addb $0x30, %al
movb %al, -0x7(%r14)
addq $-0x7, %r14
jmp 0x89f7
addq $-0x6, %r14
subl %r14d, %r15d
cmpl $0xa, %r15d
jg 0x8a16
leaq -0x2(%r14), %rdi
cmpl $0x9, %r15d
jg 0x8a30
movb $0x30, 0x1(%rdi)
incl %r15d
decq %rdi
jmp 0x8a04
leaq -0x1(%r14), %rdi
movq %r14, %rax
cmpl $0xb, %r15d
jl 0x8a37
movb (%rax), %cl
movb %cl, -0x1(%rax)
decl %r15d
incq %rax
jmp 0x8a1d
movw $0x2e30, (%rdi)         # imm = 0x2E30
jmp 0x8a3b
movb $0x2e, -0x1(%rax)
addq $0x5, %r14
movzbl (%r14), %edx
leaq -0x1(%r14), %rax
cmpl $0x30, %edx
jne 0x8a54
cmpq %rdi, %r14
movq %rax, %r14
ja 0x8a3f
leaq 0x1(%rax), %rcx
testl %edx, %edx
je 0x8a68
cmpl $0x2e, %edx
je 0x8a68
addq $0x2, %rax
movq %rax, %rcx
movb $0x0, (%rcx)
subq %rdi, %rcx
addl %ecx, %ebp
movslq %ecx, %rsi
movq %rbx, %rdx
callq 0x8a88
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq