// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r14
pushq %rbx
movq %rdi, -0x70(%rsp)
movb $0x0, -0x68(%rsp)
cmpq $0x2, (%rdx)
jne 0x26bc0
leaq -0x69(%rsp), %rax
xorl %ecx, %ecx
movb -0x70(%rsp,%rcx), %dl
movb (%rax), %dil
movb %dil, -0x70(%rsp,%rcx)
movb %dl, (%rax)
incq %rcx
decq %rax
cmpq $0x4, %rcx
jne 0x26b7b
movb -0x70(%rsp), %dil
movb -0x6f(%rsp), %bl
movb -0x6e(%rsp), %r11b
movb -0x6d(%rsp), %r10b
movb -0x6c(%rsp), %r9b
movb -0x6b(%rsp), %r8b
movb -0x6a(%rsp), %dl
movb -0x69(%rsp), %cl
movb -0x68(%rsp), %al
jmp 0x26bf1
movl %edi, %ebx
shrl $0x8, %ebx
movl %edi, %r11d
shrl $0x10, %r11d
movl %edi, %r10d
shrl $0x18, %r10d
movq %rdi, %r9
shrq $0x20, %r9
movq %rdi, %r8
shrq $0x28, %r8
movq %rdi, %rdx
shrq $0x30, %rdx
movq %rdi, %rcx
shrq $0x38, %rcx
xorl %eax, %eax
movl %edi, %ebp
andb $0x3f, %bpl
movzbl %bpl, %r14d
movq %r14, -0x60(%rsp)
shrb $0x6, %dil
leal (,%rbx,4), %ebp
orb %dil, %bpl
andb $0x3f, %bpl
movzbl %bpl, %edi
movq %rdi, -0x58(%rsp)
shrb $0x4, %bl
movl %r11d, %edi
shlb $0x4, %dil
orb %bl, %dil
andb $0x3f, %dil
movzbl %dil, %edi
movq %rdi, -0x50(%rsp)
shrb $0x2, %r11b
movzbl %r11b, %edi
movq %rdi, -0x48(%rsp)
movl %r10d, %edi
andb $0x3f, %dil
movzbl %dil, %edi
movq %rdi, -0x40(%rsp)
shrb $0x6, %r10b
leal (,%r9,4), %edi
orb %r10b, %dil
andb $0x3f, %dil
movzbl %dil, %edi
movq %rdi, -0x38(%rsp)
shrb $0x4, %r9b
movl %r8d, %edi
shlb $0x4, %dil
orb %r9b, %dil
andb $0x3f, %dil
movzbl %dil, %edi
movq %rdi, -0x30(%rsp)
shrb $0x2, %r8b
movzbl %r8b, %edi
movq %rdi, -0x28(%rsp)
movl %edx, %edi
andb $0x3f, %dil
movzbl %dil, %edi
movq %rdi, -0x20(%rsp)
shrb $0x6, %dl
leal (,%rcx,4), %edi
orb %dl, %dil
andb $0x3f, %dil
movzbl %dil, %edx
movq %rdx, -0x18(%rsp)
shrb $0x4, %cl
movl %eax, %edx
shlb $0x4, %dl
orb %cl, %dl
andb $0x3f, %dl
movzbl %dl, %ecx
movq %rcx, -0x10(%rsp)
shrb $0x2, %al
movzbl %al, %eax
movq %rax, -0x8(%rsp)
xorl %eax, %eax
leaq 0xf5b8(%rip), %rcx      # 0x362a0
movq -0x60(%rsp,%rax,8), %rdi
movb $0x3f, %dl
cmpq $0x3f, %rdi
ja 0x26cf8
movb (%rdi,%rcx), %dl
movb %dl, (%rsi,%rax)
incq %rax
cmpq $0xb, %rax
jne 0x26ce8
movb $0x0, 0xb(%rsi)
popq %rbx
popq %r14
popq %rbp
retq