// File: /workspace/github_cpp_makefile_star2_O1/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:
movq %rdi, -0x78(%rsp)
movb $0x0, -0x70(%rsp)
cmpq $0x2, (%rdx)
jne 0x27429
leaq -0x71(%rsp), %rax
xorl %ecx, %ecx
movb -0x78(%rsp,%rcx), %dl
movb (%rax), %dil
movb %dil, -0x78(%rsp,%rcx)
movb %dl, (%rax)
incq %rcx
decq %rax
cmpq $0x4, %rcx
jne 0x2740f
movzbl -0x78(%rsp), %eax
movl %eax, %ecx
andl $0x3f, %ecx
movq %rcx, -0x68(%rsp)
shrl $0x6, %eax
movzbl -0x77(%rsp), %ecx
movl %ecx, %edx
andl $0xf, %edx
leal (%rax,%rdx,4), %eax
movq %rax, -0x60(%rsp)
shrl $0x4, %ecx
movzbl -0x76(%rsp), %eax
movl %eax, %edx
shll $0x4, %edx
andl $0x30, %edx
orl %ecx, %edx
movq %rdx, -0x58(%rsp)
shrl $0x2, %eax
movq %rax, -0x50(%rsp)
movzbl -0x75(%rsp), %eax
movl %eax, %ecx
andl $0x3f, %ecx
movq %rcx, -0x48(%rsp)
shrl $0x6, %eax
movzbl -0x74(%rsp), %ecx
movl %ecx, %edx
andl $0xf, %edx
leal (%rax,%rdx,4), %eax
movq %rax, -0x40(%rsp)
shrl $0x4, %ecx
movzbl -0x73(%rsp), %eax
movl %eax, %edx
shll $0x4, %edx
andl $0x30, %edx
orl %ecx, %edx
movq %rdx, -0x38(%rsp)
shrl $0x2, %eax
movq %rax, -0x30(%rsp)
movzbl -0x72(%rsp), %eax
movl %eax, %ecx
andl $0x3f, %ecx
movq %rcx, -0x28(%rsp)
shrl $0x6, %eax
movzbl -0x71(%rsp), %ecx
movl %ecx, %edx
andl $0xf, %edx
leal (%rax,%rdx,4), %eax
movq %rax, -0x20(%rsp)
shrl $0x4, %ecx
movzbl -0x70(%rsp), %eax
movl %eax, %edx
shll $0x4, %edx
andl $0x30, %edx
orl %ecx, %edx
movq %rdx, -0x18(%rsp)
shrl $0x2, %eax
movq %rax, -0x10(%rsp)
xorl %eax, %eax
leaq 0xfbe5(%rip), %rcx      # 0x370e0
movq -0x68(%rsp,%rax,8), %rdi
movb $0x3f, %dl
cmpq $0x3f, %rdi
ja 0x2750b
movb (%rdi,%rcx), %dl
movb %dl, (%rsi,%rax)
incq %rax
cmpq $0xb, %rax
jne 0x274fb
movb $0x0, 0xb(%rsi)
retq