// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/atc.c
// Function: atc_read_thread
static void * atc_read_thread(void *param) {
    PROFILE_T *profile = (PROFILE_T *)param;
    const char *cdc_wdm = (const char *)profile->qmichannel;
    int wait_for_request_quit = 0;
    int atc_fd;

    atc_fd = cm_open_dev(cdc_wdm);
    if (atc_fd <= 0) {
        dbg_time("fail to open (%s), errno: %d (%s)", cdc_wdm, errno, strerror(errno));
        goto __quit;
    }

    dbg_time("atc_fd = %d", atc_fd);

    if (at_open(atc_fd, onUnsolicited))
        goto __quit;

    at_set_on_timeout(onTimeout);
    at_set_on_reader_closed(onClose);
    qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_CONNECTED);

    while (atc_fd > 0) {
        struct pollfd pollfds[] = {{atc_fd, POLLIN, 0}, {qmidevice_control_fd[1], POLLIN, 0}};
        int ne, ret, nevents = 2;

        ret = poll(pollfds, nevents, wait_for_request_quit ? 1000 : -1);

        if (ret == 0 && wait_for_request_quit) {
            break;
        }

        if (ret < 0) {
            dbg_time("%s poll=%d, errno: %d (%s)", __func__, ret, errno, strerror(errno));
            break;
        }

        for (ne = 0; ne < nevents; ne++) {
            int fd = pollfds[ne].fd;
            short revents = pollfds[ne].revents;

            if (revents & (POLLERR | POLLHUP | POLLNVAL)) {
                dbg_time("%s poll err/hup/inval", __func__);
                dbg_time("epoll fd = %d, events = 0x%04x", fd, revents);
                if (revents & (POLLERR | POLLHUP | POLLNVAL))
                goto __quit;
            }

            if ((revents & POLLIN) == 0)
                continue;

            if (atc_fd == fd) {
                usleep(10*1000); //let atchannel.c read at response.
            }
            else if (fd == qmidevice_control_fd[1]) {
                int triger_event;
                if (read(fd, &triger_event, sizeof(triger_event)) == sizeof(triger_event)) {
                    //dbg_time("triger_event = 0x%x", triger_event);
                    switch (triger_event) {
                        case RIL_REQUEST_QUIT:
                            goto __quit;
                        break;
                        case SIG_EVENT_STOP:
                            wait_for_request_quit = 1;
                        break;
                        default:
                        break;
                    }
                }
            }
        }
    }

