// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x5200
leaq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x50a0
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x55a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x2270d
jmp 0x22660
movq 0x14979(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x13930
movq %rax, -0x58(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rdx
movl -0x4c(%rbp), %ecx
movq %rax, %r8
leaq 0xd7bc(%rip), %rsi      # 0x2fe5e
movb $0x0, %al
callq 0x52c0
leaq 0x157b8(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x226ff
leaq 0x157ab(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x78(%rbp)
callq 0x13930
movq %rax, -0x70(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x64(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rdx
movl -0x64(%rbp), %ecx
movq %rax, %r8
leaq 0xd766(%rip), %rsi      # 0x2fe5e
movb $0x0, %al
callq 0x52c0
jmp 0x22701
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x228bb
movl $0xa, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0x1c(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %edi
movl $0x8946, %esi           # imm = 0x8946
leaq -0x48(%rbp), %rdx
movb $0x0, %al
callq 0x5210
cmpl $0x0, %eax
jge 0x22832
jmp 0x22741
movq 0x14898(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x98(%rbp)
callq 0x13930
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rdx
movq -0x88(%rbp), %rcx
movl -0x7c(%rbp), %r8d
movq %rax, %r9
leaq 0xd73d(%rip), %rsi      # 0x2fedf
movb $0x0, %al
callq 0x52c0
leaq 0x156b8(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x22824
leaq 0x156ab(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x13930
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movq -0xa8(%rbp), %rcx
movl -0x9c(%rbp), %r8d
movq %rax, %r9
leaq 0xd6c2(%rip), %rsi      # 0x2fedf
movb $0x0, %al
callq 0x52c0
jmp 0x22826
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x228bb
cmpl $0x0, -0x18(%rbp)
jne 0x228ad
jmp 0x2283a
movq 0x1479f(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x13930
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
movl -0x18(%rbp), %ecx
leaq 0xd6a2(%rip), %rsi      # 0x2ff06
movb $0x0, %al
callq 0x52c0
leaq 0x155f6(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x228a9
leaq 0x155e9(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
callq 0x13930
movq -0xc8(%rbp), %rdi
movq %rax, %rdx
movl -0x18(%rbp), %ecx
leaq 0xd664(%rip), %rsi      # 0x2ff06
movb $0x0, %al
callq 0x52c0
jmp 0x228ab
jmp 0x228ad
movl -0x14(%rbp), %edi
callq 0x5230
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)