// File: /workspace/github_c_makefile_star2_O3/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 0x1c143
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 0x768b(%rip), %rdi      # 0x2365b
movl $0x1, %esi
callq 0x5450
testl %eax, %eax
je 0x1c0af
negb %bpl
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %r9d
movl $0xffffff00, %r8d       # imm = 0xFFFFFF00
shll %cl, %r8d
movl $0xff000000, %eax       # imm = 0xFF000000
shll %cl, %eax
movl %r9d, %ecx
shrl $0x18, %ecx
shrl $0x10, %r9d
shrl $0x10, %r8d
shrl $0x18, %eax
movl $0xff, %edx
andl %edx, %r8d
andl %edx, %r9d
movl %ecx, (%rsp)
leaq 0xe2fa(%rip), %r13      # 0x2a320
leaq 0x7281(%rip), %rdx      # 0x232ae
movl $0x10, %esi
movq %r13, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x51c0
leaq 0x7682(%rip), %rdx      # 0x236c7
leaq 0x10(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rcx
movq %r15, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1bf3d
leaq 0x7670(%rip), %rdx      # 0x236e1
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x5170
testl %eax, %eax
je 0x1c083
leaq 0x7664(%rip), %rdx      # 0x236fa
leaq 0x10(%rsp), %rdi
movl $0x80, %esi
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
jmp 0x1c128
leaq 0x75ae(%rip), %rdx      # 0x23664
leaq 0x10(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movl $0x4, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1bf3d
movq %rbx, (%rsp)
leaq 0x759b(%rip), %rdx      # 0x23680
movl $0x80, %esi
movq %r12, %rdi
movl $0x4, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1bf3d
leaq 0x7592(%rip), %rdx      # 0x236a0
movl $0x80, %esi
movq %r12, %rdi
movl $0x4, %ecx
movq %r14, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x51c0
leaq 0x10(%rsp), %rdi
callq 0x1bf3d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq