// File: /workspace/github_c_makefile_star2_O0/bokunimowakaru[P]petit15term/lpc21isp/lpc21isp.c
// Function: ReceiveComPortBlock
static void ReceiveComPortBlock(ISP_ENVIRONMENT *IspEnvironment,
                                          void *answer, unsigned long max_size,
                                          unsigned long *real_size)
{
    char tmp_string[32];

#if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN

    if (IspEnvironment->HalfDuplex == 0)
        ReadFile(IspEnvironment->hCom, answer, max_size, real_size, NULL);
    else
    {
        *real_size = strlen (pRxTmpBuf);
        if (*real_size)
        {
            if (max_size >= *real_size)
            {
                strncpy((char*) answer, pRxTmpBuf, *real_size);
                RxTmpBuf[0] = 0;
                pRxTmpBuf = RxTmpBuf;
            }
            else
            {
                strncpy((char*) answer, pRxTmpBuf, max_size);
                *real_size = max_size;
                pRxTmpBuf += max_size;
            }
        }
        else
            ReadFile(IspEnvironment->hCom, answer, max_size, real_size, NULL);
    }

#endif // defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN

#if defined COMPILE_FOR_LPC21

    *real_size = read(IspEnvironment->fdCom, answer, max_size);

#endif // defined COMPILE_FOR_LPC21

#if defined COMPILE_FOR_LINUX
    {
        fd_set
            readSet;
        struct timeval
            timeVal;

        FD_ZERO(&readSet);                             // clear the set
        FD_SET(IspEnvironment->fdCom,&readSet);        // add this descriptor to the set
        timeVal.tv_sec=0;                              // set up the timeout waiting for one to come ready (500ms)
        timeVal.tv_usec=500*1000;
        if(select(FD_SETSIZE,&readSet,NULL,NULL,&timeVal)==1)    // wait up to 500 ms or until our data is ready
        {
            *real_size=read(IspEnvironment->fdCom, answer, max_size);
        }
        else
        {
            // timed out, show no characters received and timer expired
            *real_size=0;
            IspEnvironment->serial_timeout_count=0;
        }
    }
#endif // defined COMPILE_FOR_LINUX

    sprintf(tmp_string, "Read(Length=%ld): ", (*real_size));
    DumpString(5, answer, (*real_size), tmp_string);

    if (*real_size == 0)
    {
        SerialTimeoutTick(IspEnvironment);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl $0x0, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
cmpq $0x10, %rax
jae 0x4cd5
movq -0xe0(%rbp), %rax
movl -0xd4(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x4ca3
jmp 0x4cd7
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xc0(%rbp,%rax,8), %rcx
movq %rcx, -0xc0(%rbp,%rax,8)
movq $0x0, -0xd0(%rbp)
movq $0x7a120, -0xc8(%rbp) # imm = 0x7A120
movl $0x400, %edi            # imm = 0x400
leaq -0xc0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xd0(%rbp), %r8
movq %rcx, %rdx
callq 0x4170
cmpl $0x1, %eax
jne 0x4d79
movq -0x8(%rbp), %rax
movl 0x80(%rax), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4110
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x4d92
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xfc(%rax)
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
leaq 0x62eb(%rip), %rsi      # 0xb08f
movb $0x0, %al
callq 0x4240
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
leaq -0x40(%rbp), %rcx
movl $0x5, %edi
callq 0x4630
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x4dd7
movq -0x8(%rbp), %rdi
callq 0x5fb0
addq $0xe0, %rsp
popq %rbp
retq