// File: gulamf[P]NRF24LE1Flash/main.cpp
// Function: OpenSerialPort(unsigned int)
bool OpenSerialPort(speed_t baudRate)
{
    string s = port;
    strreplace(s,"/dev/", "");
    string lockFileName = "/tmp/LCK.." + s;

    try
    {
        ifstream *lockFile = new ifstream(lockFileName.c_str());
    }
    catch (...)
    {
        cout << "Error: Lock file " + lockFileName + " exists!  It is likely that another serial terminal has this port open!\r\n";
        return false;
    }

    progSerPort = open(port.c_str(),O_RDWR | O_NOCTTY | O_SYNC );

    set_interface_attribs (progSerPort, B38400, 0);
    set_blocking (progSerPort, 0);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl %edi, -0x8(%rbp)
leaq 0x9b4b(%rip), %rsi      # 0xe3b0
leaq -0x28(%rbp), %rdi
callq 0x3170
leaq -0x69(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x34d0
movq -0x120(%rbp), %rdx
leaq 0x5bc1(%rip), %rsi      # 0xa44d
leaq -0x68(%rbp), %rdi
callq 0x7370
jmp 0x4897
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x34d0
movq -0x128(%rbp), %rdx
leaq 0x61df(%rip), %rsi      # 0xaa97
leaq -0xa0(%rbp), %rdi
callq 0x7370
jmp 0x48c6
leaq -0x48(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x9790
jmp 0x48e0
leaq -0x48(%rbp), %rdi
callq 0x3568
leaq -0xa0(%rbp), %rdi
callq 0x3568
leaq -0xa1(%rbp), %rdi
callq 0x3300
leaq -0x68(%rbp), %rdi
callq 0x3568
leaq -0x69(%rbp), %rdi
callq 0x3300
leaq 0x5b39(%rip), %rsi      # 0xa453
leaq -0xc8(%rbp), %rdi
leaq -0x28(%rbp), %rdx
callq 0x7420
jmp 0x492c
movl $0x208, %edi            # imm = 0x208
callq 0x32b0
movq %rax, -0x130(%rbp)
jmp 0x493f
leaq -0xc8(%rbp), %rdi
callq 0x3160
movq -0x130(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x34f0
jmp 0x4961
movq -0x130(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x4aeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x49bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x49a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3568
leaq -0xa1(%rbp), %rdi
callq 0x3300
leaq -0x68(%rbp), %rdi
callq 0x3568
leaq -0x69(%rbp), %rdi
callq 0x3300
jmp 0x4b7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4b7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4a07
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0x32c0
movq -0x78(%rbp), %rdi
callq 0x3150
leaq 0x5a47(%rip), %rsi      # 0xa45e
leaq -0x110(%rbp), %rdi
leaq -0xc8(%rbp), %rdx
callq 0x7420
jmp 0x4a2c
leaq 0x5a3d(%rip), %rdx      # 0xa470
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x7530
jmp 0x4a48
movq 0x9589(%rip), %rdi      # 0xdfd8
leaq -0xf0(%rbp), %rsi
callq 0x3270
jmp 0x4a5d
leaq -0xf0(%rbp), %rdi
callq 0x3568
leaq -0x110(%rbp), %rdi
callq 0x3568
movb $0x0, -0x1(%rbp)
movl $0x1, -0x114(%rbp)
callq 0x3480
jmp 0x4acc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4adf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4abe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3568
leaq -0x110(%rbp), %rdi
callq 0x3568
jmp 0x4adf
jmp 0x4b4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x4b6e
callq 0x3480
jmp 0x4ae6
jmp 0x4b6e
leaq 0x98be(%rip), %rdi      # 0xe3b0
callq 0x3160
movq %rax, %rdi
xorl %eax, %eax
movl $0x101102, %esi         # imm = 0x101102
callq 0x3210
movl %eax, -0x134(%rbp)
jmp 0x4b0e
movl -0x134(%rbp), %eax
movl %eax, 0x98be(%rip)      # 0xe3d8
movl 0x98b8(%rip), %edi      # 0xe3d8
movl $0xf, %esi
xorl %edx, %edx
callq 0x4660
jmp 0x4b2e
movl 0x98a4(%rip), %edi      # 0xe3d8
xorl %esi, %esi
callq 0x47a0
jmp 0x4b3d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x114(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3568
leaq -0x28(%rbp), %rdi
callq 0x3568
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x3568
leaq -0x28(%rbp), %rdi
callq 0x3568
movq -0x78(%rbp), %rdi
callq 0x34c0
movq %rax, %rdi
callq 0x7580
nopw %cs:(%rax,%rax)