// File: Konano[P]UselessDatabase/./json.hpp
// Function: nlohmann::detail::dtoa_impl::grisu2_round(char*, int, unsigned long, unsigned long, unsigned long, unsigned long)
inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
                         std::uint64_t rest, std::uint64_t ten_k)
{
    assert(len >= 1);
    assert(dist <= delta);
    assert(rest <= delta);
    assert(ten_k > 0);

    //               <--------------------------- delta ---->
    //                                  <---- dist --------->
    // --------------[------------------+-------------------]--------------
    //               M-                 w                   M+
    //
    //                                  ten_k
    //                                <------>
    //                                       <---- rest ---->
    // --------------[------------------+----+--------------]--------------
    //                                  w    V
    //                                       = buf * 10^k
    //
    // ten_k represents a unit-in-the-last-place in the decimal representation
    // stored in buf.
    // Decrement buf by ten_k while this takes buf closer to w.

    // The tests are written in this order to avoid overflow in unsigned
    // integer arithmetic.

    while (rest < dist
            and delta - rest >= ten_k
            and (rest + ten_k < dist or dist - rest > rest + ten_k - dist))
    {
        assert(buf[len - 1] != '0');
        buf[len - 1]--;
        rest += ten_k;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpl $0x1, -0xc(%rbp)
jl 0x17797
jmp 0x177b6
leaq 0x67dbd(%rip), %rdi     # 0x7f55b
leaq 0x6739c(%rip), %rsi     # 0x7eb41
movl $0x3389, %edx           # imm = 0x3389
leaq 0x67db3(%rip), %rcx     # 0x7f564
callq 0x6350
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
ja 0x177c2
jmp 0x177e1
leaq 0x67e13(%rip), %rdi     # 0x7f5dc
leaq 0x67371(%rip), %rsi     # 0x7eb41
movl $0x338a, %edx           # imm = 0x338A
leaq 0x67d88(%rip), %rcx     # 0x7f564
callq 0x6350
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
ja 0x177ed
jmp 0x1780c
leaq 0x67df6(%rip), %rdi     # 0x7f5ea
leaq 0x67346(%rip), %rsi     # 0x7eb41
movl $0x338b, %edx           # imm = 0x338B
leaq 0x67d5d(%rip), %rcx     # 0x7f564
callq 0x6350
cmpq $0x0, -0x30(%rbp)
jbe 0x17815
jmp 0x17834
leaq 0x67ddc(%rip), %rdi     # 0x7f5f8
leaq 0x6731e(%rip), %rsi     # 0x7eb41
movl $0x338c, %edx           # imm = 0x338C
leaq 0x67d35(%rip), %rcx     # 0x7f564
callq 0x6350
jmp 0x17836
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x31(%rbp)
jae 0x1788e
movq -0x20(%rbp), %rcx
subq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x30(%rbp), %rcx
movb %al, -0x31(%rbp)
jb 0x1788e
movq -0x28(%rbp), %rcx
addq -0x30(%rbp), %rcx
movb $0x1, %al
cmpq -0x18(%rbp), %rcx
movb %al, -0x32(%rbp)
jb 0x17888
movq -0x18(%rbp), %rax
subq -0x28(%rbp), %rax
movq -0x28(%rbp), %rcx
addq -0x30(%rbp), %rcx
subq -0x18(%rbp), %rcx
cmpq %rcx, %rax
seta %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x17897
jmp 0x178f5
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
je 0x178af
jmp 0x178ce
leaq 0x67d4c(%rip), %rdi     # 0x7f602
leaq 0x67284(%rip), %rsi     # 0x7eb41
movl $0x33a5, %edx           # imm = 0x33A5
leaq 0x67c9b(%rip), %rcx     # 0x7f564
callq 0x6350
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
addb $-0x1, %dl
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x17836
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)