// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/chnroute.c
// Function: parse_chnroute_file
static int parse_chnroute_file(chnroute_list_t* list, const char* filename)
{
	char buf[512];
	char* line;
	FILE* fp;
	int r, rownum = 0;
	chnroute_item_t* item;

	fp = fopen(filename, "rb");
	if (fp == NULL) {
		loge("Can't open chnroute: %s\n", filename);
		return -1;
	}

	if (fseek(fp, 0, SEEK_SET) != 0) {
		loge("fseek\n");
		fclose(fp);
		return -1;
	}

	while ((line = fgets(buf, sizeof(buf), fp)) != NULL) {
		char* sp_pos;

		rownum++;

		if ((*line) == '#') continue;

		sp_pos = strchr(line, '\r');
		if (sp_pos)* sp_pos = 0;

		sp_pos = strchr(line, '\n');
		if (sp_pos)* sp_pos = 0;

		if (!(*line)) continue;

		item = (chnroute_item_t*)malloc(sizeof(chnroute_item_t));
		if (!item) {
			loge("calloc\n");
			fclose(fp);
			return -1;
		}

		memset(item, 0, sizeof(chnroute_item_t));

		if (is_ipv6(line)) {
			r = parse_netmask6(&item->net6, line);
			item->is_ipv6 = 1;
		}
		else {
			r = parse_netmask(&item->net, line);
		}

		if (r != 0) {
			loge("invalid addr %s in %s:%d\n", line, filename, rownum);
			free(item);
			fclose(fp);
			return -1;
		}
		else {
			dllist_add(&list->items, &item->entry);
			if (item->is_ipv6)
				list->net6_num++;
			else
				list->net_num++;
		}
	}

	fclose(fp);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x238(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x1a169(%rip), %rsi     # 0x35db1
callq 0x3440
movq %rax, -0x230(%rbp)
cmpq $0x0, -0x230(%rbp)
jne 0x1bca4
jmp 0x1bc60
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1bc96
movq -0x18(%rbp), %r9
movl $0x3, %edi
leaq 0x1b1de(%rip), %rsi     # 0x36e5a
leaq 0x1b1e6(%rip), %rdx     # 0x36e69
movl $0x106, %ecx            # imm = 0x106
leaq 0x1b1ee(%rip), %r8      # 0x36e7d
movb $0x0, %al
callq 0x243b0
jmp 0x1bc98
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1bf97
movq -0x230(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x3410
cmpl $0x0, %eax
je 0x1bd09
jmp 0x1bcbd
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1bcef
movl $0x3, %edi
leaq 0x1b185(%rip), %rsi     # 0x36e5a
leaq 0x1b18d(%rip), %rdx     # 0x36e69
movl $0x10b, %ecx            # imm = 0x10B
leaq 0x1b103(%rip), %r8      # 0x36deb
movb $0x0, %al
callq 0x243b0
jmp 0x1bcf1
movq -0x230(%rbp), %rdi
callq 0x33a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1bf97
jmp 0x1bd0b
leaq -0x220(%rbp), %rdi
movq -0x230(%rbp), %rdx
movl $0x200, %esi            # imm = 0x200
callq 0x3590
movq %rax, -0x228(%rbp)
cmpq $0x0, %rax
je 0x1bf84
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
movq -0x228(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x1bd54
jmp 0x1bd0b
movq -0x228(%rbp), %rdi
movl $0xd, %esi
callq 0x3160
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x248(%rbp)
je 0x1bd80
movq -0x248(%rbp), %rax
movb $0x0, (%rax)
movq -0x228(%rbp), %rdi
movl $0xa, %esi
callq 0x3160
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x248(%rbp)
je 0x1bdac
movq -0x248(%rbp), %rax
movb $0x0, (%rax)
movq -0x228(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x1bdbd
jmp 0x1bd0b
movl $0x38, %edi
callq 0x34d0
movq %rax, -0x240(%rbp)
cmpq $0x0, -0x240(%rbp)
jne 0x1be26
jmp 0x1bdda
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1be0c
movl $0x3, %edi
leaq 0x1b068(%rip), %rsi     # 0x36e5a
leaq 0x1b070(%rip), %rdx     # 0x36e69
movl $0x121, %ecx            # imm = 0x121
leaq 0x1b091(%rip), %r8      # 0x36e96
movb $0x0, %al
callq 0x243b0
jmp 0x1be0e
movq -0x230(%rbp), %rdi
callq 0x33a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1bf97
movq -0x240(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x3200
movq -0x228(%rbp), %rdi
callq 0x1c2f0
cmpl $0x0, %eax
je 0x1be77
movq -0x240(%rbp), %rdi
addq $0x14, %rdi
movq -0x228(%rbp), %rsi
callq 0x1c320
movl %eax, -0x234(%rbp)
movq -0x240(%rbp), %rax
movl $0x1, 0x10(%rax)
jmp 0x1be94
movq -0x240(%rbp), %rdi
addq $0x14, %rdi
movq -0x228(%rbp), %rsi
callq 0x1c4f0
movl %eax, -0x234(%rbp)
cmpl $0x0, -0x234(%rbp)
je 0x1bf10
jmp 0x1be9f
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1beea
movq -0x228(%rbp), %r9
movq -0x18(%rbp), %r10
movl -0x238(%rbp), %eax
movl $0x3, %edi
leaq 0x1af92(%rip), %rsi     # 0x36e5a
leaq 0x1af9a(%rip), %rdx     # 0x36e69
movl $0x131, %ecx            # imm = 0x131
leaq 0x1afc3(%rip), %r8      # 0x36e9e
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1beec
movq -0x240(%rbp), %rdi
callq 0x3460
movq -0x230(%rbp), %rdi
callq 0x33a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1bf97
jmp 0x1bf12
movq -0x10(%rbp), %rcx
movq -0x240(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x240(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x240(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x240(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x240(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1bf70
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x1bf7d
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x1bf7f
jmp 0x1bd0b
movq -0x230(%rbp), %rdi
callq 0x33a0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopw %cs:(%rax,%rax)