// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/udhcpc.c
// Function: ql_set_driver_link_state
void ql_set_driver_link_state(PROFILE_T *profile, int link_state) {
    char link_file[128];
    int fd;
    int new_state = 0;

    snprintf(link_file, sizeof(link_file), "/sys/class/net/%s/link_state", profile->usbnet_adapter);
    fd = open(link_file, O_RDWR | O_NONBLOCK | O_NOCTTY);
    if (fd == -1) {
        if (errno != ENOENT)
            dbg_time("Fail to access %s, errno: %d (%s)", link_file, errno, strerror(errno));
        return;
    }

    if (profile->qmap_mode <= 1)
        new_state = !!link_state;
    else {
        //0x80 means link off this pdp
        new_state = (link_state ? 0x00 : 0x80) + (profile->muxid & 0x7F);
    }

    snprintf(link_file, sizeof(link_file), "%d\n", new_state);
    if (write(fd, link_file, sizeof(link_file)) == -1) {};

    if (link_state == 0 && profile->qmapnet_adapter[0]
        && strcmp(profile->qmapnet_adapter, profile->usbnet_adapter)) {
        size_t rc;

        lseek(fd, 0, SEEK_SET);
        rc = read(fd, link_file, sizeof(link_file));
        if (rc > 1 && (!strncasecmp(link_file, "0\n", 2) || !strncasecmp(link_file, "0x0\n", 4))) {
            snprintf(link_file, sizeof(link_file), "ifconfig %s down", profile->usbnet_adapter);
            ql_system(link_file);
        }
    }

    close(fd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
movq -0x8(%rbp), %rcx
addq $0xaa, %rcx
movl $0x80, %esi
leaq 0x7dd4(%rip), %rdx      # 0x30a3e
movb $0x0, %al
callq 0x51c0
leaq -0x90(%rbp), %rdi
movl $0x902, %esi            # imm = 0x902
movb $0x0, %al
callq 0x5450
movl %eax, -0x94(%rbp)
cmpl $-0x1, -0x94(%rbp)
jne 0x28d9f
callq 0x5070
cmpl $0x2, (%rax)
je 0x28d9a
jmp 0x28ca7
movq 0xe332(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x13930
movq %rax, -0xb8(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0xb0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
movq -0xb0(%rbp), %rcx
movl -0xa4(%rbp), %r8d
movq %rax, %r9
leaq 0x7d4a(%rip), %rsi      # 0x30a5b
movb $0x0, %al
callq 0x52c0
leaq 0xf149(%rip), %rax      # 0x37e68
cmpq $0x0, (%rax)
je 0x28d96
leaq 0xf13c(%rip), %rax      # 0x37e68
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
callq 0x13930
movq %rax, -0xd8(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movl -0xc4(%rbp), %r8d
movq %rax, %r9
leaq 0x7ccc(%rip), %rsi      # 0x30a5b
movb $0x0, %al
callq 0x52c0
jmp 0x28d98
jmp 0x28d9a
jmp 0x28f1b
movq -0x8(%rbp), %rax
cmpl $0x1, 0x10a(%rax)
jg 0x28dc4
cmpl $0x0, -0xc(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x98(%rbp)
jmp 0x28de9
movl -0xc(%rbp), %edx
movl $0x80, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movq -0x8(%rbp), %rcx
movl 0x11e(%rcx), %ecx
andl $0x7f, %ecx
addl %ecx, %eax
movl %eax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
movl -0x98(%rbp), %ecx
movl $0x80, %esi
leaq 0x6804(%rip), %rdx      # 0x2f606
movb $0x0, %al
callq 0x51c0
movl -0x94(%rbp), %edi
leaq -0x90(%rbp), %rsi
movl $0x80, %edx
callq 0x5100
cmpq $-0x1, %rax
jne 0x28e28
jmp 0x28e28
cmpl $0x0, -0xc(%rbp)
jne 0x28f10
movq -0x8(%rbp), %rax
movsbl 0xca(%rax), %eax
cmpl $0x0, %eax
je 0x28f10
movq -0x8(%rbp), %rdi
addq $0xca, %rdi
movq -0x8(%rbp), %rsi
addq $0xaa, %rsi
callq 0x52a0
cmpl $0x0, %eax
je 0x28f10
movl -0x94(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x51e0
movl -0x94(%rbp), %edi
leaq -0x90(%rbp), %rsi
movl $0x80, %edx
callq 0x5250
movq %rax, -0xa0(%rbp)
cmpq $0x1, -0xa0(%rbp)
jbe 0x28f0e
leaq -0x90(%rbp), %rdi
leaq 0x7bd4(%rip), %rsi      # 0x30a85
movl $0x2, %edx
callq 0x5380
cmpl $0x0, %eax
je 0x28edd
leaq -0x90(%rbp), %rdi
leaq 0x7bb5(%rip), %rsi      # 0x30a83
movl $0x4, %edx
callq 0x5380
cmpl $0x0, %eax
jne 0x28f0e
leaq -0x90(%rbp), %rdi
movq -0x8(%rbp), %rcx
addq $0xaa, %rcx
movl $0x80, %esi
leaq 0x7b8d(%rip), %rdx      # 0x30a88
movb $0x0, %al
callq 0x51c0
leaq -0x90(%rbp), %rdi
callq 0x28f30
jmp 0x28f10
movl -0x94(%rbp), %edi
callq 0x5230
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)