// File: /workspace/github_cpp_makefile_star2_O1/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
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq -0x38(%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 -0x48(%rbp), %rdi
callq 0x2200
movsbl 0x8(%r12), %esi
leaq -0x48(%rbp), %rdi
callq 0x2200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq -0x48(%rbp), %rdi
callq 0x20d0
movsbl 0x8(%r15), %esi
leaq -0x48(%rbp), %rdi
callq 0x2200
movq (%r15), %rsi
movq 0x8(%r15), %rdx
leaq -0x48(%rbp), %rdi
callq 0x20d0
leaq -0x118(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movw $0x61, (%rcx)
movl $0x1, %eax
movq %rax, -0x8(%rcx)
leaq -0xf8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movw $0x9f, (%rcx)
movq %rax, -0x8(%rcx)
leaq -0x178(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x188(%rbp), %rdi
callq 0x1372a
leaq -0x188(%rbp), %rsi
movq %r14, %rdi
callq 0xe6b2
movl %eax, %r15d
movl -0x40(%rbp), %r13d
movq -0x188(%rbp), %rdi
cmpq %r12, %rdi
je 0xcfda
callq 0x2220
cmpl %r13d, %r15d
jne 0xd35e
movl $0x1, %edi
callq 0x21d0
leaq -0xe8(%rbp), %rdi
movl $0x1, %edx
movq %r14, %rsi
callq 0xde7c
movq -0xe0(%rbp), %r15
cmpq -0x120(%rbp), %r15
jne 0xd030
testq %r15, %r15
je 0xd079
movq -0x128(%rbp), %rsi
movq -0xe8(%rbp), %rdi
movq %r15, %rdx
callq 0x2260
testl %eax, %eax
je 0xd079
cmpq -0x100(%rbp), %r15
jne 0xd058
testq %r15, %r15
je 0xd079
movq -0x108(%rbp), %rsi
movq -0xe8(%rbp), %rdi
movq %r15, %rdx
callq 0x2260
testl %eax, %eax
je 0xd079
movq -0xe8(%rbp), %rax
movsbl (%rax), %esi
leaq 0xbd40(%rip), %rdi      # 0x18da9
xorl %eax, %eax
callq 0x2060
leaq -0x38(%rbp), %r14
jmp 0xd2f6
leaq -0x148(%rbp), %rdi
movl $0x1, %edx
movq %r14, %rsi
callq 0xde7c
movq -0x140(%rbp), %rdx
cmpq $0x1, %rdx
jne 0xd19f
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
movl $0xc000, (%rax)         # imm = 0xC000
movq $0x4, -0x8(%rax)
movb $0x0, 0x4(%rax)
movq -0x148(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x20d0
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
movw $0x90, (%rax)
movq $0x2, -0x8(%rax)
movb $0x0, 0x2(%rax)
leaq -0x158(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
addq %rsi, %rdx
leaq -0x168(%rbp), %rdi
callq 0x1372a
leaq -0x168(%rbp), %rsi
movq %r14, %rdi
callq 0xe6b2
movq -0x168(%rbp), %rdi
cmpq %r15, %rdi
je 0xd132
callq 0x2220
movq -0x148(%rbp), %rax
movsbq (%rax), %rdx
addq -0xa0(%rbp), %rdx
leaq -0x68(%rbp), %rdi
movq %r14, %rsi
callq 0xde7c
leaq -0x68(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq $-0x2, %rdx
leaq -0x88(%rbp), %rdi
movq $-0x1, %rcx
callq 0x2270
movq -0x80(%rbp), %rdx
movb $0x1, %r14b
cmpq -0xa0(%rbp), %rdx
jne 0xd1b7
testq %rdx, %rdx
je 0xd1b4
movq -0xa8(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x2260
testl %eax, %eax
setne %r14b
jmp 0xd1b7
leaq 0xbdb4(%rip), %rdi      # 0x18f5a
callq 0x23c0
leaq -0x38(%rbp), %r14
jmp 0xd2e1
xorl %r14d, %r14d
leaq -0x78(%rbp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0xd1ca
callq 0x2220
testb %r14b, %r14b
je 0xd1e0
leaq 0xbd54(%rip), %rdi      # 0x18f2a
callq 0x23c0
jmp 0xd29b
movq -0x68(%rbp), %rax
cmpb $-0x24, (%rax)
jne 0xd223
movsbq 0x1(%rax), %rcx
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x2, %edx
callq 0x2270
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x1385e
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xd223
callq 0x2220
movq -0x68(%rbp), %rax
cmpb $-0x25, (%rax)
jne 0xd29b
movq -0x60(%rbp), %rax
andq $-0x2, %rax
cmpq $0x2, %rax
je 0xd29b
movl $0x1, %r13d
leaq -0x88(%rbp), %r14
leaq -0x68(%rbp), %r15
leaq 0x1(%r13), %rdx
movq -0x68(%rbp), %rax
movsbq (%rax,%r13), %rcx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1385e
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xd27f
callq 0x2220
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
movsbq (%rax,%r13), %rax
addq %rax, %r13
incq %r13
addq $-0x2, %rcx
cmpq %rcx, %r13
jb 0xd24b
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd2ad
callq 0x2220
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
leaq -0x38(%rbp), %r14
leaq -0xb8(%rbp), %r15
je 0xd2d0
callq 0x2220
movq -0xc8(%rbp), %rdi
cmpq %r15, %rdi
je 0xd2e1
callq 0x2220
leaq -0x138(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd2f6
callq 0x2220
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd30b
callq 0x2220
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xd323
callq 0x2220
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0xd33b
callq 0x2220
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xd349
callq 0x2220
movq %rbx, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3a4c
jmp 0xd3b0
jmp 0xd3ab
jmp 0xd3ab
jmp 0xd37c
movq %rax, %r14
movq -0x168(%rbp), %rdi
cmpq %r15, %rdi
jne 0xd3d1
jmp 0xd3d6
movq %rax, %r14
jmp 0xd3d6
movq %rax, %r14
jmp 0xd3ee
movq %rax, %r14
jmp 0xd41b
jmp 0xd432
movq %rax, %r14
movq -0x188(%rbp), %rdi
cmpq %r12, %rdi
jne 0xd42b
jmp 0xd435
movq %rax, %r14
jmp 0xd3c4
movq %rax, %r14
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0xd3c4
callq 0x2220
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd3d6
callq 0x2220
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xd3ee
callq 0x2220
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xd406
callq 0x2220
leaq -0x138(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd41b
callq 0x2220
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd435
callq 0x2220
jmp 0xd435
movq %rax, %r14
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xd44d
callq 0x2220
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0xd46a
callq 0x2220
jmp 0xd46a
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xd47c
callq 0x2220
movq %rbx, %rdi
callq 0xafd4
movq %r14, %rdi
callq 0x2400