// File: /workspace/github_c_makefile_star2_O1/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 0x1c4ab
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 0x72cd(%rip), %rdi      # 0x23605
movl $0x1, %esi
callq 0x5450
testl %eax, %eax
je 0x1c417
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 0xdf92(%rip), %r13      # 0x2a320
leaq 0x6ef9(%rip), %rdx      # 0x2328e
movl $0x10, %esi
movq %r13, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x51c0
leaq 0x72c4(%rip), %rdx      # 0x23671
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 0x1c2a5
leaq 0x72b2(%rip), %rdx      # 0x2368b
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x5170
testl %eax, %eax
je 0x1c3eb
leaq 0x72a6(%rip), %rdx      # 0x236a4
leaq 0x10(%rsp), %rdi
movl $0x80, %esi
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
jmp 0x1c490
leaq 0x71f0(%rip), %rdx      # 0x2360e
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 0x1c2a5
movq %rbx, (%rsp)
leaq 0x71dd(%rip), %rdx      # 0x2362a
movl $0x80, %esi
movq %r12, %rdi
movl $0x4, %ecx
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x51c0
movq %r12, %rdi
callq 0x1c2a5
leaq 0x71d4(%rip), %rdx      # 0x2364a
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 0x1c2a5
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq