// File: /workspace/github_cpp_makefile_star2_O3/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 -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 0x2200
movsbl 0x8(%r12), %esi
leaq -0x68(%rbp), %rdi
callq 0x2200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq -0x68(%rbp), %rdi
callq 0x20d0
movsbl 0x8(%r15), %esi
leaq -0x68(%rbp), %rdi
callq 0x2200
movq (%r15), %rsi
movq 0x8(%r15), %rdx
leaq -0x68(%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 -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0x188(%rbp), %rdi
callq 0x1394e
leaq -0x188(%rbp), %rsi
movq %r14, %rdi
callq 0xe93c
movl %eax, %r15d
movl -0x60(%rbp), %r13d
movq -0x188(%rbp), %rdi
cmpq %r12, %rdi
je 0xd2b8
callq 0x2220
cmpl %r13d, %r15d
jne 0xd65e
movl $0x1, %edi
callq 0x21d0
leaq -0xe8(%rbp), %rdi
movl $0x1, %edx
movq %r14, %rsi
callq 0xe17e
movq -0xe0(%rbp), %r15
cmpq -0x120(%rbp), %r15
jne 0xd30e
testq %r15, %r15
je 0xd341
movq -0x128(%rbp), %rsi
movq -0xe8(%rbp), %rdi
movq %r15, %rdx
callq 0x2260
testl %eax, %eax
je 0xd341
cmpq -0x100(%rbp), %r15
jne 0xd469
testq %r15, %r15
je 0xd341
movq -0x108(%rbp), %rsi
movq -0xe8(%rbp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x2260
testl %eax, %eax
jne 0xd470
leaq -0x148(%rbp), %rdi
movl $0x1, %edx
movq %r14, %rsi
callq 0xe17e
cmpq $0x1, -0x140(%rbp)
jne 0xd48c
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
movl $0x1, %edx
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 0x1394e
leaq -0x168(%rbp), %rsi
movq %r14, %rdi
callq 0xe93c
movq -0x168(%rbp), %rdi
cmpq %r15, %rdi
je 0xd3fc
callq 0x2220
movq -0x148(%rbp), %rax
movsbq (%rax), %rdx
addq -0xa0(%rbp), %rdx
leaq -0x88(%rbp), %rdi
movq %r14, %rsi
callq 0xe17e
leaq -0x88(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq $-0x2, %rdx
leaq -0x48(%rbp), %rdi
movq $-0x1, %rcx
callq 0x2270
movq -0x40(%rbp), %rdx
cmpq -0xa0(%rbp), %rdx
jne 0xd4a1
movq -0x48(%rbp), %r14
testq %rdx, %rdx
je 0xd4aa
movq -0xa8(%rbp), %rsi
movq %r14, %rdi
callq 0x2260
testl %eax, %eax
setne %r15b
jmp 0xd4ad
movq -0xe8(%rbp), %r12
movsbl (%r12), %esi
leaq 0xb92d(%rip), %rdi      # 0x18da9
xorl %eax, %eax
callq 0x2060
leaq -0x58(%rbp), %r14
jmp 0xd5f6
leaq 0xbac7(%rip), %rdi      # 0x18f5a
callq 0x23c0
leaq -0x58(%rbp), %r14
jmp 0xd5e1
movb $0x1, %r15b
movq -0x48(%rbp), %r14
jmp 0xd4ad
xorl %r15d, %r15d
leaq -0x38(%rbp), %rax
cmpq %rax, %r14
je 0xd4be
movq %r14, %rdi
callq 0x2220
testb %r15b, %r15b
je 0xd4db
leaq 0xba60(%rip), %rdi      # 0x18f2a
callq 0x23c0
movq -0x88(%rbp), %rdi
jmp 0xd59f
movq -0x88(%rbp), %rdi
movb (%rdi), %al
cmpb $-0x24, %al
jne 0xd529
movsbq 0x1(%rdi), %rcx
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl $0x2, %edx
callq 0x2270
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x13a8a
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xd520
callq 0x2220
movq -0x88(%rbp), %rdi
movb (%rdi), %al
cmpb $-0x25, %al
jne 0xd59f
movq -0x80(%rbp), %rax
andq $-0x2, %rax
cmpq $0x2, %rax
je 0xd59f
movl $0x1, %r13d
leaq -0x48(%rbp), %r14
leaq -0x88(%rbp), %r15
leaq 0x1(%r13), %r12
movsbq (%rdi,%r13), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13a8a
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xd580
callq 0x2220
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rax
movsbq (%rdi,%r13), %rcx
addq %rcx, %r12
addq $-0x2, %rax
movq %r12, %r13
cmpq %rax, %r12
jb 0xd54c
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xd5ad
callq 0x2220
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
leaq -0x58(%rbp), %r14
leaq -0xb8(%rbp), %r15
je 0xd5d0
callq 0x2220
movq -0xc8(%rbp), %rdi
cmpq %r15, %rdi
je 0xd5e1
callq 0x2220
leaq -0x138(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd5f6
callq 0x2220
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd60b
callq 0x2220
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xd623
callq 0x2220
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0xd63b
callq 0x2220
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0xd649
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 0xd6b0
jmp 0xd6ab
jmp 0xd6ab
jmp 0xd67c
movq %rax, %r14
movq -0x168(%rbp), %rdi
cmpq %r15, %rdi
jne 0xd6d2
jmp 0xd6d7
movq %rax, %r14
jmp 0xd6d7
movq %rax, %r14
jmp 0xd6ef
movq %rax, %r14
jmp 0xd71c
jmp 0xd733
movq %rax, %r14
movq -0x188(%rbp), %rdi
cmpq %r12, %rdi
jne 0xd72c
jmp 0xd736
movq %rax, %r14
jmp 0xd6c5
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xd6c5
callq 0x2220
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd6d7
callq 0x2220
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xd6ef
callq 0x2220
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xd707
callq 0x2220
leaq -0x138(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd71c
callq 0x2220
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd736
callq 0x2220
jmp 0xd736
movq %rax, %r14
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xd74e
callq 0x2220
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0xd76b
callq 0x2220
jmp 0xd76b
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xd77d
callq 0x2220
movq %rbx, %rdi
callq 0xb2cc
movq %r14, %rdi
callq 0x2400
nop