// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/util.c
// Function: update_resolv_conf
void update_resolv_conf(int iptype, const char *ifname, const char *dns1, const char *dns2) {
    const char *dns_file = "/etc/resolv.conf";
    FILE *dns_fp;
    char dns_line[256];
    #define MAX_DNS 16
    char *dns_info[MAX_DNS];
    char dns_tag[64];
    int dns_match = 0;
    int i;

    snprintf(dns_tag, sizeof(dns_tag), "# IPV%d %s", iptype, ifname);

    for (i = 0; i < MAX_DNS; i++)
        dns_info[i] = NULL;
    
    dns_fp = fopen(dns_file, "r");
    if (dns_fp) {
        i = 0;    
        dns_line[sizeof(dns_line)-1] = '\0';
        
        while((fgets(dns_line, sizeof(dns_line)-1, dns_fp)) != NULL) {
            if ((strlen(dns_line) > 1) && (dns_line[strlen(dns_line) - 1] == '\n'))
                dns_line[strlen(dns_line) - 1] = '\0';
            //dbg_time("%s", dns_line);
            if (strstr(dns_line, dns_tag)) {
                dns_match++;
                continue;
            }
            dns_info[i++] = strdup(dns_line);
            if (i == MAX_DNS)
                break;
        }

        fclose(dns_fp);
    }
    else if (errno != ENOENT) {
        dbg_time("fopen %s fail, errno:%d (%s)", dns_file, errno, strerror(errno));
        return;
    }
    
    if (dns1 == NULL && dns_match == 0)
        return;

    dns_fp = fopen(dns_file, "w");
    if (dns_fp) {
        if (dns1)
            fprintf(dns_fp, "nameserver %s %s\n", dns1, dns_tag);
        if (dns2)
            fprintf(dns_fp, "nameserver %s %s\n", dns2, dns_tag);
        
        for (i = 0; i < MAX_DNS && dns_info[i]; i++)
            fprintf(dns_fp, "%s\n", dns_info[i]);
        fclose(dns_fp);
    }
    else {
        dbg_time("fopen %s fail, errno:%d (%s)", dns_file, errno, strerror(errno));
    }

    for (i = 0; i < MAX_DNS && dns_info[i]; i++)
        free(dns_info[i]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0x19e92(%rip), %rax     # 0x2df63
movq %rax, -0x28(%rbp)
movl $0x0, -0x1f4(%rbp)
leaq -0x1f0(%rbp), %rdi
movl -0x4(%rbp), %ecx
movq -0x10(%rbp), %r8
movl $0x40, %esi
leaq 0x19e7b(%rip), %rdx     # 0x2df74
movb $0x0, %al
callq 0x51c0
movl $0x0, -0x1f8(%rbp)
cmpl $0x10, -0x1f8(%rbp)
jge 0x14137
movslq -0x1f8(%rbp), %rax
movq $0x0, -0x1b0(%rbp,%rax,8)
movl -0x1f8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1f8(%rbp)
jmp 0x1410a
movq -0x28(%rbp), %rdi
leaq 0x1b2a5(%rip), %rsi     # 0x2f3e7
callq 0x5480
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1423f
movl $0x0, -0x1f8(%rbp)
movb $0x0, -0x31(%rbp)
leaq -0x130(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl $0xff, %esi
callq 0x5270
cmpq $0x0, %rax
je 0x14231
leaq -0x130(%rbp), %rdi
callq 0x5160
cmpq $0x1, %rax
jbe 0x141ca
leaq -0x130(%rbp), %rdi
callq 0x5160
subq $0x1, %rax
movsbl -0x130(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x141ca
leaq -0x130(%rbp), %rdi
callq 0x5160
subq $0x1, %rax
movb $0x0, -0x130(%rbp,%rax)
leaq -0x130(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x5560
cmpq $0x0, %rax
je 0x141f7
movl -0x1f4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1f4(%rbp)
jmp 0x14164
leaq -0x130(%rbp), %rdi
callq 0x5530
movq %rax, %rcx
movl -0x1f8(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1f8(%rbp)
cltq
movq %rcx, -0x1b0(%rbp,%rax,8)
cmpl $0x10, -0x1f8(%rbp)
jne 0x1422c
jmp 0x14231
jmp 0x14164
movq -0x30(%rbp), %rdi
callq 0x5130
jmp 0x1433b
callq 0x5070
cmpl $0x2, (%rax)
je 0x14339
jmp 0x1424f
movq 0x22d8a(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x218(%rbp)
callq 0x13930
movq %rax, -0x210(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x208(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x1fc(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x218(%rbp), %rdi
movq -0x210(%rbp), %rdx
movq -0x208(%rbp), %rcx
movl -0x1fc(%rbp), %r8d
movq %rax, %r9
leaq 0x19cc9(%rip), %rsi     # 0x2df7f
movb $0x0, %al
callq 0x52c0
cmpq $0x0, 0x23ba3(%rip)     # 0x37e68
je 0x14332
movq 0x23b9a(%rip), %rax     # 0x37e68
movq %rax, -0x238(%rbp)
callq 0x13930
movq %rax, -0x230(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x228(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x21c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x238(%rbp), %rdi
movq -0x230(%rbp), %rdx
movq -0x228(%rbp), %rcx
movl -0x21c(%rbp), %r8d
movq %rax, %r9
leaq 0x19c54(%rip), %rsi     # 0x2df7f
movb $0x0, %al
callq 0x52c0
jmp 0x14334
jmp 0x14585
jmp 0x1433b
cmpq $0x0, -0x18(%rbp)
jne 0x14350
cmpl $0x0, -0x1f4(%rbp)
jne 0x14350
jmp 0x14585
movq -0x28(%rbp), %rdi
leaq 0x1a54e(%rip), %rsi     # 0x2e8a9
callq 0x5480
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x14437
cmpq $0x0, -0x18(%rbp)
je 0x14393
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x1f0(%rbp), %rcx
leaq 0x19c16(%rip), %rsi     # 0x2dfa2
movb $0x0, %al
callq 0x52c0
cmpq $0x0, -0x20(%rbp)
je 0x143b7
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq -0x1f0(%rbp), %rcx
leaq 0x19bf2(%rip), %rsi     # 0x2dfa2
movb $0x0, %al
callq 0x52c0
movl $0x0, -0x1f8(%rbp)
xorl %eax, %eax
cmpl $0x10, -0x1f8(%rbp)
movb %al, -0x239(%rbp)
jge 0x143eb
movslq -0x1f8(%rbp), %rax
cmpq $0x0, -0x1b0(%rbp,%rax,8)
setne %al
movb %al, -0x239(%rbp)
movb -0x239(%rbp), %al
testb $0x1, %al
jne 0x143f7
jmp 0x14429
movq -0x30(%rbp), %rdi
movslq -0x1f8(%rbp), %rax
movq -0x1b0(%rbp,%rax,8), %rdx
leaq 0x17c84(%rip), %rsi     # 0x2c095
movb $0x0, %al
callq 0x52c0
movl -0x1f8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1f8(%rbp)
jmp 0x143c1
movq -0x30(%rbp), %rdi
callq 0x5130
jmp 0x14520
jmp 0x14439
movq 0x22ba0(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x258(%rbp)
callq 0x13930
movq %rax, -0x250(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x248(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x240(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x258(%rbp), %rdi
movq -0x250(%rbp), %rdx
movq -0x248(%rbp), %rcx
movl -0x240(%rbp), %r8d
movq %rax, %r9
leaq 0x19adf(%rip), %rsi     # 0x2df7f
movb $0x0, %al
callq 0x52c0
cmpq $0x0, 0x239b9(%rip)     # 0x37e68
je 0x1451c
movq 0x239b0(%rip), %rax     # 0x37e68
movq %rax, -0x278(%rbp)
callq 0x13930
movq %rax, -0x270(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x268(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x25c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x278(%rbp), %rdi
movq -0x270(%rbp), %rdx
movq -0x268(%rbp), %rcx
movl -0x25c(%rbp), %r8d
movq %rax, %r9
leaq 0x19a6a(%rip), %rsi     # 0x2df7f
movb $0x0, %al
callq 0x52c0
jmp 0x1451e
jmp 0x14520
movl $0x0, -0x1f8(%rbp)
xorl %eax, %eax
cmpl $0x10, -0x1f8(%rbp)
movb %al, -0x279(%rbp)
jge 0x14554
movslq -0x1f8(%rbp), %rax
cmpq $0x0, -0x1b0(%rbp,%rax,8)
setne %al
movb %al, -0x279(%rbp)
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x14560
jmp 0x14585
movslq -0x1f8(%rbp), %rax
movq -0x1b0(%rbp,%rax,8), %rdi
callq 0x5040
movl -0x1f8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1f8(%rbp)
jmp 0x1452a
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
nop