// File: /workspace/github_c_makefile_star2_O3/Carton32[P]quectel-CM/device.c
// Function: ql_get_netcard_carrier_state
int ql_get_netcard_carrier_state(const char *devname)
{
    int fd = -1;
    struct ethtool_value edata;
    struct ifreq ifr;	/* ifreq suitable for ethtool ioctl */

    memset(&ifr, 0, sizeof(ifr));
    strcpy(ifr.ifr_name, devname);

    fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (fd < 0) {
        dbg_time("Cannot get control socket: errno(%d)(%s)", errno, strerror(errno));
        return -1;
    }

    edata.cmd = ETHTOOL_GLINK;
    edata.data = 0;
    ifr.ifr_data = (void *)&edata;

    if (ioctl(fd, SIOCETHTOOL, &ifr) < 0) {
        dbg_time("ioctl('%s') error: errno(%d)(%s)", devname, errno, strerror(errno));
        return -1;
    }

    if (!edata.data)
        dbg_time("netcard carrier = %d", edata.data);

    close(fd);

    return edata.data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movq $0x0, 0x20(%rdi)
movq %rbx, %rsi
callq 0x50a0
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x55a0
testl %eax, %eax
js 0x17cf5
movl %eax, %ebp
leaq 0x8(%rsp), %rax
movq $0xa, (%rax)
leaq 0x10(%rsp), %rdx
movq %rax, 0x10(%rdx)
movl $0x8946, %esi           # imm = 0x8946
movl %ebp, %edi
xorl %eax, %eax
callq 0x5210
testl %eax, %eax
js 0x17d78
cmpl $0x0, 0xc(%rsp)
jne 0x17ce5
movq 0x12327(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
movl 0xc(%rsp), %ecx
leaq 0xb02d(%rip), %rsi      # 0x22cd9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12fe8(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x17ce5
callq 0xea3b
movl 0xc(%rsp), %ecx
leaq 0xb001(%rip), %rsi      # 0x22cd9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movl %ebp, %edi
callq 0x5230
movl 0xc(%rsp), %ebp
jmp 0x17dfc
movq 0x122c4(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movq %rax, %r15
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xaf12(%rip), %rsi      # 0x22c31
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x52c0
leaq 0x12f70(%rip), %rax     # 0x2aca8
movq (%rax), %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x17dfc
callq 0xea3b
movq %rax, %r15
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5530
leaq 0xaed0(%rip), %rsi      # 0x22c31
movq %r14, %rdi
movq %r15, %rdx
movl %ebx, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x52c0
jmp 0x17dfc
movq 0x12241(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xea3b
movq %rax, %r12
callq 0x5070
movq %rax, %r14
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xaf10(%rip), %rsi      # 0x22cb2
movq %r15, %rdi
movq %r12, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x12ee9(%rip), %rax     # 0x2aca8
movq (%rax), %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x17dfc
callq 0xea3b
movq %rax, %r12
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
leaq 0xaecc(%rip), %rsi      # 0x22cb2
movq %r15, %rdi
movq %r12, %rdx
movq %rbx, %rcx
movl %r14d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movl %ebp, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq