// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/atchannel.c
// Function: readline
static const char *readline()
{
    ssize_t count;

    char *p_read = NULL;
    char *p_eol = NULL;
    char *ret;

    /* this is a little odd. I use *s_ATBufferCur == 0 to
     * mean "buffer consumed completely". If it points to a character, than
     * the buffer continues until a \0
     */
    if (*s_ATBufferCur == '\0') {
        /* empty buffer */
        s_ATBufferCur = s_ATBuffer;
        *s_ATBufferCur = '\0';
        p_read = s_ATBuffer;
    } else {   /* *s_ATBufferCur != '\0' */
        /* there's data in the buffer from the last read */

        // skip over leading newlines
        while (*s_ATBufferCur == '\r' || *s_ATBufferCur == '\n')
            s_ATBufferCur++;

        p_eol = findNextEOL(s_ATBufferCur);

        if (p_eol == NULL) {
            /* a partial line. move it up and prepare to read more */
            size_t len;

            len = strlen(s_ATBufferCur);

            memmove(s_ATBuffer, s_ATBufferCur, len + 1);
            p_read = s_ATBuffer + len;
            s_ATBufferCur = s_ATBuffer;
        }
        /* Otherwise, (p_eol !- NULL) there is a complete line  */
        /* that will be returned the while () loop below        */
    }

    while (p_eol == NULL) {
        if (0 == MAX_AT_RESPONSE - (p_read - s_ATBuffer)) {
            LOGE("ERROR: Input line exceeded buffer\n");
            /* ditch buffer and start over again */
            s_ATBufferCur = s_ATBuffer;
            *s_ATBufferCur = '\0';
            p_read = s_ATBuffer;
        }

        do {
            while (s_fd > 0) {
                struct pollfd pollfds[1] = {{s_fd, POLLIN, 0}};
                int ret;
            
                do {
                    ret = poll(pollfds, 1, -1);
                } while ((ret < 0) && (errno == EINTR));

                if (pollfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
                    break;
                } else if   (pollfds[0].revents & (POLLIN))  {
                    break;
                }
            };

            count = (s_fd == -1) ? 0 : read(s_fd, p_read,
                            MAX_AT_RESPONSE - (p_read - s_ATBuffer));
        } while (count < 0 && errno == EINTR);

        if (count > 0) {
            AT_DUMP( "<< ", p_read, count );
            s_readCount += count;

            p_read[count] = '\0';

            // skip over leading newlines
            while (*s_ATBufferCur == '\r' || *s_ATBufferCur == '\n')
                s_ATBufferCur++;

            p_eol = findNextEOL(s_ATBufferCur);
            p_read += count;
        } else if (count <= 0) {
            /* read error encountered or EOF reached */
            if(count == 0) {
                LOGD("atchannel: EOF reached");
            } else {
                LOGD("atchannel: read error %s", strerror(errno));
            }
            return NULL;
        }
    }

    /* a full line in the buffer. Place a \0 over the \r and return */

    ret = s_ATBufferCur;
    *p_eol = '\0';
    s_ATBufferCur = p_eol + 1; /* this will always be <= p_read,    */
                              /* and there will be a \0 at *p_read */

    LOGD("AT< %s", ret);
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq 0xfc96(%rip), %rax      # 0x37448
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x277e2
movq 0xfc8f(%rip), %rax      # 0x37450
movq %rax, 0xfc80(%rip)      # 0x37448
movq 0xfc79(%rip), %rax      # 0x37448
movb $0x0, (%rax)
movq 0xfc77(%rip), %rax      # 0x37450
movq %rax, -0x18(%rbp)
jmp 0x27889
jmp 0x277e4
movq 0xfc5d(%rip), %rax      # 0x37448
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xd, %ecx
movb %al, -0x3d(%rbp)
je 0x2780b
movq 0xfc49(%rip), %rax      # 0x37448
movsbl (%rax), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x27814
jmp 0x27828
movq 0xfc2d(%rip), %rax      # 0x37448
addq $0x1, %rax
movq %rax, 0xfc22(%rip)      # 0x37448
jmp 0x277e4
movq 0xfc19(%rip), %rdi      # 0x37448
callq 0x27c80
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x27887
movq 0xfc02(%rip), %rdi      # 0x37448
callq 0x5160
movq %rax, -0x30(%rbp)
movq 0xfbfa(%rip), %rdi      # 0x37450
movq 0xfbeb(%rip), %rsi      # 0x37448
movq -0x30(%rbp), %rdx
addq $0x1, %rdx
callq 0x53f0
movq 0xfbdf(%rip), %rax      # 0x37450
addq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0xfbd0(%rip), %rax      # 0x37450
movq %rax, 0xfbc1(%rip)      # 0x37448
jmp 0x27889
jmp 0x2788b
cmpq $0x0, -0x20(%rbp)
jne 0x27bd7
movq -0x18(%rbp), %rax
movq 0xfbaf(%rip), %rcx      # 0x37450
subq %rcx, %rax
movl $0x1000, %ecx           # imm = 0x1000
subq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x2793b
jmp 0x278b9
movq 0xf720(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
callq 0x13930
movq -0x48(%rbp), %rdi
movq %rax, %rdx
leaq 0x8fa8(%rip), %rsi      # 0x30882
movb $0x0, %al
callq 0x52c0
leaq 0x10580(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x27916
leaq 0x10573(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x13930
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0x8f73(%rip), %rsi      # 0x30882
movb $0x0, %al
callq 0x52c0
jmp 0x27918
movq 0xfb31(%rip), %rax      # 0x37450
movq %rax, 0xfb22(%rip)      # 0x37448
movq 0xfb1b(%rip), %rax      # 0x37448
movb $0x0, (%rax)
movq 0xfb19(%rip), %rax      # 0x37450
movq %rax, -0x18(%rbp)
jmp 0x2793d
jmp 0x2793f
cmpl $0x0, 0xfafa(%rip)      # 0x37440
jle 0x279b3
movl 0xfaf2(%rip), %eax      # 0x37440
movl %eax, -0x38(%rbp)
movw $0x1, -0x34(%rbp)
movw $0x0, -0x32(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x1, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x53d0
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x51(%rbp)
jge 0x2798c
callq 0x5070
cmpl $0x4, (%rax)
sete %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x2795d
movswl -0x32(%rbp), %eax
andl $0x38, %eax
cmpl $0x0, %eax
je 0x279a1
jmp 0x279b3
movswl -0x32(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x279af
jmp 0x279b3
jmp 0x279b1
jmp 0x2793f
cmpl $-0x1, 0xfa86(%rip)     # 0x37440
jne 0x279c4
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x279ed
movl 0xfa76(%rip), %edi      # 0x37440
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0xfa77(%rip), %rcx      # 0x37450
subq %rcx, %rax
movl $0x1000, %edx           # imm = 0x1000
subq %rax, %rdx
callq 0x5250
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x61(%rbp)
jge 0x27a0f
callq 0x5070
cmpl $0x4, (%rax)
sete %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x2793d
cmpq $0x0, -0x10(%rbp)
jle 0x27aae
jmp 0x27a27
jmp 0x27a29
movq -0x10(%rbp), %rcx
movslq 0x1173c(%rip), %rax     # 0x39170
addq %rcx, %rax
movl %eax, 0x11733(%rip)     # 0x39170
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq 0xf9f8(%rip), %rax      # 0x37448
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xd, %ecx
movb %al, -0x62(%rbp)
je 0x27a70
movq 0xf9e4(%rip), %rax      # 0x37448
movsbl (%rax), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
testb $0x1, %al
jne 0x27a79
jmp 0x27a8d
movq 0xf9c8(%rip), %rax      # 0x37448
addq $0x1, %rax
movq %rax, 0xf9bd(%rip)      # 0x37448
jmp 0x27a49
movq 0xf9b4(%rip), %rdi      # 0x37448
callq 0x27c80
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x27bd2
cmpq $0x0, -0x10(%rbp)
jg 0x27bd0
cmpq $0x0, -0x10(%rbp)
jne 0x27b26
jmp 0x27ac2
movq 0xf517(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0x70(%rbp)
callq 0x13930
movq -0x70(%rbp), %rdi
movq %rax, %rdx
leaq 0x8dc8(%rip), %rsi      # 0x308ab
movb $0x0, %al
callq 0x52c0
leaq 0x10377(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x27b1f
leaq 0x1036a(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x78(%rbp)
callq 0x13930
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x8d93(%rip), %rsi      # 0x308ab
movb $0x0, %al
callq 0x52c0
jmp 0x27b21
jmp 0x27bc3
jmp 0x27b28
movq 0xf4b1(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
callq 0x13930
movq %rax, -0x80(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq %rax, %rcx
leaq 0x8d65(%rip), %rsi      # 0x308c8
movb $0x0, %al
callq 0x52c0
leaq 0x102f7(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x27bbf
leaq 0x102ea(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x98(%rbp)
callq 0x13930
movq %rax, -0x90(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rdx
movq %rax, %rcx
leaq 0x8d10(%rip), %rsi      # 0x308c8
movb $0x0, %al
callq 0x52c0
jmp 0x27bc1
jmp 0x27bc3
movq $0x0, -0x8(%rbp)
jmp 0x27c73
jmp 0x27bd2
jmp 0x2788b
movq 0xf86a(%rip), %rax      # 0x37448
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, 0xf850(%rip)      # 0x37448
movq 0xf3e1(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
callq 0x13930
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
movq -0x28(%rbp), %rcx
leaq 0x8cc4(%rip), %rsi      # 0x308e7
movb $0x0, %al
callq 0x52c0
leaq 0x10237(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x27c69
leaq 0x1022a(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
callq 0x13930
movq -0xa8(%rbp), %rdi
movq %rax, %rdx
movq -0x28(%rbp), %rcx
leaq 0x8c85(%rip), %rsi      # 0x308e7
movb $0x0, %al
callq 0x52c0
jmp 0x27c6b
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq