// File: /workspace/github_cpp_makefile_star2_O2/FFY00[P]uicc/include/uicc.h
// Function: USIM::authenticate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
vector<string> authenticate(string rand, string autn) {
        vector<string> ret;
        string order(u8"\x00\x88\x00\x81",4);
        order+=(unsigned char) (rand.size()+autn.size()+2);
        order+=(unsigned char) rand.size();
        order+=rand;
        order+=(unsigned char) autn.size();
        order+=autn;
        string answerKeys(u8"\x61",1);
        string answerAUTS(u8"\x9f",1);

        Assert(write(order)==(int)order.size(),"");
        // Cards need CPU procesing, so delay to check Milenage
        sleep(1);
        string answer=read(1);

        if ( answer != answerKeys && answer != answerAUTS) {
            printf("Not possible answer to milenage challenge: %x\n", answer[0]);
            return ret;
        }

        string size=read(1);

        if (size.size() !=1) {
            printf("No answer to mileange challenge\n");
            return ret;
        }

        string getData(u8"\x00\xc0\x00\x00",4);
        getData+=size;
        string good(u8"\x90\x00",2);
        write(getData);
        string values=read(size[0] + good.size());

        if ( values.substr(values.size()-2) != good) {
            printf("Can't get APDU in return of millenage challenge\n");
            return ret;
        }

        if (values[0] == '\xDC' ) // we have a AUTS answer encoded as len+val
            ret.push_back(values.substr(2,values[1]));

        if (values[0] == '\xDB' ) { //we have the keys
            size_t pos=1;
            while (pos < values.size()-2 ) {
                ret.push_back(values.substr(pos+1,values[pos]));
                pos+=values[pos]+1;
            }
        }

        return ret;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movl $0x81008800, (%rax)     # imm = 0x81008800
movq $0x4, -0x8(%rax)
movb $0x0, 0x4(%rax)
movl 0x8(%rcx), %eax
addl 0x8(%rdx), %eax
addb $0x2, %al
movsbl %al, %esi
leaq -0x68(%rbp), %rdi
callq 0x21f0
movsbl 0x8(%r12), %esi
leaq -0x68(%rbp), %rdi
callq 0x21f0
leaq -0x68(%rbp), %rdi
movq %r12, %rsi
callq 0x2470
movsbl 0x8(%r15), %esi
leaq -0x68(%rbp), %rdi
callq 0x21f0
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x2470
leaq -0x178(%rbp), %rax
movq %rax, -0x10(%rax)
movw $0x61, (%rax)
pushq $0x1
popq %rcx
movq %rcx, -0x8(%rax)
leaq -0x158(%rbp), %rax
movq %rax, -0x10(%rax)
movw $0x9f, (%rax)
movq %rcx, -0x8(%rax)
leaq -0x148(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2330
leaq -0x148(%rbp), %rsi
movq %r14, %rdi
callq 0xb178
movl %eax, %r15d
movl -0x60(%rbp), %r12d
leaq -0x148(%rbp), %rdi
callq 0x2120
cmpl %r12d, %r15d
jne 0xa4ec
pushq $0x1
popq %rdi
callq 0x21c0
leaq -0xc8(%rbp), %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0xac6e
leaq -0xc8(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0xa602
testb %al, %al
je 0xa2c9
leaq -0xc8(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xa602
testb %al, %al
je 0xa2c9
movq -0xc8(%rbp), %rax
movsbl (%rax), %esi
leaq 0x9acc(%rip), %rdi      # 0x13d89
xorl %eax, %eax
callq 0x2050
jmp 0xa4aa
leaq -0xa8(%rbp), %rdi
pushq $0x1
popq %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0xac6e
cmpq $0x1, -0xa0(%rbp)
jne 0xa3d7
leaq -0xf8(%rbp), %rax
movq %rax, -0x10(%rax)
movl $0xc000, (%rax)         # imm = 0xC000
movq $0x4, -0x8(%rax)
movb $0x0, 0x4(%rax)
leaq -0x108(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2470
leaq -0xd8(%rbp), %rax
movq %rax, -0x10(%rax)
movw $0x90, (%rax)
movq $0x2, -0x8(%rax)
movb $0x0, 0x2(%rax)
leaq -0x128(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x2330
leaq -0x128(%rbp), %rsi
movq %r14, %rdi
callq 0xb178
leaq -0x128(%rbp), %rdi
callq 0x2120
movq -0xa8(%rbp), %rax
movsbq (%rax), %rdx
addq -0xe0(%rbp), %rdx
leaq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0xac6e
leaq -0x48(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq $-0x2, %rdx
leaq -0x88(%rbp), %rdi
pushq $-0x1
popq %rcx
callq 0x2260
leaq -0x88(%rbp), %r14
leaq -0xe8(%rbp), %rsi
movq %r14, %rdi
callq 0xa602
movl %eax, %r12d
movq %r14, %rdi
callq 0x2120
testb %r12b, %r12b
je 0xa3e8
leaq 0x9b3d(%rip), %rdi      # 0x13f0a
callq 0x23c0
jmp 0xa47d
leaq 0x9b5c(%rip), %rdi      # 0x13f3a
callq 0x23c0
jmp 0xa49e
movq -0x48(%rbp), %rax
movb (%rax), %cl
cmpb $-0x24, %cl
jne 0xa42c
movsbq 0x1(%rax), %rcx
leaq -0x88(%rbp), %rdi
leaq -0x48(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x2260
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0xf1f8
leaq -0x88(%rbp), %rdi
callq 0x2120
movq -0x48(%rbp), %rax
movb (%rax), %cl
cmpb $-0x25, %cl
jne 0xa47d
leaq -0x48(%rbp), %r12
movq -0x40(%rbp), %rcx
addq $-0x2, %rcx
cmpq %rcx, %r15
jae 0xa47d
leaq 0x1(%r15), %r13
movsbq (%rax,%r15), %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2260
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1f8
movq %r14, %rdi
callq 0x2120
movq -0x48(%rbp), %rax
movsbq (%rax,%r15), %rcx
addq %rcx, %r13
movq %r13, %r15
jmp 0xa435
leaq -0x48(%rbp), %rdi
callq 0x2120
leaq -0xe8(%rbp), %rdi
callq 0x2120
leaq -0x108(%rbp), %rdi
callq 0x2120
leaq -0xa8(%rbp), %rdi
callq 0x2120
leaq -0xc8(%rbp), %rdi
callq 0x2120
leaq -0x168(%rbp), %rdi
callq 0x2120
leaq -0x188(%rbp), %rdi
callq 0x2120
leaq -0x68(%rbp), %rdi
callq 0x2120
movq %rbx, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xeadd(%rip), %r14      # 0x18fd0
movq (%r14), %rbx
callq 0x2040
movl (%rax), %edi
callq 0x20c0
leaq 0x9806(%rip), %rsi      # 0x13d0f
leaq 0x8a51(%rip), %rdx      # 0x12f61
leaq 0x8f75(%rip), %rcx      # 0x1348c
movq %rbx, %rdi
movl $0x3ad, %r8d            # imm = 0x3AD
movq %rax, %r9
xorl %eax, %eax
callq 0x2360
movq 0xea77(%rip), %rax      # 0x18fa8
movq (%rax), %rdi
callq 0x22c0
movq (%r14), %rdi
callq 0x22c0
pushq $0x1
popq %rdi
callq 0x22e0
jmp 0xa584
jmp 0xa57f
jmp 0xa57f
jmp 0xa55d
movq %rax, %r14
leaq -0x128(%rbp), %rdi
jmp 0xa597
movq %rax, %r14
jmp 0xa59c
movq %rax, %r14
jmp 0xa5a8
movq %rax, %r14
jmp 0xa5c0
jmp 0xa57a
movq %rax, %r14
leaq -0x148(%rbp), %rdi
jmp 0xa5c7
movq %rax, %r14
jmp 0xa5cc
movq %rax, %r14
jmp 0xa593
movq %rax, %r14
leaq -0x88(%rbp), %rdi
callq 0x2120
leaq -0x48(%rbp), %rdi
callq 0x2120
leaq -0xe8(%rbp), %rdi
callq 0x2120
leaq -0x108(%rbp), %rdi
callq 0x2120
leaq -0xa8(%rbp), %rdi
callq 0x2120
leaq -0xc8(%rbp), %rdi
callq 0x2120
leaq -0x168(%rbp), %rdi
callq 0x2120
leaq -0x188(%rbp), %rdi
callq 0x2120
jmp 0xa5e9
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x8a5a
movq %r14, %rdi
callq 0x2400