// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/udhcpc.c
// Function: ql_raw_ip_mode_check
static int ql_raw_ip_mode_check(const char *ifname, uint32_t ip) {
    int fd;
    char raw_ip[128];
    char shell_cmd[128];
    char mode[2] = "X";
    int mode_change = 0;

    if (ql_netcard_ipv4_address_check(ifname, qmi2addr(ip)))
        return 0;
    
    snprintf(raw_ip, sizeof(raw_ip), "/sys/class/net/%s/qmi/raw_ip", ifname);
    if (access(raw_ip, F_OK))
        return 0;

    fd = open(raw_ip, O_RDWR | O_NONBLOCK | O_NOCTTY);
    if (fd < 0) {
        dbg_time("%s %d fail to open(%s), errno:%d (%s)", __FILE__, __LINE__, raw_ip, errno, strerror(errno));
        return 0;
    }

    if (read(fd, mode, 2) == -1) {};
    if (mode[0] == '0' || mode[0] == 'N') {
        dbg_time("File:%s Line:%d udhcpc fail to get ip address, try next:", __func__, __LINE__);
        snprintf(shell_cmd, sizeof(shell_cmd), "ifconfig %s down", ifname);
        ql_system(shell_cmd);
        dbg_time("echo Y > /sys/class/net/%s/qmi/raw_ip", ifname);
        mode[0] = 'Y';
        if (write(fd, mode, 2) == -1) {};
        mode_change = 1;
        snprintf(shell_cmd, sizeof(shell_cmd), "ifconfig %s up", ifname);
        ql_system(shell_cmd);
    }

    close(fd);
    return mode_change;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movw 0x61f2(%rip), %ax       # 0x3054b
movw %ax, -0x122(%rbp)
movl $0x0, -0x128(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
movl -0x14(%rbp), %edi
callq 0x2a300
movq -0x130(%rbp), %rdi
movl %eax, %esi
callq 0x2a2c0
cmpl $0x0, %eax
je 0x2a39c
movl $0x0, -0x4(%rbp)
jmp 0x2a6e6
leaq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x80, %esi
leaq 0x69a5(%rip), %rdx      # 0x30d58
movb $0x0, %al
callq 0x51c0
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x2a3d9
movl $0x0, -0x4(%rbp)
jmp 0x2a6e6
leaq -0xa0(%rbp), %rdi
movl $0x902, %esi            # imm = 0x902
movb $0x0, %al
callq 0x5450
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x2a522
jmp 0x2a3fb
movq 0xcbde(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0x150(%rbp)
callq 0x13930
movq %rax, -0x148(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x140(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x134(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x150(%rbp), %rdi
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %r9
movl -0x134(%rbp), %r10d
leaq 0x6913(%rip), %rsi      # 0x30d75
leaq 0x6938(%rip), %rcx      # 0x30da1
movl $0x83, %r8d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x52c0
leaq 0xd9e2(%rip), %rax      # 0x37e68
cmpq $0x0, (%rax)
je 0x2a514
leaq 0xd9d1(%rip), %rax      # 0x37e68
movq (%rax), %rax
movq %rax, -0x170(%rbp)
callq 0x13930
movq %rax, -0x168(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x160(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x154(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x170(%rbp), %rdi
movq -0x168(%rbp), %rdx
movq -0x160(%rbp), %r9
movl -0x154(%rbp), %r10d
leaq 0x687e(%rip), %rsi      # 0x30d75
leaq 0x68a3(%rip), %rcx      # 0x30da1
movl $0x83, %r8d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x52c0
jmp 0x2a516
movl $0x0, -0x4(%rbp)
jmp 0x2a6e6
movl -0x18(%rbp), %edi
leaq -0x122(%rbp), %rsi
movl $0x2, %edx
callq 0x5250
cmpq $-0x1, %rax
jne 0x2a53e
jmp 0x2a53e
movsbl -0x122(%rbp), %eax
cmpl $0x30, %eax
je 0x2a55a
movsbl -0x122(%rbp), %eax
cmpl $0x4e, %eax
jne 0x2a6d5
jmp 0x2a55c
movq 0xca7d(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0x178(%rbp)
callq 0x13930
movq -0x178(%rbp), %rdi
movq %rax, %rdx
leaq 0x6827(%rip), %rsi      # 0x30daa
leaq 0x685f(%rip), %rcx      # 0x30de9
movl $0x89, %r8d
movb $0x0, %al
callq 0x52c0
leaq 0xd8ca(%rip), %rax      # 0x37e68
cmpq $0x0, (%rax)
je 0x2a5df
leaq 0xd8bd(%rip), %rax      # 0x37e68
movq (%rax), %rax
movq %rax, -0x180(%rbp)
callq 0x13930
movq -0x180(%rbp), %rdi
movq %rax, %rdx
leaq 0x67df(%rip), %rsi      # 0x30daa
leaq 0x6817(%rip), %rcx      # 0x30de9
movl $0x89, %r8d
movb $0x0, %al
callq 0x52c0
jmp 0x2a5e1
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x80, %esi
leaq 0x6490(%rip), %rdx      # 0x30a88
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
callq 0x28f30
movq 0xc9ce(%rip), %rax      # 0x36fe0
movq (%rax), %rax
movq %rax, -0x188(%rbp)
callq 0x13930
movq -0x188(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
leaq 0x67c8(%rip), %rsi      # 0x30dfe
movb $0x0, %al
callq 0x52c0
leaq 0xd824(%rip), %rax      # 0x37e68
cmpq $0x0, (%rax)
je 0x2a67c
leaq 0xd817(%rip), %rax      # 0x37e68
movq (%rax), %rax
movq %rax, -0x190(%rbp)
callq 0x13930
movq -0x190(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
leaq 0x6789(%rip), %rsi      # 0x30dfe
movb $0x0, %al
callq 0x52c0
jmp 0x2a67e
movb $0x59, -0x122(%rbp)
movl -0x18(%rbp), %edi
leaq -0x122(%rbp), %rsi
movl $0x2, %edx
callq 0x5100
cmpq $-0x1, %rax
jne 0x2a6a1
jmp 0x2a6a1
movl $0x1, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x80, %esi
leaq 0x5dca(%rip), %rdx      # 0x3048c
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
callq 0x28f30
movl -0x18(%rbp), %edi
callq 0x5230
movl -0x128(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw %cs:(%rax,%rax)