__quit:
    at_close();
    qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_DISCONNECTED);
    dbg_time("%s exit", __func__);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x8a, %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x13770
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0x2359a
jmp 0x234d4
movq 0x13b05(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x68(%rbp)
callq 0x13930
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl -0x4c(%rbp), %r8d
movq %rax, %r9
leaq 0xc0f9(%rip), %rsi      # 0x2f61c
movb $0x0, %al
callq 0x52c0
leaq 0x14937(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x23593
leaq 0x1492a(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x88(%rbp)
callq 0x13930
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
movl -0x6c(%rbp), %r8d
movq %rax, %r9
leaq 0xc090(%rip), %rsi      # 0x2f61c
movb $0x0, %al
callq 0x52c0
jmp 0x23595
jmp 0x23997
jmp 0x2359c
movq 0x13a3d(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x90(%rbp)
callq 0x13930
movq -0x90(%rbp), %rdi
movq %rax, %rdx
movl -0x20(%rbp), %ecx
leaq 0xcd01(%rip), %rsi      # 0x302c7
movb $0x0, %al
callq 0x52c0
leaq 0x14894(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x2360b
leaq 0x14887(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x98(%rbp)
callq 0x13930
movq -0x98(%rbp), %rdi
movq %rax, %rdx
movl -0x20(%rbp), %ecx
leaq 0xccc3(%rip), %rsi      # 0x302c7
movb $0x0, %al
callq 0x52c0
jmp 0x2360d
movl -0x20(%rbp), %edi
leaq 0x2fe9(%rip), %rsi      # 0x26600
callq 0x26ac0
cmpl $0x0, %eax
je 0x23626
jmp 0x23997
leaq 0x3063(%rip), %rdi      # 0x26690
callq 0x27450
leaq 0x30d7(%rip), %rdi      # 0x26710
callq 0x27470
movl $0x1002, %edi           # imm = 0x1002
callq 0x8240
cmpl $0x0, -0x20(%rbp)
jle 0x23995
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
movw $0x1, -0x2c(%rbp)
movw $0x0, -0x2a(%rbp)
leaq 0x13f29(%rip), %rax     # 0x37594
movl 0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movw $0x1, -0x24(%rbp)
movw $0x0, -0x22(%rbp)
movl $0x2, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
movl -0x1c(%rbp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x3e8, %eax            # imm = 0x3E8
cmpl $0x0, %ecx
cmovnel %eax, %edx
callq 0x53d0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x236b8
cmpl $0x0, -0x1c(%rbp)
je 0x236b8
jmp 0x23995
cmpl $0x0, -0x38(%rbp)
jge 0x237c0
jmp 0x236c4
movq 0x13915(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x13930
movq %rax, -0xa8(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0xa0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
movl -0xa0(%rbp), %r8d
movl -0x9c(%rbp), %r9d
leaq 0x7a8d(%rip), %rsi      # 0x2b1b3
leaq 0xcbac(%rip), %rcx      # 0x302d9
movq %rax, (%rsp)
movb $0x0, %al
callq 0x52c0
leaq 0x14729(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x237b9
leaq 0x1471c(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
callq 0x13930
movq %rax, -0xc0(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0xb8(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movl -0xb8(%rbp), %r8d
movl -0xb4(%rbp), %r9d
leaq 0x7a0c(%rip), %rsi      # 0x2b1b3
leaq 0xcb2b(%rip), %rcx      # 0x302d9
movq %rax, (%rsp)
movb $0x0, %al
callq 0x52c0
jmp 0x237bb
jmp 0x23995
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x23990
movslq -0x34(%rbp), %rax
movl -0x30(%rbp,%rax,8), %eax
movl %eax, -0x40(%rbp)
movslq -0x34(%rbp), %rax
movw -0x2a(%rbp,%rax,8), %ax
movw %ax, -0x42(%rbp)
movswl -0x42(%rbp), %eax
andl $0x38, %eax
cmpl $0x0, %eax
je 0x23906
jmp 0x237fd
movq 0x137dc(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
callq 0x13930
movq -0xd0(%rbp), %rdi
movq %rax, %rdx
leaq 0x79b0(%rip), %rsi      # 0x2b1d4
leaq 0xcaae(%rip), %rcx      # 0x302d9
movb $0x0, %al
callq 0x52c0
leaq 0x1462f(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x23874
leaq 0x14622(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
callq 0x13930
movq -0xd8(%rbp), %rdi
movq %rax, %rdx
leaq 0x796e(%rip), %rsi      # 0x2b1d4
leaq 0xca6c(%rip), %rcx      # 0x302d9
movb $0x0, %al
callq 0x52c0
jmp 0x23876
jmp 0x23878
movq 0x13761(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
callq 0x13930
movq -0xe0(%rbp), %rdi
movq %rax, %rdx
movl -0x40(%rbp), %ecx
movswl -0x42(%rbp), %r8d
leaq 0x7b67(%rip), %rsi      # 0x2b40e
movb $0x0, %al
callq 0x52c0
leaq 0x145b3(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x238f1
leaq 0x145a6(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
callq 0x13930
movq -0xe8(%rbp), %rdi
movq %rax, %rdx
movl -0x40(%rbp), %ecx
movswl -0x42(%rbp), %r8d
leaq 0x7b24(%rip), %rsi      # 0x2b40e
movb $0x0, %al
callq 0x52c0
jmp 0x238f3
movswl -0x42(%rbp), %eax
andl $0x38, %eax
cmpl $0x0, %eax
je 0x23904
jmp 0x23997
jmp 0x23906
movswl -0x42(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x23914
jmp 0x23982
movl -0x20(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x23928
movl $0x2710, %edi           # imm = 0x2710
callq 0x5590
jmp 0x23980
movl -0x40(%rbp), %eax
leaq 0x13c62(%rip), %rcx     # 0x37594
cmpl 0x4(%rcx), %eax
jne 0x2397e
movl -0x40(%rbp), %edi
leaq -0x48(%rbp), %rsi
movl $0x4, %edx
callq 0x5250
cmpq $0x4, %rax
jne 0x2397c
movl -0x48(%rbp), %eax
movl %eax, -0xec(%rbp)
subl $0x2, %eax
je 0x2396f
jmp 0x2395e
movl -0xec(%rbp), %eax
subl $0x1000, %eax           # imm = 0x1000
jne 0x23978
jmp 0x2396d
jmp 0x23997
movl $0x1, -0x1c(%rbp)
jmp 0x2397a
jmp 0x2397a
jmp 0x2397c
jmp 0x2397e
jmp 0x23980
jmp 0x23982
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x237c7
jmp 0x23648
jmp 0x23997
movb $0x0, %al
callq 0x26c60
movl $0x1003, %edi           # imm = 0x1003
callq 0x8240
movq 0x13631(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
callq 0x13930
movq -0xf8(%rbp), %rdi
movq %rax, %rdx
leaq 0x7895(%rip), %rsi      # 0x2b264
leaq 0xc903(%rip), %rcx      # 0x302d9
movb $0x0, %al
callq 0x52c0
leaq 0x14484(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x23a1f
leaq 0x14477(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x100(%rbp)
callq 0x13930
movq -0x100(%rbp), %rdi
movq %rax, %rdx
leaq 0x7853(%rip), %rsi      # 0x2b264
leaq 0xc8c1(%rip), %rcx      # 0x302d9
movb $0x0, %al
callq 0x52c0
jmp 0x23a21
xorl %eax, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)