// File: gulamf[P]NRF24LE1Flash/main.cpp
// Function: CheckUC()
bool CheckUC()
{
    string s = port;
    BLCommandReturnType blCommandReturnVal;


    if (resetpin == blenabled)
    {
        cout << "Reset and bootloader enable pins cannot be the same!\n";
        return false;
    }

    //begin start bootloader
    blCommandReturnVal = ExecuteCommandStartBootloader();

    if (blCommandReturnVal == BLCommandReturnType_SerialPortFailure)
    {
        cout << "Error: Could not open COM port!\n";
        return false;
    }
    else if (blCommandReturnVal != BLCommandReturnType_OK)
    {
        cout << "Error: Device not connected!\n";
        return false;
    }
    //end start	bootloader

    //begin device id check
    uint16_t devId = 0;

    blCommandReturnVal = ExecuteCommandGetDevID(&devId);

    if (blCommandReturnVal != BLCommandReturnType_OK)
    {
        cout << "Lost communications with device!\n";
        return false;
    }
    //end device id check

    //begin bootloader version check
    unsigned char blVersion = 0;

    blCommandReturnVal = ExecuteCommandGetBLVersion(&blVersion);

    if (blCommandReturnVal != BLCommandReturnType_OK)
    {
        cout << "Lost communications with device!\n";
        return false;
    }
    //end device id check

    //begin exit bootloader only
    blCommandReturnVal = ExecuteCommandExitBootloader();

    if (blCommandReturnVal != BLCommandReturnType_OK)
    {
        cout<< "Lost communications with device!\n";
        return false;
    }
    //end exit bootloader

    //If we have made it this far, then everything went to plan, so update the microcontroller type and bootloader version textboxes
    cout << ConvertBLDevIDToString(devId);
    cout << "Device found!\n";

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
leaq -0x28(%rbp), %rdi
leaq 0x90aa(%rip), %rsi      # 0xe3b0
callq 0x3170
movl 0x8fb3(%rip), %eax      # 0xe2c4
cmpl 0x90b9(%rip), %eax      # 0xe3d0
jne 0x534f
movq 0x8cb8(%rip), %rdi      # 0xdfd8
leaq 0x51b1(%rip), %rsi      # 0xa4d8
callq 0x32a0
jmp 0x532e
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x54f1
callq 0x4fe0
movl %eax, -0x6c(%rbp)
jmp 0x5359
movl -0x6c(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jne 0x538a
movq 0x8c6c(%rip), %rdi      # 0xdfd8
leaq 0x519b(%rip), %rsi      # 0xa50e
callq 0x32a0
jmp 0x537a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
cmpl $0x0, -0x2c(%rbp)
je 0x53b5
movq 0x8c41(%rip), %rdi      # 0xdfd8
leaq 0x5191(%rip), %rsi      # 0xa52f
callq 0x32a0
jmp 0x53a5
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
jmp 0x53b7
movw $0x0, -0x42(%rbp)
leaq -0x42(%rbp), %rdi
callq 0x5040
movl %eax, -0x70(%rbp)
jmp 0x53cb
movl -0x70(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x53fc
movq 0x8bfa(%rip), %rdi      # 0xdfd8
leaq 0x5168(%rip), %rsi      # 0xa54d
callq 0x32a0
jmp 0x53ec
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
movb $0x0, -0x43(%rbp)
leaq -0x43(%rbp), %rdi
callq 0x50d0
movl %eax, -0x74(%rbp)
jmp 0x540e
movl -0x74(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x543f
movq 0x8bb7(%rip), %rdi      # 0xdfd8
leaq 0x5125(%rip), %rsi      # 0xa54d
callq 0x32a0
jmp 0x542f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
callq 0x5130
movl %eax, -0x78(%rbp)
jmp 0x5449
movl -0x78(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x5477
movq 0x8b7c(%rip), %rdi      # 0xdfd8
leaq 0x50ea(%rip), %rsi      # 0xa54d
callq 0x32a0
jmp 0x546a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
movzwl -0x42(%rbp), %esi
leaq -0x68(%rbp), %rdi
callq 0x5180
jmp 0x5486
movq 0x8b4b(%rip), %rdi      # 0xdfd8
leaq -0x68(%rbp), %rsi
callq 0x3270
jmp 0x5498
leaq -0x68(%rbp), %rdi
callq 0x3568
movq 0x8b30(%rip), %rdi      # 0xdfd8
leaq 0x50c0(%rip), %rsi      # 0xa56f
callq 0x32a0
jmp 0x54b6
movb $0x1, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x54da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3568
jmp 0x54f1
leaq -0x28(%rbp), %rdi
callq 0x3568
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x3568
movq -0x38(%rbp), %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)