// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/udhcpc.c
// Function: update_ipv4_address
void update_ipv4_address(const char *ifname, const char *ip, const char *gw, unsigned prefix)
{
    char shell_cmd[128];

    if (!ifname)
        return;

    if (!access("/sbin/ip", X_OK)) {
        snprintf(shell_cmd, sizeof(shell_cmd), "ip -%d address flush dev %s", 4, ifname);
        ql_system(shell_cmd);

        snprintf(shell_cmd, sizeof(shell_cmd), "ip -%d address add %s/%u dev %s", 4, ip, prefix, ifname);
        ql_system(shell_cmd);

        //ping6 www.qq.com
        snprintf(shell_cmd, sizeof(shell_cmd), "ip -%d route add default via %s dev %s", 4, gw, ifname);
        ql_system(shell_cmd);
    } else {
        unsigned n =  (0xFFFFFFFF >> (32 - prefix)) << (32 - prefix);
        n = (n>>24) | (n>>8&0xff00) | (n<<8&0xff0000) | (n<<24);

        snprintf(shell_cmd, sizeof(shell_cmd), "ifconfig %s %s netmask %s", ifname, ip, ipv4Str(n));
        ql_system(shell_cmd);

        //Resetting default routes
        snprintf(shell_cmd, sizeof(shell_cmd), "route del default dev %s", ifname);
        while(!system(shell_cmd));

        snprintf(shell_cmd, sizeof(shell_cmd), "route add default gw %s dev %s", gw, ifname);
        ql_system(shell_cmd);
    }
}

// Assembly:
testq %rdi, %rdi
je 0x1ada9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x6a1e(%rip), %rdi      # 0x2167a
pushq $0x1
popq %rsi
callq 0x5460
testl %eax, %eax
je 0x1ad17
negb %bpl
pushq $-0x1
popq %rax
movl %ebp, %ecx
shll %cl, %eax
movl %eax, %edx
shrl $0x18, %edx
shrl $0x8, %eax
andl $0xff00, %eax           # imm = 0xFF00
movl $0xffffff00, %esi       # imm = 0xFFFFFF00
shll %cl, %esi
movl $0xff000000, %edi       # imm = 0xFF000000
shll %cl, %edi
andl $0xff0000, %esi         # imm = 0xFF0000
orl %edx, %edi
orl %esi, %edi
orl %eax, %edi
callq 0x1adaa
leaq 0x6a3d(%rip), %rdx      # 0x216e6
leaq 0xe670(%rip), %r9       # 0x29320
leaq 0x10(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1abc9
leaq 0x6a27(%rip), %rdx      # 0x21700
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x5170
testl %eax, %eax
je 0x1aceb
leaq 0x6a1b(%rip), %rdx      # 0x21719
leaq 0x10(%rsp), %rdi
movl $0x80, %esi
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
jmp 0x1ad8e
leaq 0x6965(%rip), %rdx      # 0x21683
leaq 0x10(%rsp), %r12
pushq $0x4
popq %r13
movl $0x80, %esi
movq %r12, %rdi
movl %r13d, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1abc9
movq %rbx, (%rsp)
leaq 0x6950(%rip), %rdx      # 0x2169f
movl $0x80, %esi
movq %r12, %rdi
movl %r13d, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1abc9
leaq 0x6949(%rip), %rdx      # 0x216bf
movl $0x80, %esi
movq %r12, %rdi
movl %r13d, %ecx
movq %r14, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x51c0
leaq 0x10(%rsp), %rdi
callq 0x1abc9
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq