// File: FFY00[P]uicc/include/uicc.h
// Function: UICC::open[abi:cxx11](char*)
string open(char *portname) {
        Assert( (fd=::open(portname, O_RDWR | O_NOCTTY | O_SYNC)) >=0,
                "Failed to open %s", portname);
        struct termios tty;
        Assert (tcgetattr(fd, &tty) >= 0, "");
        tty.c_cflag &= ~( CSIZE );
        tty.c_cflag |= CLOCAL | CREAD | CS8 | PARENB | CSTOPB | HUPCL ;
        /* setup for non-canonical mode */
        tty.c_iflag &= ~(IGNBRK | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
        tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
        tty.c_oflag &= ~OPOST;
        /* fetch bytes as they become available */
        tty.c_cc[VMIN] = 0;
        tty.c_cc[VTIME] = 1;
        cfsetispeed(&tty, (speed_t)B9600);
        cfsetospeed(&tty, (speed_t)B9600);
        Assert (tcsetattr(fd, TCSANOW, &tty) == 0,"");
        // reset the UICC
        int iFlags;
        iFlags = 0 ;
        // turn off DTR
        ioctl(fd, TIOCMSET, &iFlags);
        struct timespec t= {0,1000*1000*100};
        nanosleep(&t,NULL);
        iFlags = 0xFFFF;
        // turn on DTR
        //iFlags = TIOCM_CTS  ;
        //ioctl(fd, TIOCMSET, &iFlags);
        return this->read();
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x80(%rbp)
movq %rdi, %rax
movq %rax, -0x78(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movl $0x101102, %esi         # imm = 0x101102
movb $0x0, %al
callq 0x3200
movq -0x70(%rbp), %rcx
movl %eax, 0x4(%rcx)
cmpl $0x0, %eax
jge 0xea6f
movq 0x205d3(%rip), %rax     # 0x2efd0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30d0
movq -0x88(%rbp), %rdi
movq %rax, %r9
movq -0x18(%rbp), %rax
leaq 0x16d98(%rip), %rsi     # 0x257c0
leaq 0x16e32(%rip), %rdx     # 0x25861
leaq 0x16e30(%rip), %rcx     # 0x25866
movl $0x12b, %r8d            # imm = 0x12B
movq %rax, (%rsp)
movb $0x0, %al
callq 0x3410
movq 0x20552(%rip), %rax     # 0x2efa0
movq (%rax), %rdi
callq 0x3350
movq 0x20573(%rip), %rax     # 0x2efd0
movq (%rax), %rdi
callq 0x3350
movl $0x1, %edi
callq 0x3370
jmp 0xea71
jmp 0xea73
movq -0x70(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x54(%rbp), %rsi
callq 0x3320
cmpl $0x0, %eax
jge 0xeaf9
movq 0x20541(%rip), %rax     # 0x2efd0
movq (%rax), %rax
movq %rax, -0x90(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30d0
movq -0x90(%rbp), %rdi
movq %rax, %r9
leaq 0x16dbf(%rip), %rsi     # 0x25875
leaq 0x16da4(%rip), %rdx     # 0x25861
leaq 0x16da2(%rip), %rcx     # 0x25866
movl $0x12d, %r8d            # imm = 0x12D
movb $0x0, %al
callq 0x3410
movq 0x204c8(%rip), %rax     # 0x2efa0
movq (%rax), %rdi
callq 0x3350
movq 0x204e9(%rip), %rax     # 0x2efd0
movq (%rax), %rdi
callq 0x3350
movl $0x1, %edi
callq 0x3370
jmp 0xeafb
movl -0x4c(%rbp), %eax
andl $-0x31, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
orl $0xdf0, %eax            # imm = 0xDF0
movl %eax, -0x4c(%rbp)
movl -0x54(%rbp), %eax
andl $0xfffffa16, %eax       # imm = 0xFFFFFA16
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
andl $0xffff7fb4, %eax       # imm = 0xFFFF7FB4
movl %eax, -0x48(%rbp)
movl -0x50(%rbp), %eax
andl $-0x2, %eax
movl %eax, -0x50(%rbp)
movb $0x0, -0x3d(%rbp)
movb $0x1, -0x3e(%rbp)
leaq -0x54(%rbp), %rdi
movl $0xd, %esi
callq 0x3190
leaq -0x54(%rbp), %rdi
movl $0xd, %esi
callq 0x3310
movq -0x70(%rbp), %rax
movl 0x4(%rax), %edi
xorl %esi, %esi
leaq -0x54(%rbp), %rdx
callq 0x33a0
cmpl $0x0, %eax
je 0xebda
movq 0x20460(%rip), %rax     # 0x2efd0
movq (%rax), %rax
movq %rax, -0x98(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30d0
movq -0x98(%rbp), %rdi
movq %rax, %r9
leaq 0x16d51(%rip), %rsi     # 0x258e8
leaq 0x16cc3(%rip), %rdx     # 0x25861
leaq 0x16cc1(%rip), %rcx     # 0x25866
movl $0x139, %r8d            # imm = 0x139
movb $0x0, %al
callq 0x3410
movq 0x203e7(%rip), %rax     # 0x2efa0
movq (%rax), %rdi
callq 0x3350
movq 0x20408(%rip), %rax     # 0x2efd0
movq (%rax), %rdi
callq 0x3350
movl $0x1, %edi
callq 0x3370
jmp 0xebdc
movq -0x70(%rbp), %rax
movl $0x0, -0x58(%rbp)
movl 0x4(%rax), %edi
movl $0x5418, %esi           # imm = 0x5418
leaq -0x58(%rbp), %rdx
movb $0x0, %al
callq 0x3400
movq 0x17747(%rip), %rax     # 0x26348
movq %rax, -0x68(%rbp)
movq 0x17744(%rip), %rax     # 0x26350
movq %rax, -0x60(%rbp)
leaq -0x68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x30c0
movq -0x80(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl $0xffff, -0x58(%rbp)    # imm = 0xFFFF
movl $0x400, %edx            # imm = 0x400
callq 0x13fd0
movq -0x78(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)