// File: /workspace/github_c_makefile_star2_O0/jfriesse[P]omping/omping.c
// Function: omping_process_msg
static int
omping_process_msg(struct omping_instance *instance, const char *msg, size_t msg_len,
    const struct sockaddr_storage *from, uint8_t ttl, enum sf_cast_type cast_type,
    struct timeval rp_timestamp)
{
	char addr_str[INET6_ADDRSTRLEN];
	struct msg_decoded msg_decoded;
	const char *cast_str;
	struct rh_item *rh_item;
	int res;

	res = 0;

	msg_decode(msg, msg_len, &msg_decoded);

	cast_str = sf_cast_type_to_str(cast_type);

	af_sa_to_str((struct sockaddr *)from, addr_str);
	DEBUG_PRINTF("Received %scast message from %s type %c (0x%X), len %zu", cast_str, addr_str,
	    msg_decoded.msg_type, msg_decoded.msg_type, msg_len);

	if (omping_check_msg_common(&msg_decoded) == -1) {
		res = ms_stop(instance->ucast_socket, &instance->mcast_addr.sas, &msg_decoded,
		    from);
	} else {
		switch (msg_decoded.msg_type) {
		case MSG_TYPE_INIT:
			if (cast_type != SF_CT_UNI)
				goto error_unknown_mcast;

			if (instance->op_mode == OMPING_OP_MODE_CLIENT)
				goto error_unknown_msg_type;

			res = omping_process_init_msg(instance, msg, msg_len, &msg_decoded, from,
			    rp_timestamp);
			break;
		case MSG_TYPE_RESPONSE:
			if (cast_type != SF_CT_UNI)
				goto error_unknown_mcast;

			if (instance->op_mode == OMPING_OP_MODE_SERVER)
				goto error_unknown_msg_type;

			res = omping_process_response_msg(instance, msg, msg_len, &msg_decoded,
			    from);
			break;
		case MSG_TYPE_QUERY:
			if (cast_type != SF_CT_UNI)
				goto error_unknown_mcast;

			if (instance->op_mode == OMPING_OP_MODE_CLIENT)
				goto error_unknown_msg_type;

			res = omping_process_query_msg(instance, msg, msg_len, &msg_decoded, from,
			    rp_timestamp);
			break;
		case MSG_TYPE_ANSWER:
			if (instance->op_mode == OMPING_OP_MODE_SERVER && cast_type == SF_CT_UNI)
				goto error_unknown_msg_type;

			res = omping_process_answer_msg(instance, msg, msg_len, &msg_decoded, from,
			    ttl, cast_type, rp_timestamp);
			break;
		}
	}

	switch (res) {
	case -1:
		err(2, "Cannot send message");
		/* NOTREACHED */
		break;
	case -2:
		return (-2);
		/* NOTREACHED */
		break;
	case -3:
		warn("Send message error");
		rh_item = rh_list_find(&instance->remote_hosts, (const struct sockaddr *)from);
		if (rh_item == NULL) {
			DEBUG_PRINTF("Received message from unknown address");
		} else {
			rh_item->client_info.no_err_msgs++;
		}
		break;
	case -4:
		DEBUG_PRINTF("Cannot send message. Buffer too small");
		break;
	}

	return (0);

error_unknown_mcast:
	DEBUG_PRINTF("Received multicast message with invalid type %c (0x%X)",
	    msg_decoded.msg_type, msg_decoded.msg_type);

	return (0);

error_unknown_msg_type:
	DEBUG_PRINTF("Received message type %c (0x%X) which is not supported in given "
	    "operational mode", msg_decoded.msg_type, msg_decoded.msg_type);

