// File: /workspace/github_c_makefile_star2_O3/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 0x4b5c
leaq 0x4587(%rip), %rsi      # 0x90d5
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
jmp 0x4b73
movl 0xc(%rsp), %edx
leaq 0x4553(%rip), %rsi      # 0x90ba
movl $0x3, %edi
xorl %eax, %eax
callq 0x43fd
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 0x4bc2
leaq 0x454e(%rip), %rsi      # 0x9102
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
jmp 0x4bd9
movl 0xc(%rsp), %edx
leaq 0x451a(%rip), %rsi      # 0x90e7
movl $0x3, %edi
xorl %eax, %eax
callq 0x43fd
movl 0x80(%rbx), %edi
leaq 0xc(%rsp), %rdx
movl $0x5415, %esi           # imm = 0x5415
xorl %eax, %eax
callq 0x40f0
testl %eax, %eax
je 0x4c09
leaq 0x44da(%rip), %rsi      # 0x90d5
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
jmp 0x4c20
movl 0xc(%rsp), %edx
leaq 0x44a6(%rip), %rsi      # 0x90ba
movl $0x3, %edi
xorl %eax, %eax
callq 0x43fd
movzbl %bpl, %edx
movzbl %r14b, %ecx
leaq 0x44e5(%rip), %rsi      # 0x9114
movl $0x3, %edi
xorl %eax, %eax
callq 0x43fd
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq