// File: /workspace/github_c_makefile_star2_O3/jfriesse[P]omping/msg.c
// Function: msg_decode
void
msg_decode(const char *msg, size_t msg_len, struct msg_decoded *decoded)
{
	char debug_str[128];
	struct tlv_iterator tlv_iter;
	size_t pos;
	uint32_t u32, u32_2;
	uint16_t tlv_len;
	uint16_t u16;
	uint8_t u8;

	memset(decoded, 0, sizeof(struct msg_decoded));

	decoded->msg_type = (enum msg_type)msg[0];

	DEBUG2_PRINTF("Message type %c (0x%X)", decoded->msg_type, decoded->msg_type);

	tlv_iter_init(msg, msg_len, &tlv_iter);

	while (tlv_iter_next(&tlv_iter) == 0) {
		tlv_len = tlv_iter_get_len(&tlv_iter);

		if (logging_get_verbose() >= LOGGING_LEVEL_DEBUG2) {
			snprintf(debug_str, sizeof(debug_str), "%u:%s:%u:",
			    tlv_iter_get_type(&tlv_iter),
			    tlv_opt_type_to_str(tlv_iter_get_type(&tlv_iter)), tlv_len);
		}

		switch (tlv_iter_get_type(&tlv_iter)) {
		case TLV_OPT_TYPE_VERSION:
			if (tlv_len == 1) {
				memcpy(&u8, tlv_iter_get_data(&tlv_iter), sizeof(u8));

				decoded->version = u8;

				DEBUG2_PRINTF("%s%u", debug_str, u8);
			} else {
				DEBUG2_PRINTF("%slen != 1", debug_str);
			}
			break;
		case TLV_OPT_TYPE_CLIENT_ID:
			if (tlv_len > 0) {
				decoded->client_id_len = tlv_len;
				decoded->client_id = tlv_iter_get_data(&tlv_iter);

				DEBUG2_HEXDUMP(debug_str, decoded->client_id, tlv_len);
			} else {
				DEBUG2_PRINTF("%slen <= 0", debug_str);
			}
			break;
		case TLV_OPT_TYPE_SEQ_NUM:
			if (tlv_len == 4) {
				decoded->seq_num_isset = 1;
				memcpy(&u32, tlv_iter_get_data(&tlv_iter), sizeof(u32));
				u32 = ntohl(u32);
				decoded->seq_num = u32;

				DEBUG2_PRINTF("%s%u", debug_str, u32);
			} else {
				DEBUG2_PRINTF("%slen != 4", debug_str);
			}
			break;
		case TLV_OPT_TYPE_CLIENT_TSTAMP:
			if (tlv_len == 8) {
				memcpy(&u32, tlv_iter_get_data(&tlv_iter), sizeof(u32));
				u32 = ntohl(u32);
				decoded->client_tstamp.tv_sec = u32;

				memcpy(&u32_2, tlv_iter_get_data(&tlv_iter) + sizeof(u32),
				    sizeof(u32_2));
				u32_2 = ntohl(u32_2);
				decoded->client_tstamp.tv_usec = u32_2;

				decoded->client_tstamp_isset = 1;

				DEBUG2_PRINTF("%s(%u,%u)", debug_str, u32, u32_2);
			} else {
				DEBUG2_PRINTF("%slen != 8", debug_str);
			}
			break;
		case TLV_OPT_TYPE_MCAST_GRP:
			if (tlv_len > 2) {
				memcpy(&u16, tlv_iter_get_data(&tlv_iter), sizeof(u16));
				u16 = ntohs(u16);

				if ((u16 == AF_IANA_IP && tlv_len == 6) ||
				    (u16 == AF_IANA_IP6 && tlv_len == 18)) {
					decoded->mcast_grp_len = tlv_len;
					decoded->mcast_grp = tlv_iter_get_data(&tlv_iter);

					DEBUG2_PRINTF("%sAF %u", debug_str, u16);
				} else {
					DEBUG2_PRINTF("%sbad AF %u or len", debug_str, u16);
				}
			} else {
				DEBUG2_PRINTF("%slen <= 2", debug_str);
			}
			break;
		case TLV_OPT_TYPE_OPT_REQUEST:
			if (tlv_len > 1 && (tlv_len % 2  == 0)) {
				for (pos = 0; pos < (uint16_t)(tlv_len / 2); pos++) {
					memcpy(&u16, tlv_iter_get_data(&tlv_iter) + pos * 2,
					    sizeof(u16));

					u16 = ntohs(u16);

					switch (u16) {
					case TLV_OPT_TYPE_SERVER_INFO:
						decoded->request_opt_server_info = 1;

						DEBUG2_PRINTF("%s%zu opt %u", debug_str, pos, u16);
						break;
					case TLV_OPT_TYPE_SERVER_TSTAMP:
						decoded->request_opt_server_tstamp = 1;

						DEBUG2_PRINTF("%s%zu opt %u", debug_str, pos, u16);
						break;
					default:
						DEBUG2_PRINTF("%s%zu unknown opt %u", debug_str,
						    pos, u16);
						break;
					}
				}
			} else {
				DEBUG2_PRINTF("%slen <= 1 || (tlv_len %%2 != 0)", debug_str);
			}
			break;
		case TLV_OPT_TYPE_SERVER_INFO:
			if (tlv_len > 0) {
				decoded->server_info = tlv_iter_get_data(&tlv_iter);
				decoded->server_info_len = tlv_len;

				DEBUG2_HEXDUMP(debug_str, decoded->server_info, tlv_len);
			} else {
				DEBUG2_PRINTF("%slen <= 0", debug_str);
			}
			break;
		case TLV_OPT_TYPE_TTL:
			if (tlv_len == 1) {
				memcpy(&u8, tlv_iter_get_data(&tlv_iter), sizeof(u8));

				decoded->ttl = u8;

				DEBUG2_PRINTF("%s%u", debug_str, u8);
			} else {
				DEBUG2_PRINTF("%slen != 1", debug_str);
			}
			break;
		case TLV_OPT_TYPE_MCAST_PREFIX:
			if (tlv_len > 2) {
				memcpy(&u16, tlv_iter_get_data(&tlv_iter), sizeof(u16));
				u16 = ntohs(u16);

				if (u16 == AF_IANA_IP  || u16 == AF_IANA_IP6) {
					decoded->mcast_prefix_isset = 1;

					DEBUG2_PRINTF("%sAF %u", debug_str, u16);
				} else {
					DEBUG2_PRINTF("%sbad AF %u", debug_str, u16);
				}
			} else {
				DEBUG2_PRINTF("%slen <= 2", debug_str);
			}
			break;
		case TLV_OPT_TYPE_SES_ID:
			if (tlv_len > 0) {
				decoded->ses_id_len = tlv_len;
				decoded->ses_id = tlv_iter_get_data(&tlv_iter);

				DEBUG2_HEXDUMP(debug_str, decoded->ses_id, tlv_len);
			} else {
				DEBUG2_PRINTF("%slen <= 0", debug_str);
			}
			break;
		case TLV_OPT_TYPE_SERVER_TSTAMP:
			if (tlv_len == 8) {
				memcpy(&u32, tlv_iter_get_data(&tlv_iter), sizeof(u32));
				u32 = ntohl(u32);
				decoded->server_tstamp.tv_sec = u32;

				memcpy(&u32_2, tlv_iter_get_data(&tlv_iter) + sizeof(u32),
				    sizeof(u32_2));
				u32_2 = ntohl(u32_2);
				decoded->server_tstamp.tv_usec = u32_2;

				decoded->server_tstamp_isset = 1;

				DEBUG2_PRINTF("%s(%u,%u)", debug_str, u32, u32_2);
			} else {
				DEBUG2_PRINTF("%slen != 8", debug_str);
			}
			break;
		default:
			DEBUG2_PRINTF("%s", debug_str);
			break;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2150
movsbl (%r15), %r8d
movl %r8d, 0x20(%rbx)
leaq 0x6094(%rip), %rdi      # 0xad6c
leaq 0x6093(%rip), %rcx      # 0xad72
movl $0x65, %esi
movl $0x3, %edx
movl %r8d, %r9d
xorl %eax, %eax
callq 0x4ad6
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x8a23
movq %r12, %rdi
callq 0x8b06
testl %eax, %eax
jne 0x51fc
leaq 0x8(%rsp), %r14
leaq 0x20(%rsp), %r12
leaq 0x6045(%rip), %r13      # 0xad6c
movq %r14, %rdi
callq 0x89ff
movl %eax, %r15d
callq 0x4a03
cmpl $0x3, %eax
jl 0x4d74
movq %r14, %rdi
callq 0x8a10
movl %eax, %ebp
movq %r14, %rdi
callq 0x8a10
movl %eax, %edi
callq 0x8d24
movzwl %r15w, %r9d
movl $0x80, %esi
movq %r12, %rdi
leaq 0x6021(%rip), %rdx      # 0xad89
movl %ebp, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x2120
movq %r14, %rdi
callq 0x8a10
cmpl $0xc, %eax
ja 0x50d6
movl %eax, %eax
leaq 0x5faa(%rip), %rcx      # 0xad38
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpw $0x1, %r15w
jne 0x5132
movq %r14, %rdi
callq 0x89f0
movzbl (%rax), %r9d
movb %r9b, 0x91(%rbx)
movq %r13, %rdi
movl $0x79, %esi
jmp 0x5037
cmpw $0x8, %r15w
jne 0x50ef
movq %r14, %rdi
callq 0x89f0
movl (%rax), %r15d
bswapl %r15d
movq %r15, 0x10(%rbx)
movq %r14, %rdi
callq 0x89f0
movl 0x4(%rax), %eax
bswapl %eax
movq %rax, 0x18(%rbx)
movl $0x1, 0x68(%rbx)
movl %eax, (%rsp)
movq %r13, %rdi
movl $0x111, %esi            # imm = 0x111
jmp 0x4f68
cmpw $0x3, %r15w
jb 0x50f9
movq %r14, %rdi
callq 0x89f0
movzwl (%rax), %eax
movl %eax, %ecx
rolw $0x8, %cx
movzwl %cx, %ebp
movl %eax, %ecx
xorl $0x100, %ecx            # imm = 0x100
movl %r15d, %edx
xorl $0x6, %edx
orw %cx, %dx
je 0x4e4d
xorl $0x200, %eax            # imm = 0x200
movl %r15d, %ecx
xorl $0x12, %ecx
orw %ax, %cx
jne 0x51cb
movzwl %r15w, %eax
movq %rax, 0x30(%rbx)
movq %r14, %rdi
callq 0x89f0
movq %rax, 0x78(%rbx)
movq %r13, %rdi
movl $0xb0, %esi
movl $0x3, %edx
leaq 0x5f59(%rip), %rcx      # 0xadce
jmp 0x51df
cmpw $0x2, %r15w
setb %al
movl %r15d, %ecx
orb %al, %cl
testb $0x1, %cl
jne 0x5103
movzwl %r15w, %ebp
shrl %ebp
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x89f0
movzwl (%rax,%r15,2), %eax
rolw $0x8, %ax
cmpw $0xc, %ax
je 0x4ed0
movzwl %ax, %eax
cmpl $0x6, %eax
jne 0x4ef4
movl $0x1, 0x5c(%rbx)
movl $0x6, (%rsp)
movq %r13, %rdi
movl $0xc4, %esi
jmp 0x4ee6
movl $0x1, 0x60(%rbx)
movl $0xc, (%rsp)
movq %r13, %rdi
movl $0xc9, %esi
movl $0x3, %edx
leaq 0x5f02(%rip), %rcx      # 0xadf4
jmp 0x4f0b
movl %eax, (%rsp)
movq %r13, %rdi
movl $0xcd, %esi
movl $0x3, %edx
leaq 0x5ef6(%rip), %rcx      # 0xae01
movq %r12, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x4ad6
incq %r15
cmpq %r15, %rbp
jne 0x4e99
jmp 0x51ec
cmpw $0x8, %r15w
jne 0x511c
movq %r14, %rdi
callq 0x89f0
movl (%rax), %r15d
bswapl %r15d
movq %r15, (%rbx)
movq %r14, %rdi
callq 0x89f0
movl 0x4(%rax), %eax
bswapl %eax
movq %rax, 0x8(%rbx)
movl $0x1, 0x54(%rbx)
movl %eax, (%rsp)
movq %r13, %rdi
movl $0xa1, %esi
movl $0x3, %edx
leaq 0x5e45(%rip), %rcx      # 0xadb9
movq %r12, %r8
movl %r15d, %r9d
jmp 0x51e5
cmpw $0x4, %r15w
jne 0x513c
movl $0x1, 0x64(%rbx)
movq %r14, %rdi
callq 0x89f0
movl (%rax), %r9d
bswapl %r9d
movl %r9d, 0x50(%rbx)
movq %r13, %rdi
movl $0x8f, %esi
jmp 0x5037
testw %r15w, %r15w
je 0x517e
movzwl %r15w, %r15d
movq %r15, 0x28(%rbx)
movq %r14, %rdi
callq 0x89f0
movq %rax, 0x70(%rbx)
movq %r13, %rdi
movl $0x83, %esi
jmp 0x5074
testw %r15w, %r15w
je 0x5188
movq %r14, %rdi
callq 0x89f0
movq %rax, 0x80(%rbx)
movzwl %r15w, %r9d
movq %r9, 0x40(%rbx)
movq %r13, %rdi
movl $0xda, %esi
movl $0x3, %edx
movq %r12, %rcx
movq %rax, %r8
jmp 0x5082
cmpw $0x1, %r15w
jne 0x5152
movq %r14, %rdi
callq 0x89f0
movzbl (%rax), %r9d
movb %r9b, 0x90(%rbx)
movq %r13, %rdi
movl $0xe5, %esi
movl $0x3, %edx
leaq 0x5d50(%rip), %rcx      # 0xad93
movq %r12, %r8
jmp 0x51e5
testw %r15w, %r15w
je 0x5192
movzwl %r15w, %r15d
movq %r15, 0x48(%rbx)
movq %r14, %rdi
callq 0x89f0
movq %rax, 0x88(%rbx)
movq %r13, %rdi
movl $0xff, %esi
movl $0x3, %edx
movq %r12, %rcx
movq %rax, %r8
movq %r15, %r9
callq 0x4a0a
jmp 0x51ec
cmpw $0x3, %r15w
jb 0x5168
movq %r14, %rdi
callq 0x89f0
movzwl (%rax), %eax
rolw $0x8, %ax
movzwl %ax, %r9d
decl %eax
cmpw $0x1, %ax
ja 0x51b2
movl $0x1, 0x58(%rbx)
movq %r13, %rdi
movl $0xf2, %esi
movl $0x3, %edx
leaq 0x5cfd(%rip), %rcx      # 0xadce
jmp 0x5043
movq %r13, %rdi
movl $0x117, %esi            # imm = 0x117
movl $0x3, %edx
leaq 0x5604(%rip), %rcx      # 0xa6ee
jmp 0x51a6
movq %r13, %rdi
movl $0x113, %esi            # imm = 0x113
jmp 0x5124
movq %r13, %rdi
movl $0xb5, %esi
jmp 0x5170
movq %r13, %rdi
movl $0xd2, %esi
movl $0x3, %edx
leaq 0x5cff(%rip), %rcx      # 0xae16
jmp 0x51a6
movq %r13, %rdi
movl $0xa3, %esi
movl $0x3, %edx
leaq 0x5c93(%rip), %rcx      # 0xadc3
jmp 0x51a6
movq %r13, %rdi
movl $0x7b, %esi
jmp 0x515a
movq %r13, %rdi
movl $0x91, %esi
movl $0x3, %edx
leaq 0x5c5e(%rip), %rcx      # 0xadae
jmp 0x51a6
movq %r13, %rdi
movl $0xe7, %esi
movl $0x3, %edx
leaq 0x5c32(%rip), %rcx      # 0xad98
jmp 0x51a6
movq %r13, %rdi
movl $0xf7, %esi
movl $0x3, %edx
leaq 0x5c6d(%rip), %rcx      # 0xade9
jmp 0x51a6
movq %r13, %rdi
movl $0x85, %esi
jmp 0x519a
movq %r13, %rdi
movl $0xdc, %esi
jmp 0x519a
movq %r13, %rdi
movl $0x101, %esi            # imm = 0x101
movl $0x3, %edx
leaq 0x5bfd(%rip), %rcx      # 0xada3
movq %r12, %r8
xorl %eax, %eax
callq 0x4ad6
jmp 0x51ec
movq %r13, %rdi
movl $0xf4, %esi
movl $0x3, %edx
leaq 0x5c71(%rip), %rcx      # 0xae37
jmp 0x5043
movq %r13, %rdi
movl $0xb2, %esi
movl $0x3, %edx
leaq 0x5bf7(%rip), %rcx      # 0xadd6
movq %r12, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x4ad6
movq %r14, %rdi
callq 0x8b06
testl %eax, %eax
je 0x4d27
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq