// File: mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::ae_double2str(double, char*, alglib_impl::ae_state*)
void ae_double2str(double v, char *buf, ae_state *state)
{
    union _u
    {
        double dval;
        unsigned char bytes[9];
    } u;
    ae_int_t i;
    ae_int_t sixbits[12];

    /*
     * handle special quantities
     */
    if( ae_isnan(v, state) )
    {
        const char *s = ".nan_______";
        memcpy(buf, s, strlen(s)+1);
        return;
    }
    if( ae_isposinf(v, state) )
    {
        const char *s = ".posinf____";
        memcpy(buf, s, strlen(s)+1);
        return;
    }
    if( ae_isneginf(v, state) )
    {
        const char *s = ".neginf____";
        memcpy(buf, s, strlen(s)+1);
        return;
    }
    
    /*
     * process general case:
     * 1. copy v to array of chars
     * 2. set 9th byte of u.bytes to zero in order to
     *    simplify conversion to six-bit representation
     * 3. convert to little endian (if needed)
     * 4. convert to six-bit representation
     *    (last 12th element of sixbits is always zero, we do not output it)
     */
    u.dval = v;
    u.bytes[8] = 0;
    if( state->endianness==AE_BIG_ENDIAN )
    {
        for(i=0; i<sizeof(double)/2; i++)
        {
            unsigned char tc;
            tc = u.bytes[i];
            u.bytes[i] = u.bytes[sizeof(double)-1-i];
            u.bytes[sizeof(double)-1-i] = tc;
        }
    }
    ae_threebytes2foursixbits(u.bytes+0, sixbits+0);
    ae_threebytes2foursixbits(u.bytes+3, sixbits+4);
    ae_threebytes2foursixbits(u.bytes+6, sixbits+8);
    for(i=0; i<AE_SER_ENTRY_LENGTH; i++)
        buf[i] = ae_sixbits2char(sixbits[i]);
    buf[AE_SER_ENTRY_LENGTH] = 0x00;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movsd %xmm0, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd -0x8(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c760
testb $0x1, %al
jne 0x3e44c
jmp 0x3e49e
leaq 0x19dc7(%rip), %rax     # 0x5821a
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x98(%rbp), %rdi
callq 0x3110
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x3230
jmp 0x3e65a
movsd -0x8(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c7c0
testb $0x1, %al
jne 0x3e4b2
jmp 0x3e504
leaq 0x19d6d(%rip), %rax     # 0x58226
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x3110
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x3230
jmp 0x3e65a
movsd -0x8(%rbp), %xmm0
movq -0x18(%rbp), %rdi
callq 0x3c7f0
testb $0x1, %al
jne 0x3e518
jmp 0x3e56a
leaq 0x19d13(%rip), %rax     # 0x58232
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x3110
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x3230
jmp 0x3e65a
movsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movb $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x2, (%rax)
jne 0x3e5d7
movq $0x0, -0x30(%rbp)
cmpq $0x4, -0x30(%rbp)
jae 0x3e5d5
movq -0x30(%rbp), %rax
movb -0x28(%rbp,%rax), %al
movb %al, -0xa9(%rbp)
movl $0x7, %eax
subq -0x30(%rbp), %rax
movb -0x28(%rbp,%rax), %cl
movq -0x30(%rbp), %rax
movb %cl, -0x28(%rbp,%rax)
movb -0xa9(%rbp), %cl
movl $0x7, %eax
subq -0x30(%rbp), %rax
movb %cl, -0x28(%rbp,%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3e58a
jmp 0x3e5d7
leaq -0x28(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3dcf0
leaq -0x28(%rbp), %rdi
addq $0x3, %rdi
leaq -0x90(%rbp), %rsi
addq $0x20, %rsi
callq 0x3dcf0
leaq -0x28(%rbp), %rdi
addq $0x6, %rdi
leaq -0x90(%rbp), %rsi
addq $0x40, %rsi
callq 0x3dcf0
movq $0x0, -0x30(%rbp)
cmpq $0xb, -0x30(%rbp)
jge 0x3e652
movq -0x30(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rdi
callq 0x3dc60
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3e61f
movq -0x10(%rbp), %rax
movb $0x0, 0xb(%rax)
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)