// File: /workspace/github_c_makefile_star2_O2/bokunimowakaru[P]petit15term/lpc21isp/lpc21isp.c
// Function: ControlModemLines
static void ControlModemLines(ISP_ENVIRONMENT *IspEnvironment, unsigned char DTR, unsigned char RTS)
{
    //handle wether to invert the control lines:
    DTR ^= IspEnvironment->ControlLinesInverted;
    RTS ^= IspEnvironment->ControlLinesInverted;

    //handle wether to swap the control lines
    if (IspEnvironment->ControlLinesSwapped)
    {
        unsigned char tempRTS;
        tempRTS = RTS;
        RTS = DTR;
        DTR = tempRTS;
    }

#if defined COMPILE_FOR_LINUX
    int status;

    if (ioctl(IspEnvironment->fdCom, TIOCMGET, &status) == 0)
    {
        DebugPrintf(3, "ioctl get ok, status = %X\n",status);
    }
    else
    {
        DebugPrintf(1, "ioctl get failed\n");
    }

    if (DTR) status |=  TIOCM_DTR;
    else    status &= ~TIOCM_DTR;

    if (RTS) status |=  TIOCM_RTS;
    else    status &= ~TIOCM_RTS;

    if (ioctl(IspEnvironment->fdCom, TIOCMSET, &status) == 0)
    {
        DebugPrintf(3, "ioctl set ok, status = %X\n",status);
    }
    else
    {
        DebugPrintf(1, "ioctl set failed\n");
    }

    if (ioctl(IspEnvironment->fdCom, TIOCMGET, &status) == 0)
    {
        DebugPrintf(3, "ioctl get ok, status = %X\n",status);
    }
    else
    {
        DebugPrintf(1, "ioctl get failed\n");
    }

#endif // defined COMPILE_FOR_LINUX
#if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN

    if (DTR) EscapeCommFunction(IspEnvironment->hCom, SETDTR);
    else    EscapeCommFunction(IspEnvironment->hCom, CLRDTR);

    if (RTS) EscapeCommFunction(IspEnvironment->hCom, SETRTS);
    else    EscapeCommFunction(IspEnvironment->hCom, CLRRTS);

#endif // defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN

#if defined COMPILE_FOR_LPC21
    LPC_RESET(DTR);
    LPC_BSL(RTS);
#endif

    DebugPrintf(3, "DTR (%d), RTS (%d)\n", DTR, RTS);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movb 0xb(%rdi), %al
xorb %al, %sil
xorb %al, %dl
cmpb $0x0, 0xa(%rdi)
movzbl %dl, %ebp
movzbl %sil, %eax
movl %eax, %r14d
cmovel %ebp, %r14d
cmovel %eax, %ebp
movl 0x80(%rdi), %edi
leaq 0xc(%rsp), %rdx
movl $0x5415, %esi           # imm = 0x5415
xorl %eax, %eax
callq 0x40f0
testl %eax, %eax
je 0x4b40
leaq 0x45a1(%rip), %rsi      # 0x90d5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x43f9
jmp 0x4b55
movl 0xc(%rsp), %edx
leaq 0x456f(%rip), %rsi      # 0x90ba
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x43f9
xorl %eax, %eax
testb %bpl, %bpl
setne %al
leaq 0xc(%rsp), %rdx
movl (%rdx), %ecx
andl $-0x7, %ecx
addl %eax, %eax
xorl %esi, %esi
testb %r14b, %r14b
setne %sil
leal (%rax,%rsi,4), %eax
orl %ecx, %eax
movl %eax, (%rdx)
movl 0x80(%rbx), %edi
movl $0x5418, %esi           # imm = 0x5418
xorl %eax, %eax
callq 0x40f0
testl %eax, %eax
je 0x4ba2
leaq 0x456c(%rip), %rsi      # 0x9102
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x43f9
jmp 0x4bb7
movl 0xc(%rsp), %edx
leaq 0x453a(%rip), %rsi      # 0x90e7
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x43f9
movl 0x80(%rbx), %edi
leaq 0xc(%rsp), %rdx
movl $0x5415, %esi           # imm = 0x5415
xorl %eax, %eax
callq 0x40f0
testl %eax, %eax
je 0x4be5
leaq 0x44fc(%rip), %rsi      # 0x90d5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x43f9
jmp 0x4bfa
movl 0xc(%rsp), %edx
leaq 0x44ca(%rip), %rsi      # 0x90ba
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x43f9
movzbl %bpl, %edx
movzbl %r14b, %ecx
leaq 0x450b(%rip), %rsi      # 0x9114
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x43f9
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq