// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movb %dl, %al
movb %sil, %cl
movq %rdi, -0x8(%rbp)
movb %cl, -0x9(%rbp)
movb %al, -0xa(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xb(%rax), %ecx
movzbl -0x9(%rbp), %eax
xorl %ecx, %eax
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xb(%rax), %ecx
movzbl -0xa(%rbp), %eax
xorl %ecx, %eax
movb %al, -0xa(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0xa(%rax)
je 0x5035
movb -0xa(%rbp), %al
movb %al, -0xb(%rbp)
movb -0x9(%rbp), %al
movb %al, -0xa(%rbp)
movb -0xb(%rbp), %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movl 0x80(%rax), %edi
movl $0x5415, %esi           # imm = 0x5415
leaq -0x10(%rbp), %rdx
movb $0x0, %al
callq 0x40f0
cmpl $0x0, %eax
jne 0x506c
movl -0x10(%rbp), %edx
movl $0x3, %edi
leaq 0x603f(%rip), %rsi      # 0xb0a2
movb $0x0, %al
callq 0x44e0
jmp 0x507f
movl $0x1, %edi
leaq 0x6045(%rip), %rsi      # 0xb0bd
movb $0x0, %al
callq 0x44e0
cmpb $0x0, -0x9(%rbp)
je 0x5090
movl -0x10(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x10(%rbp)
jmp 0x5099
movl -0x10(%rbp), %eax
andl $-0x3, %eax
movl %eax, -0x10(%rbp)
cmpb $0x0, -0xa(%rbp)
je 0x50aa
movl -0x10(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x10(%rbp)
jmp 0x50b3
movl -0x10(%rbp), %eax
andl $-0x5, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x80(%rax), %edi
movl $0x5418, %esi           # imm = 0x5418
leaq -0x10(%rbp), %rdx
movb $0x0, %al
callq 0x40f0
cmpl $0x0, %eax
jne 0x50ea
movl -0x10(%rbp), %edx
movl $0x3, %edi
leaq 0x5fee(%rip), %rsi      # 0xb0cf
movb $0x0, %al
callq 0x44e0
jmp 0x50fd
movl $0x1, %edi
leaq 0x5ff4(%rip), %rsi      # 0xb0ea
movb $0x0, %al
callq 0x44e0
movq -0x8(%rbp), %rax
movl 0x80(%rax), %edi
movl $0x5415, %esi           # imm = 0x5415
leaq -0x10(%rbp), %rdx
movb $0x0, %al
callq 0x40f0
cmpl $0x0, %eax
jne 0x5134
movl -0x10(%rbp), %edx
movl $0x3, %edi
leaq 0x5f77(%rip), %rsi      # 0xb0a2
movb $0x0, %al
callq 0x44e0
jmp 0x5147
movl $0x1, %edi
leaq 0x5f7d(%rip), %rsi      # 0xb0bd
movb $0x0, %al
callq 0x44e0
movzbl -0x9(%rbp), %edx
movzbl -0xa(%rbp), %ecx
movl $0x3, %edi
leaq 0x5fa1(%rip), %rsi      # 0xb0fc
movb $0x0, %al
callq 0x44e0
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)