// File: 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
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rcx, -0x240(%rbp)
movq %rdx, -0x238(%rbp)
movq %rdi, -0x230(%rbp)
movq %rdi, %rax
movq %rax, -0x228(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x220(%rbp)
movb $0x0, -0x21(%rbp)
callq 0xec50
leaq -0x49(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x34d0
movq -0x218(%rbp), %rcx
leaq 0x10d91(%rip), %rsi     # 0x232dd
leaq -0x48(%rbp), %rdi
movl $0x4, %edx
callq 0x3330
jmp 0x1255c
leaq -0x49(%rbp), %rdi
callq 0x3300
movq -0x238(%rbp), %rdi
callq 0x31f0
movq -0x240(%rbp), %rdi
movq %rax, -0x248(%rbp)
callq 0x31f0
movq %rax, %rcx
movq -0x248(%rbp), %rax
movl %ecx, %edx
movl %eax, %ecx
movl %ecx, %eax
movl %edx, %ecx
leal 0x2(%rax,%rcx), %eax
movsbl %al, %esi
leaq -0x48(%rbp), %rdi
callq 0x31b0
jmp 0x125a8
movq -0x238(%rbp), %rdi
callq 0x31f0
movsbl %al, %esi
leaq -0x48(%rbp), %rdi
callq 0x31b0
jmp 0x125c2
movq -0x238(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x33b0
jmp 0x125d4
movq -0x240(%rbp), %rdi
callq 0x31f0
movsbl %al, %esi
leaq -0x48(%rbp), %rdi
callq 0x31b0
jmp 0x125ee
movq -0x240(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x33b0
jmp 0x12600
leaq -0x81(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x34d0
movq -0x250(%rbp), %rcx
leaq 0x13a03(%rip), %rsi     # 0x26024
leaq -0x80(%rbp), %rdi
movl $0x1, %edx
callq 0x3330
jmp 0x12631
leaq -0x81(%rbp), %rdi
callq 0x3300
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x34d0
movq -0x258(%rbp), %rcx
leaq 0x13bc1(%rip), %rsi     # 0x2621f
leaq -0xa8(%rbp), %rdi
movl $0x1, %edx
callq 0x3330
jmp 0x12671
leaq -0xa9(%rbp), %rdi
callq 0x3300
leaq -0xd0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3120
jmp 0x1268f
movq -0x220(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x14a30
movl %eax, -0x25c(%rbp)
jmp 0x126aa
leaq -0x48(%rbp), %rdi
callq 0x31f0
movq %rax, %rcx
movl -0x25c(%rbp), %eax
cmpl %ecx, %eax
sete %al
xorb $-0x1, %al
movb %al, -0x25d(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x31a0
movb -0x25d(%rbp), %al
testb $0x1, %al
jne 0x126e4
jmp 0x127ec
movq 0x1c8e5(%rip), %rax     # 0x2efd0
movq (%rax), %rax
movq %rax, -0x268(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30d0
movq -0x268(%rbp), %rdi
movq %rax, %r9
leaq 0x13b0f(%rip), %rsi     # 0x26221
leaq 0x128fc(%rip), %rdx     # 0x25015
leaq 0x13146(%rip), %rcx     # 0x25866
xorl %eax, %eax
movl $0x3ad, %r8d            # imm = 0x3AD
callq 0x3410
movq 0x1c86c(%rip), %rax     # 0x2efa0
movq (%rax), %rdi
callq 0x3350
jmp 0x1273e
movq 0x1c88b(%rip), %rax     # 0x2efd0
movq (%rax), %rdi
callq 0x3350
jmp 0x1274f
movl $0x1, %edi
callq 0x3370
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x3300
jmp 0x12dfe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12dd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x81(%rbp), %rdi
callq 0x3300
jmp 0x12dd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x3300
jmp 0x12dce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12dc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x31a0
jmp 0x12dc2
jmp 0x127ee
jmp 0x127f0
movl $0x1, %edi
callq 0x3210
jmp 0x127fc
movq -0x220(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
movl $0x1, %edx
callq 0x13fd0
jmp 0x12816
leaq -0xf0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x12e40
testb $0x1, %al
jne 0x1282c
jmp 0x1289c
leaq -0xf0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x12e40
testb $0x1, %al
jne 0x12845
jmp 0x1289c
xorl %eax, %eax
movl %eax, %esi
leaq -0xf0(%rbp), %rdi
callq 0x3520
movq %rax, -0x270(%rbp)
jmp 0x1285e
movq -0x270(%rbp), %rax
movsbl (%rax), %esi
leaq 0x13a2c(%rip), %rdi     # 0x2629b
xorl %eax, %eax
callq 0x3050
jmp 0x12878
movb $0x1, -0x21(%rbp)
movl $0x1, -0xf4(%rbp)
jmp 0x12d84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12db6
movq -0x220(%rbp), %rsi
leaq -0x118(%rbp), %rdi
movl $0x1, %edx
callq 0x13fd0
jmp 0x128b6
leaq -0x118(%rbp), %rdi
callq 0x31f0
cmpq $0x1, %rax
je 0x128fc
leaq 0x139fb(%rip), %rdi     # 0x262ca
xorl %eax, %eax
callq 0x3050
jmp 0x128d8
movb $0x1, -0x21(%rbp)
movl $0x1, -0xf4(%rbp)
jmp 0x12d68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12d76
leaq -0x139(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x34d0
movq -0x278(%rbp), %rcx
leaq 0x10978(%rip), %rsi     # 0x23295
leaq -0x138(%rbp), %rdi
movl $0x4, %edx
callq 0x3330
jmp 0x12930
leaq -0x139(%rbp), %rdi
callq 0x3300
leaq -0x138(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x33b0
jmp 0x12951
leaq -0x161(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x34d0
movq -0x280(%rbp), %rcx
leaq 0x108f3(%rip), %rsi     # 0x23265
leaq -0x160(%rbp), %rdi
movl $0x2, %edx
callq 0x3330
jmp 0x12985
leaq -0x161(%rbp), %rdi
callq 0x3300
leaq -0x188(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x3120
jmp 0x129a6
movq -0x220(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x14a30
jmp 0x129bb
leaq -0x188(%rbp), %rdi
callq 0x31a0
xorl %eax, %eax
movl %eax, %esi
leaq -0x118(%rbp), %rdi
callq 0x3520
movq %rax, -0x288(%rbp)
jmp 0x129e0
movq -0x288(%rbp), %rax
movsbq (%rax), %rax
movq %rax, -0x290(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x31f0
movq -0x290(%rbp), %rdx
movq -0x220(%rbp), %rsi
addq %rax, %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x13fd0
jmp 0x12a1d
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x31f0
movq -0x298(%rbp), %rsi
movq %rax, %rdx
addq $-0x2, %rdx
leaq -0x1c8(%rbp), %rdi
movq $-0x1, %rcx
callq 0x32c0
jmp 0x12a53
leaq -0x1c8(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x12e40
movb %al, -0x299(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x31a0
movb -0x299(%rbp), %al
testb $0x1, %al
jne 0x12a87
jmp 0x12b34
leaq 0x1385d(%rip), %rdi     # 0x262eb
xorl %eax, %eax
callq 0x3050
jmp 0x12a97
movb $0x1, -0x21(%rbp)
movl $0x1, -0xf4(%rbp)
jmp 0x12d1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x139(%rbp), %rdi
callq 0x3300
jmp 0x12d76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12d5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x161(%rbp), %rdi
callq 0x3300
jmp 0x12d5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12d4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x31a0
jmp 0x12d4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x12d42
xorl %eax, %eax
movl %eax, %esi
leaq -0x1a8(%rbp), %rdi
callq 0x3520
movq %rax, -0x2a8(%rbp)
jmp 0x12b4d
movq -0x2a8(%rbp), %rax
movsbl (%rax), %eax
cmpl $-0x24, %eax
jne 0x12bdb
leaq -0x1a8(%rbp), %rdi
movl $0x1, %esi
callq 0x3520
movq %rax, -0x2b0(%rbp)
jmp 0x12b76
movq -0x2b0(%rbp), %rax
movsbq (%rax), %rcx
leaq -0x1e8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
movl $0x2, %edx
callq 0x32c0
jmp 0x12b9b
movq -0x230(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x11160
jmp 0x12bb0
leaq -0x1e8(%rbp), %rdi
callq 0x31a0
jmp 0x12bdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x31a0
jmp 0x12d42
xorl %eax, %eax
movl %eax, %esi
leaq -0x1a8(%rbp), %rdi
callq 0x3520
movq %rax, -0x2b8(%rbp)
jmp 0x12bf4
movq -0x2b8(%rbp), %rax
movsbl (%rax), %eax
cmpl $-0x25, %eax
jne 0x12d0e
movq $0x1, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x31f0
movq %rax, %rcx
movq -0x2c0(%rbp), %rax
subq $0x2, %rcx
cmpq %rcx, %rax
jae 0x12d0c
movq -0x1f0(%rbp), %rsi
movq %rsi, %rax
incq %rax
movq %rax, -0x2d0(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3520
movq %rax, -0x2c8(%rbp)
jmp 0x12c6c
movq -0x2d0(%rbp), %rdx
movq -0x2c8(%rbp), %rax
movsbq (%rax), %rcx
leaq -0x210(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x32c0
jmp 0x12c93
movq -0x230(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x11160
jmp 0x12ca8
leaq -0x210(%rbp), %rdi
callq 0x31a0
movq -0x1f0(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x3520
movq %rax, -0x2d8(%rbp)
jmp 0x12cd0
movq -0x2d8(%rbp), %rax
movsbl (%rax), %eax
addl $0x1, %eax
cltq
addq -0x1f0(%rbp), %rax
movq %rax, -0x1f0(%rbp)
jmp 0x12c12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x31a0
jmp 0x12d42
jmp 0x12d0e
movb $0x1, -0x21(%rbp)
movl $0x1, -0xf4(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x31a0
leaq -0x160(%rbp), %rdi
callq 0x31a0
leaq -0x138(%rbp), %rdi
callq 0x31a0
jmp 0x12d68
leaq -0x1a8(%rbp), %rdi
callq 0x31a0
leaq -0x160(%rbp), %rdi
callq 0x31a0
leaq -0x138(%rbp), %rdi
callq 0x31a0
jmp 0x12d76
leaq -0x118(%rbp), %rdi
callq 0x31a0
jmp 0x12d84
leaq -0x118(%rbp), %rdi
callq 0x31a0
jmp 0x12db6
leaq -0xf0(%rbp), %rdi
callq 0x31a0
leaq -0xa8(%rbp), %rdi
callq 0x31a0
leaq -0x80(%rbp), %rdi
callq 0x31a0
leaq -0x48(%rbp), %rdi
callq 0x31a0
testb $0x1, -0x21(%rbp)
jne 0x12dee
jmp 0x12de2
leaq -0xf0(%rbp), %rdi
callq 0x31a0
leaq -0xa8(%rbp), %rdi
callq 0x31a0
leaq -0x80(%rbp), %rdi
callq 0x31a0
leaq -0x48(%rbp), %rdi
callq 0x31a0
jmp 0x12dfe
movq -0x230(%rbp), %rdi
callq 0xf6b0
movq -0x228(%rbp), %rax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
movq -0x230(%rbp), %rdi
callq 0xf6b0
movq -0x58(%rbp), %rdi
callq 0x34b0
nopw %cs:(%rax,%rax)
nopl (%rax)