// File: gulamf[P]NRF24LE1Flash/main.cpp
// Function: set_interface_attribs(int, int, int)
int
set_interface_attribs (int fd, int speed, int parity)
{
        struct termios tty;
        memset (&tty, 0, sizeof tty);
        if (tcgetattr (fd, &tty) != 0)
        {
                cout <<  "error %d from tcgetattr" <<  errno;
                return -1;
        }

        cfsetospeed (&tty, speed);
        cfsetispeed (&tty, speed);

        tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;     // 8-bit chars
        // disable IGNBRK for mismatched speed tests; otherwise receive break
        // as \000 chars
        tty.c_iflag &= ~IGNBRK;         // disable break processing
        tty.c_lflag = 0;                // no signaling chars, no echo,
                                        // no canonical processing
        tty.c_oflag = 0;                // no remapping, no delays
        tty.c_cc[VMIN]  = 0;            // read doesn't block
        tty.c_cc[VTIME] = 5;            // 0.5 seconds read timeout

        tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl

        tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
                                        // enable reading
        tty.c_cflag &= ~(PARENB | PARODD);      // shut off parity
        tty.c_cflag |= parity;
        tty.c_cflag &= ~CSTOPB;
        tty.c_cflag &= ~CRTSCTS;

        if (tcsetattr (fd, TCSANOW, &tty) != 0)
        {
                cout << "error from tcsetattr:" << errno;
                return -1;
        }
        return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
leaq -0x4c(%rbp), %rdi
xorl %esi, %esi
movl $0x3c, %edx
callq 0x31a0
movl -0x8(%rbp), %edi
leaq -0x4c(%rbp), %rsi
callq 0x3350
cmpl $0x0, %eax
je 0x46c5
movq 0x993f(%rip), %rdi      # 0xdfd8
leaq 0x5d49(%rip), %rsi      # 0xa3e9
callq 0x32a0
movq %rax, -0x58(%rbp)
callq 0x3060
movq -0x58(%rbp), %rdi
movl (%rax), %esi
callq 0x34b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4790
movl -0xc(%rbp), %esi
leaq -0x4c(%rbp), %rdi
callq 0x3320
movl -0xc(%rbp), %esi
leaq -0x4c(%rbp), %rdi
callq 0x31d0
movl -0x44(%rbp), %eax
andl $-0x31, %eax
orl $0x30, %eax
movl %eax, -0x44(%rbp)
movl -0x4c(%rbp), %eax
andl $-0x2, %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
movb $0x0, -0x35(%rbp)
movb $0x5, -0x36(%rbp)
movl -0x4c(%rbp), %eax
andl $0xffffe3ff, %eax       # imm = 0xFFFFE3FF
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %eax
orl $0x880, %eax            # imm = 0x880
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
andl $0xfffffcff, %eax       # imm = 0xFFFFFCFF
movl %eax, -0x44(%rbp)
movl -0x10(%rbp), %eax
orl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
andl $-0x41, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x44(%rbp)
movl -0x8(%rbp), %edi
xorl %esi, %esi
leaq -0x4c(%rbp), %rdx
callq 0x3380
cmpl $0x0, %eax
je 0x4789
movq 0x9878(%rip), %rdi      # 0xdfd8
leaq 0x5c9a(%rip), %rsi      # 0xa401
callq 0x32a0
movq %rax, -0x60(%rbp)
callq 0x3060
movq -0x60(%rbp), %rdi
movl (%rax), %esi
callq 0x34b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4790
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)