// File: /workspace/github_c_makefile_star2_O0/jfriesse[P]omping/omping.c
// Function: omping_process_response_msg
static int
omping_process_response_msg(struct omping_instance *instance, const char *msg, size_t msg_len,
    const struct msg_decoded *msg_decoded, const struct sockaddr_storage *from)
{
	struct rh_item *rh_item;
	enum rh_client_state old_cstate;
	const char *ci_ses_id;
	const char *msg_ses_id;
	int send_res;

	rh_item = rh_list_find(&instance->remote_hosts, (const struct sockaddr *)from);
	if (rh_item == NULL) {
		DEBUG_PRINTF("Received message from unknown address");

		return (-5);
	}

	if (rh_item->client_info.state == RH_CS_STOP) {
		DEBUG_PRINTF("Client is in stop state. Ignoring message.");

		return (-5);
	}

	if (msg_decoded->client_id == NULL) {
		DEBUG_PRINTF("Message doesn't contain client id");

		return (-5);
	}

	if (msg_decoded->client_id_len != CLIENTID_LEN ||
	    memcmp(msg_decoded->client_id, rh_item->client_info.client_id, CLIENTID_LEN) != 0) {
		DEBUG_PRINTF("Message doesn't contain our client id");

		return (-5);
	}

	if (instance->op_mode == OMPING_OP_MODE_SHOW_VERSION) {
		if (msg_decoded->server_info_len > 0) {
			rh_item->client_info.server_info_len = msg_decoded->server_info_len;

			free(rh_item->client_info.server_info);

			rh_item->client_info.server_info =
			    (char *)malloc(rh_item->client_info.server_info_len);

			if (rh_item->client_info.server_info == NULL) {
				errx(1, "Can't alloc memory");
			}

			memcpy(rh_item->client_info.server_info, msg_decoded->server_info,
			    rh_item->client_info.server_info_len);

			omping_client_move_to_stop(instance, rh_item,
			    RH_CSR_REMOTE_VERSION_RECEIVED);
		} else {
			DEBUG_PRINTF("Message doesn't contain server information");

			return (-5);
		}

		return (0);
	}

	if (msg_decoded->mcast_grp == NULL || msg_decoded->mcast_grp_len == 0) {
		DEBUG_PRINTF("Server doesn't send us multicast group");

		if (rh_item->client_info.state == RH_CS_QUERY) {
			DEBUG_PRINTF("Client was in query state. Put to initial state");

			rh_item->client_info.state = RH_CS_INITIAL;
			/*
			 * Technically, packet was sent and also received so no lost at all
			 */
			rh_item->client_info.no_sent--;

			util_gen_cid(rh_item->client_info.client_id, &instance->local_addr);
		} else {
			DEBUG_PRINTF("Client was not in query state. Put it to stop state");
			omping_client_move_to_stop(instance, rh_item, RH_CSR_SERVER);
		}

		return (-5);
	}

	if (!(tlv_mcast_grp_eq(&instance->mcast_addr.sas, msg_decoded->mcast_grp,
	    msg_decoded->mcast_grp_len))) {
		DEBUG_PRINTF("Server send us different multicast group then expected");

	}

	if (msg_decoded->ses_id == NULL) {
		DEBUG_PRINTF("Message doesn't contain session id");

		return (-5);
	}

	if (rh_item->client_info.ses_id_len == msg_decoded->ses_id_len) {
		ci_ses_id = rh_item->client_info.ses_id;
		msg_ses_id = msg_decoded->ses_id;

		if (memcmp(ci_ses_id, msg_ses_id, msg_decoded->ses_id_len) == 0) {
			DEBUG_PRINTF("Duplicate server response");

			return (-5);
		}
	}

	old_cstate = rh_item->client_info.state;
	rh_item->client_info.state = RH_CS_QUERY;
	rh_item->client_info.ses_id_len = msg_decoded->ses_id_len;

	free(rh_item->client_info.ses_id);

	rh_item->client_info.ses_id = (char *)malloc(rh_item->client_info.ses_id_len);
	if (rh_item->client_info.ses_id == NULL) {
		errx(1, "Can't alloc memory");
	}

	memcpy(rh_item->client_info.ses_id, msg_decoded->ses_id, rh_item->client_info.ses_id_len);

	if (old_cstate == RH_CS_INITIAL) {
		if (instance->quiet < 2) {
			cliprint_client_state(rh_item->addr->host_name, instance->hn_max_len,
			    instance->transport_method, &instance->mcast_addr.sas,
			    &rh_item->addr->sas, RH_CS_QUERY, RH_CSR_NONE);
		}
	}

	send_res = omping_send_client_query(instance, rh_item, (old_cstate == RH_CS_INITIAL));

	return (send_res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq -0x30(%rbp), %rsi
callq 0x9b40
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x8c06
leaq 0x63be(%rip), %rdi      # 0xefa0
movl $0x310, %esi            # imm = 0x310
movl $0x2, %edx
leaq 0x662c(%rip), %rcx      # 0xf21f
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movq -0x38(%rbp), %rax
cmpl $0x2, 0x8(%rax)
jne 0x8c3b
leaq 0x6389(%rip), %rdi      # 0xefa0
movl $0x316, %esi            # imm = 0x316
movl $0x2, %edx
leaq 0x6793(%rip), %rcx      # 0xf3bb
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movq -0x28(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jne 0x8c71
leaq 0x6353(%rip), %rdi      # 0xefa0
movl $0x31c, %esi            # imm = 0x31C
movl $0x2, %edx
leaq 0x6788(%rip), %rcx      # 0xf3e6
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movq -0x28(%rbp), %rax
cmpq $0x18, 0x28(%rax)
jne 0x8c9f
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x8, %rsi
addq $0x4, %rsi
movl $0x18, %edx
callq 0x2180
cmpl $0x0, %eax
je 0x8cca
leaq 0x62fa(%rip), %rdi      # 0xefa0
movl $0x323, %esi            # imm = 0x323
movl $0x2, %edx
leaq 0x6751(%rip), %rcx      # 0xf408
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movq -0x10(%rbp), %rax
cmpl $0x3, 0x150(%rax)
jne 0x8da8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jbe 0x8d71
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x2250
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x8d3d
movl $0x1, %edi
leaq 0x549e(%rip), %rsi      # 0xe1d4
movb $0x0, %al
callq 0x20d0
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x80(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdx
callq 0x2200
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x4, %edx
callq 0x82c0
jmp 0x8d9c
leaq 0x6228(%rip), %rdi      # 0xefa0
movl $0x33b, %esi            # imm = 0x33B
movl $0x2, %edx
leaq 0x66a5(%rip), %rcx      # 0xf42e
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movl $0x0, -0x4(%rbp)
jmp 0x9077
movq -0x28(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x8dc2
movq -0x28(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x8e7f
leaq 0x61d7(%rip), %rdi      # 0xefa0
movl $0x344, %esi            # imm = 0x344
movl $0x2, %edx
leaq 0x667f(%rip), %rcx      # 0xf459
movb $0x0, %al
callq 0x5dc0
movq -0x38(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x8e42
leaq 0x61ae(%rip), %rdi      # 0xefa0
movl $0x347, %esi            # imm = 0x347
movl $0x2, %edx
leaq 0x667d(%rip), %rcx      # 0xf480
movb $0x0, %al
callq 0x5dc0
movq -0x38(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0xe0(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0xe0(%rax)
movq -0x38(%rbp), %rdi
addq $0x8, %rdi
addq $0x4, %rdi
movq -0x10(%rbp), %rsi
callq 0xc9c0
jmp 0x8e73
leaq 0x6157(%rip), %rdi      # 0xefa0
movl $0x351, %esi            # imm = 0x351
movl $0x2, %edx
leaq 0x6656(%rip), %rcx      # 0xf4b0
movb $0x0, %al
callq 0x5dc0
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x82c0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movq -0x10(%rbp), %rdi
addq $0x98, %rdi
movq -0x28(%rbp), %rax
movq 0x78(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0xc740
cmpl $0x0, %eax
jne 0x8ec3
leaq 0x60f5(%rip), %rdi      # 0xefa0
movl $0x35a, %esi            # imm = 0x35A
movl $0x2, %edx
leaq 0x6628(%rip), %rcx      # 0xf4e4
movb $0x0, %al
callq 0x5dc0
movq -0x28(%rbp), %rax
cmpq $0x0, 0x88(%rax)
jne 0x8efc
leaq 0x60c8(%rip), %rdi      # 0xefa0
movl $0x35f, %esi            # imm = 0x35F
movl $0x2, %edx
leaq 0x6632(%rip), %rcx      # 0xf51b
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jne 0x8f70
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rdx
callq 0x2180
cmpl $0x0, %eax
jne 0x8f6e
leaq 0x6056(%rip), %rdi      # 0xefa0
movl $0x369, %esi            # imm = 0x369
movl $0x2, %edx
leaq 0x65e3(%rip), %rcx      # 0xf53e
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x9077
jmp 0x8f70
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x2250
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x8fd8
movl $0x1, %edi
leaq 0x5203(%rip), %rsi      # 0xe1d4
movb $0x0, %al
callq 0x20d0
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x88(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rdx
callq 0x2200
cmpl $0x0, -0x3c(%rbp)
jne 0x9055
movq -0x10(%rbp), %rax
cmpl $0x2, 0x180(%rax)
jge 0x9053
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x174(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x154(%rax), %edx
movq -0x10(%rbp), %rcx
addq $0x98, %rcx
movq -0x38(%rbp), %rax
movq (%rax), %r8
movl $0x1, %r9d
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x50f0
jmp 0x9055
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
cmpl $0x0, -0x3c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %edx
callq 0x8110
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq