// File: /workspace/github_c_makefile_star2_O0/jfriesse[P]omping/rsfunc.c
// Function: rs_receive_msg
ssize_t
rs_receive_msg(int sock, struct sockaddr_storage *from_addr, char *msg, size_t msg_len,
    uint8_t *ttl, struct timeval *timestamp)
{
	char cmsg_buf[CMSG_SPACE(1024)];
	struct cmsghdr *cmsg;
	struct iovec msg_iovec;
	struct msghdr msg_hdr;
	ssize_t recv_size;
	int ittl;
	int timestamp_set;

	ittl = 0;
	timestamp_set = 0;

	memset(&msg_iovec, 0, sizeof(msg_iovec));
	msg_iovec.iov_base = msg;
	msg_iovec.iov_len = msg_len;

	memset(&msg_hdr, 0, sizeof(msg_hdr));
	msg_hdr.msg_name = from_addr;
	msg_hdr.msg_namelen = sizeof(struct sockaddr_storage);
	msg_hdr.msg_iov = &msg_iovec;
	msg_hdr.msg_iovlen = 1;
	msg_hdr.msg_control = cmsg_buf;
	msg_hdr.msg_controllen = sizeof(cmsg_buf);

	recv_size = recvmsg(sock, &msg_hdr, 0);

	if (recv_size == -1) {
		if (errno == EINTR) {
			DEBUG2_PRINTF("recvmsg error - EINTR");
			return (-2);
		}

		if (errno == EHOSTUNREACH || errno == EHOSTDOWN || errno == ENETDOWN ||
		    errno == ECONNRESET) {
			DEBUG2_PRINTF("recvmsg error - EHOSTUNREACH || EHOSTDOWN || ENETDOWN ||"
			    " ECONNRESET");
			return (-3);
		}

		DEBUG2_PRINTF("recvmsg error - errno = %d", errno);
		return (-1);
	}

	if (msg_hdr.msg_flags & MSG_TRUNC || msg_hdr.msg_flags & MSG_CTRUNC) {
		DEBUG2_PRINTF("recvmsg error - MSG_TRUNC | MSG_CTRUNC");
		return (-4);
	}

	for (cmsg = CMSG_FIRSTHDR(&msg_hdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg_hdr, cmsg)) {
		switch (cmsg->cmsg_level) {
		case SOL_SOCKET:
#ifdef SCM_TIMESTAMP
			if (cmsg->cmsg_type == SCM_TIMESTAMP &&
			    cmsg->cmsg_len >= sizeof(struct timeval) && timestamp != NULL) {
				memcpy(timestamp, CMSG_DATA(cmsg), sizeof(struct timeval));
				timestamp_set = 1;
			}
#endif
		case IPPROTO_IP:
			if (cmsg->cmsg_type == IP_TTL && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
				memcpy(&ittl, CMSG_DATA(cmsg), sizeof(ittl));
			}
#ifdef IP_RECVTTL
			if (cmsg->cmsg_type == IP_RECVTTL && cmsg->cmsg_len > 1) {
				ittl = *(uint8_t *)CMSG_DATA(cmsg);
			}
#endif
			break;
		case IPPROTO_IPV6:
			if (cmsg->cmsg_type == IPV6_HOPLIMIT && cmsg->cmsg_len ==
			    CMSG_LEN(sizeof(int))) {
				memcpy(&ittl, CMSG_DATA(cmsg), sizeof(ittl));
			}
			break;
		}
	}

	*ttl = (uint8_t)ittl;

	if (!timestamp_set && timestamp != NULL) {
		*timestamp = util_get_time();
	}

	return (recv_size);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x4ac(%rbp)
movl $0x0, -0x4b0(%rbp)
leaq -0x468(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2150
movq -0x20(%rbp), %rax
movq %rax, -0x468(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x460(%rbp)
leaq -0x4a0(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x2150
movq -0x18(%rbp), %rax
movq %rax, -0x4a0(%rbp)
movl $0x80, -0x498(%rbp)
leaq -0x468(%rbp), %rax
movq %rax, -0x490(%rbp)
movq $0x1, -0x488(%rbp)
leaq -0x450(%rbp), %rax
movq %rax, -0x480(%rbp)
movq $0x410, -0x478(%rbp) # imm = 0x410
movl -0xc(%rbp), %edi
leaq -0x4a0(%rbp), %rsi
xorl %edx, %edx
callq 0x2270
movq %rax, -0x4a8(%rbp)
cmpq $-0x1, -0x4a8(%rbp)
jne 0xa20d
callq 0x2050
cmpl $0x4, (%rax)
jne 0xa185
leaq 0x550c(%rip), %rdi      # 0xf66c
movl $0xa7, %esi
movl $0x3, %edx
leaq 0x5571(%rip), %rcx      # 0xf6e2
movb $0x0, %al
callq 0x5dc0
movq $-0x2, -0x8(%rbp)
jmp 0xa41e
callq 0x2050
cmpl $0x71, (%rax)
je 0xa1ad
callq 0x2050
cmpl $0x70, (%rax)
je 0xa1ad
callq 0x2050
cmpl $0x64, (%rax)
je 0xa1ad
callq 0x2050
cmpl $0x68, (%rax)
jne 0xa1d9
leaq 0x54b8(%rip), %rdi      # 0xf66c
movl $0xae, %esi
movl $0x3, %edx
leaq 0x5533(%rip), %rcx      # 0xf6f8
movb $0x0, %al
callq 0x5dc0
movq $-0x3, -0x8(%rbp)
jmp 0xa41e
callq 0x2050
movl (%rax), %r8d
leaq 0x5484(%rip), %rdi      # 0xf66c
movl $0xb2, %esi
movl $0x3, %edx
leaq 0x5543(%rip), %rcx      # 0xf73c
movb $0x0, %al
callq 0x5dc0
movq $-0x1, -0x8(%rbp)
jmp 0xa41e
movl -0x470(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xa229
movl -0x470(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xa255
leaq 0x543c(%rip), %rdi      # 0xf66c
movl $0xb7, %esi
movl $0x3, %edx
leaq 0x5516(%rip), %rcx      # 0xf757
movb $0x0, %al
callq 0x5dc0
movq $-0x4, -0x8(%rbp)
jmp 0xa41e
cmpq $0x10, -0x478(%rbp)
jb 0xa26f
movq -0x480(%rbp), %rax
movq %rax, -0x4c8(%rbp)
jmp 0xa27a
xorl %eax, %eax
movq %rax, -0x4c8(%rbp)
jmp 0xa27a
movq -0x4c8(%rbp), %rax
movq %rax, -0x458(%rbp)
cmpq $0x0, -0x458(%rbp)
je 0xa3b8
movq -0x458(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x4cc(%rbp)
testl %eax, %eax
je 0xa314
jmp 0xa2ac
movl -0x4cc(%rbp), %eax
subl $0x1, %eax
je 0xa2cd
jmp 0xa2b9
movl -0x4cc(%rbp), %eax
subl $0x29, %eax
je 0xa36b
jmp 0xa397
movq -0x458(%rbp), %rax
cmpl $0x1d, 0xc(%rax)
jne 0xa312
movq -0x458(%rbp), %rax
cmpq $0x10, (%rax)
jb 0xa312
cmpq $0x0, -0x38(%rbp)
je 0xa312
movq -0x38(%rbp), %rax
movq -0x458(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl $0x1, -0x4b0(%rbp)
jmp 0xa314
movq -0x458(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0xa33e
movq -0x458(%rbp), %rax
cmpq $0x14, (%rax)
jne 0xa33e
movq -0x458(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4ac(%rbp)
movq -0x458(%rbp), %rax
cmpl $0xc, 0xc(%rax)
jne 0xa369
movq -0x458(%rbp), %rax
cmpq $0x1, (%rax)
jbe 0xa369
movq -0x458(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x4ac(%rbp)
jmp 0xa397
movq -0x458(%rbp), %rax
cmpl $0x34, 0xc(%rax)
jne 0xa395
movq -0x458(%rbp), %rax
cmpq $0x14, (%rax)
jne 0xa395
movq -0x458(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4ac(%rbp)
jmp 0xa397
jmp 0xa399
movq -0x458(%rbp), %rsi
leaq -0x4a0(%rbp), %rdi
callq 0x2320
movq %rax, -0x458(%rbp)
jmp 0xa288
movl -0x4ac(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
cmpl $0x0, -0x4b0(%rbp)
jne 0xa413
cmpq $0x0, -0x38(%rbp)
je 0xa413
movq -0x38(%rbp), %rax
movq %rax, -0x4d8(%rbp)
callq 0xcb30
movq %rax, %rcx
movq -0x4d8(%rbp), %rax
movq %rcx, -0x4c0(%rbp)
movq %rdx, -0x4b8(%rbp)
movq -0x4c0(%rbp), %rcx
movq %rcx, (%rax)
movq -0x4b8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x4a8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
nopl (%rax,%rax)