	return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movb %r8b, %al
leaq 0x10(%rbp), %r8
movq %r8, -0x118(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movb %al, -0x29(%rbp)
movl %r9d, -0x30(%rbp)
movl $0x0, -0x10c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x6000
movl -0x30(%rbp), %edi
callq 0xaf50
movq %rax, -0x100(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3360
movq -0x100(%rbp), %r8
leaq -0x60(%rbp), %r9
movl -0xd8(%rbp), %r11d
movl -0xd8(%rbp), %r10d
movq -0x20(%rbp), %rax
leaq 0x6ad2(%rip), %rdi      # 0xefa0
movl $0x1a5, %esi            # imm = 0x1A5
movl $0x2, %edx
leaq 0x6d08(%rip), %rcx      # 0xf1e7
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x5dc0
leaq -0xf8(%rbp), %rdi
callq 0x8820
cmpl $-0x1, %eax
jne 0x8535
movq -0x10(%rbp), %rax
movl 0x198(%rax), %edi
movq -0x10(%rbp), %rsi
addq $0x98, %rsi
movq -0x28(%rbp), %rcx
leaq -0xf8(%rbp), %rdx
callq 0x73e0
movl %eax, -0x10c(%rbp)
jmp 0x86c2
movl -0xd8(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0x120(%rbp)
subl $0x12, %eax
ja 0x86c0
movq -0x120(%rbp), %rax
leaq 0x69e6(%rip), %rcx      # 0xef44
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, -0x30(%rbp)
je 0x8572
jmp 0x87aa
movq -0x10(%rbp), %rax
cmpl $0x1, 0x150(%rax)
jne 0x8584
jmp 0x87e0
movq -0x118(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
leaq -0xf8(%rbp), %rcx
movq (%rax), %r9
movq %r9, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x88e0
movl %eax, -0x10c(%rbp)
jmp 0x86c0
cmpl $0x0, -0x30(%rbp)
je 0x85cd
jmp 0x87aa
movq -0x10(%rbp), %rax
cmpl $0x2, 0x150(%rax)
jne 0x85df
jmp 0x87e0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
leaq -0xf8(%rbp), %rcx
callq 0x8ba0
movl %eax, -0x10c(%rbp)
jmp 0x86c0
cmpl $0x0, -0x30(%rbp)
je 0x8611
jmp 0x87aa
movq -0x10(%rbp), %rax
cmpl $0x1, 0x150(%rax)
jne 0x8623
jmp 0x87e0
movq -0x118(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
leaq -0xf8(%rbp), %rcx
movq (%rax), %r9
movq %r9, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x9080
movl %eax, -0x10c(%rbp)
jmp 0x86c0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x150(%rax)
jne 0x8676
cmpl $0x0, -0x30(%rbp)
jne 0x8676
jmp 0x87e0
movq -0x118(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
movb -0x29(%rbp), %r9b
movl -0x30(%rbp), %r10d
leaq -0xf8(%rbp), %rcx
movzbl %r9b, %r9d
movl %r10d, (%rsp)
movq (%rax), %r10
movq %r10, 0x8(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x9300
movl %eax, -0x10c(%rbp)
jmp 0x86c2
movl -0x10c(%rbp), %eax
addl $0x4, %eax
movl %eax, %ecx
movq %rcx, -0x128(%rbp)
subl $0x3, %eax
ja 0x87a1
movq -0x128(%rbp), %rax
leaq 0x68a5(%rip), %rcx      # 0xef90
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, %edi
leaq 0x69a9(%rip), %rsi      # 0xf0a9
movb $0x0, %al
callq 0x2240
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x8814
leaq 0x69a3(%rip), %rdi      # 0xf0bd
movb $0x0, %al
callq 0x2070
movq -0x10(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq -0x28(%rbp), %rsi
callq 0x9b40
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x108(%rbp)
jne 0x8767
leaq 0x6853(%rip), %rdi      # 0xefa0
movl $0x1e1, %esi            # imm = 0x1E1
movl $0x2, %edx
leaq 0x6ac1(%rip), %rcx      # 0xf21f
movb $0x0, %al
callq 0x5dc0
jmp 0x8780
movq -0x108(%rbp), %rax
movq 0xb8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0xb8(%rax)
jmp 0x87a1
leaq 0x6817(%rip), %rdi      # 0xefa0
movl $0x1e7, %esi            # imm = 0x1E7
movl $0x2, %edx
leaq 0x6936(%rip), %rcx      # 0xf0d0
movb $0x0, %al
callq 0x5dc0
movl $0x0, -0x4(%rbp)
jmp 0x8814
movl -0xd8(%rbp), %r8d
movl -0xd8(%rbp), %r9d
leaq 0x67e1(%rip), %rdi      # 0xefa0
movl $0x1ef, %esi            # imm = 0x1EF
movl $0x2, %edx
leaq 0x6a75(%rip), %rcx      # 0xf245
movb $0x0, %al
callq 0x5dc0
movl $0x0, -0x4(%rbp)
jmp 0x8814
movl -0xd8(%rbp), %r8d
movl -0xd8(%rbp), %r9d
leaq 0x67ab(%rip), %rdi      # 0xefa0
movl $0x1f5, %esi            # imm = 0x1F5
movl $0x2, %edx
leaq 0x6a76(%rip), %rcx      # 0xf27c
movb $0x0, %al
callq 0x5dc0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq