// File: /workspace/github_c_makefile_star2_O0/jfriesse[P]omping/tlv.c
// Function: tlv_pref_eq
int
tlv_pref_eq(const struct sockaddr_storage *sas, uint16_t iana_af, uint8_t prefix, const char *addr)
{
	char sas_addr[32];
	size_t sas_addr_len;
	uint16_t sas_iana_af;
	unsigned char cb1, cb2;
	uint8_t plen_max, plen_min;

	memset(sas_addr, 0, sizeof(sas_addr));

	switch (sas->ss_family) {
	case AF_INET:
		sas_iana_af = AF_IANA_IP;

		plen_min = 4;
		plen_max = 32;

		sas_addr_len = sizeof(struct in_addr);
		memcpy(sas_addr, &((struct sockaddr_in *)sas)->sin_addr, sas_addr_len);
		break;
	case AF_INET6:
		sas_iana_af = AF_IANA_IP6;

		plen_min = 8;
		plen_max = 128;

		sas_addr_len = sizeof(struct in6_addr);
		memcpy(sas_addr, &((struct sockaddr_in6 *)sas)->sin6_addr, sas_addr_len);
		break;
	default:
		DEBUG_PRINTF("Unknown ss family %d", sas->ss_family);
		errx(1, "Unknown ss family %d", sas->ss_family);
	}

	if (iana_af != sas_iana_af) {
		return (0);
	}

	if (prefix == 0) {
		/*
		 * Wildcard
		 */
		return (1);
	}

	if (prefix < plen_min || prefix > plen_max) {
		return (0);
	}

	/*
	 * Full bytes comparation
	 */
	if (memcmp(sas_addr, addr, prefix / 8) != 0) {
		return (0);
	}


	/*
	 * Rest bit comparation
	 */
	if (prefix % 8 != 0 && prefix / 8 < sizeof(sas_addr_len)) {
		cb1 = (unsigned char)(sas_addr[prefix / 8] & (0xff << (8 - (prefix % 8))));
		cb2 = (unsigned char)(addr[prefix / 8] & (0xff << (8 - (prefix % 8))));
		if (cb1 != cb2) {
			return (0);
		}
	}

	return (1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %dl, %al
movw %si, %dx
movq %rdi, -0x10(%rbp)
movw %dx, -0x12(%rbp)
movb %al, -0x13(%rbp)
movq %rcx, -0x20(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0x54(%rbp)
subl $0x2, %eax
je 0xc542
jmp 0xc538
movl -0x54(%rbp), %eax
subl $0xa, %eax
je 0xc56f
jmp 0xc59c
movw $0x1, -0x4a(%rbp)
movb $0x4, -0x4e(%rbp)
movb $0x20, -0x4d(%rbp)
movq $0x4, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x4, %rsi
movq -0x48(%rbp), %rdx
callq 0x2200
jmp 0xc5dd
movw $0x2, -0x4a(%rbp)
movb $0x8, -0x4e(%rbp)
movb $-0x80, -0x4d(%rbp)
movq $0x10, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movq -0x48(%rbp), %rdx
callq 0x2200
jmp 0xc5dd
movq -0x10(%rbp), %rax
movzwl (%rax), %r8d
leaq 0x36cd(%rip), %rdi      # 0xfc78
movl $0x20d, %esi            # imm = 0x20D
movl $0x2, %edx
leaq 0x37fd(%rip), %rcx      # 0xfdb9
movb $0x0, %al
callq 0x5dc0
movq -0x10(%rbp), %rax
movzwl (%rax), %edx
movl $0x1, %edi
leaq 0x37e3(%rip), %rsi      # 0xfdb9
movb $0x0, %al
callq 0x20d0
movzwl -0x12(%rbp), %eax
movzwl -0x4a(%rbp), %ecx
cmpl %ecx, %eax
je 0xc5f5
movl $0x0, -0x4(%rbp)
jmp 0xc728
movzbl -0x13(%rbp), %eax
cmpl $0x0, %eax
jne 0xc60a
movl $0x1, -0x4(%rbp)
jmp 0xc728
movzbl -0x13(%rbp), %eax
movzbl -0x4e(%rbp), %ecx
cmpl %ecx, %eax
jl 0xc622
movzbl -0x13(%rbp), %eax
movzbl -0x4d(%rbp), %ecx
cmpl %ecx, %eax
jle 0xc62e
movl $0x0, -0x4(%rbp)
jmp 0xc728
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movslq %eax, %rdx
callq 0x2180
cmpl $0x0, %eax
je 0xc65b
movl $0x0, -0x4(%rbp)
jmp 0xc728
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xc721
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
cmpq $0x8, %rax
jae 0xc721
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
movsbl -0x40(%rbp,%rax), %eax
movl %eax, -0x64(%rbp)
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl -0x64(%rbp), %eax
movl $0x8, %ecx
subl %edx, %ecx
movl $0xff, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movb %al, -0x4b(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
movzbl -0x13(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl -0x58(%rbp), %eax
movl $0x8, %ecx
subl %edx, %ecx
movl $0xff, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movb %al, -0x4c(%rbp)
movzbl -0x4b(%rbp), %eax
movzbl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
je 0xc71f
movl $0x0, -0x4(%rbp)
jmp 0xc728
jmp 0xc721
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)