// File: mouda[P]LTE_random_access-simulate/ap.cpp
// Function: alglib_impl::ae_int2str(long, char*, alglib_impl::ae_state*)
void ae_int2str(ae_int_t v, char *buf, ae_state *state)
{
    union _u
    {
        ae_int_t ival;
        unsigned char bytes[9];
    } u;
    ae_int_t i;
    ae_int_t sixbits[12];
    unsigned char c;
    
    /*
     * copy v to array of chars, sign extending it and 
     * converting to little endian order
     *
     * because we don't want to mention size of ae_int_t explicitly, 
     * we do it as follows:
     * 1. we fill u.bytes by zeros or ones (depending on sign of v)
     * 2. we copy v to u.ival
     * 3. if we run on big endian architecture, we reorder u.bytes
     * 4. now we have signed 64-bit representation of v stored in u.bytes
     * 5. additionally, we set 9th byte of u.bytes to zero in order to
     *    simplify conversion to six-bit representation
     */
    c = v<0 ? (unsigned char)0xFF : (unsigned char)0x00;
    u.ival = v;
    for(i=sizeof(ae_int_t); i<=8; i++) /* <=8 is preferred because it avoids unnecessary compiler warnings*/
        u.bytes[i] = c;
    u.bytes[8] = 0;
    if( state->endianness==AE_BIG_ENDIAN )
    {
        for(i=0; i<sizeof(ae_int_t)/2; i++)
        {
            unsigned char tc;
            tc = u.bytes[i];
            u.bytes[i] = u.bytes[sizeof(ae_int_t)-1-i];
            u.bytes[sizeof(ae_int_t)-1-i] = tc;
        }
    }
    
    /*
     * convert to six-bit representation, output
     *
     * NOTE: last 12th element of sixbits is always zero, we do not output it
     */
    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 $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rcx
movb $-0x1, %al
xorl %edx, %edx
movb %dl, -0x94(%rbp)
cmpq $0x0, %rcx
movb %al, -0x93(%rbp)
jl 0x3e03d
movb -0x94(%rbp), %al
movb %al, -0x93(%rbp)
movb -0x93(%rbp), %al
movb %al, -0x91(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x8, -0x30(%rbp)
cmpq $0x8, -0x30(%rbp)
jg 0x3e07c
movb -0x91(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, -0x28(%rbp,%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3e059
movb $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x2, (%rax)
jne 0x3e0df
movq $0x0, -0x30(%rbp)
cmpq $0x4, -0x30(%rbp)
jae 0x3e0dd
movq -0x30(%rbp), %rax
movb -0x28(%rbp,%rax), %al
movb %al, -0x92(%rbp)
movl $0x7, %eax
subq -0x30(%rbp), %rax
movb -0x28(%rbp,%rax), %cl
movq -0x30(%rbp), %rax
movb %cl, -0x28(%rbp,%rax)
movb -0x92(%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 0x3e092
jmp 0x3e0df
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 0x3e15a
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 0x3e127
movq -0x10(%rbp), %rax
movb $0x0, 0xb(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)