// File: /workspace/github_c_makefile_star2_O0/jfriesse[P]omping/omping.c
// Function: omping_poll_receive_loop
static int
omping_poll_receive_loop(struct omping_instance *instance, int timeout_time)
{
	char msg[MAX_MSG_SIZE];
	struct sockaddr_storage from;
	struct timeval old_tstamp;
	struct timeval rp_timestamp;
	enum sf_cast_type cast_type;
	int i;
	int poll_res;
	int receive_res;
	uint8_t ttl;
	int res;

	memset(&old_tstamp, 0, sizeof(old_tstamp));

	do {
		poll_res = omping_poll_timeout(instance, &old_tstamp, timeout_time);
		if (poll_res == -2) {
			return (-2);
			/* NOTREACHED */
		}

		for (i = 0; i < 2; i++) {
			receive_res = 0;

			if (i == 0 && poll_res & 1) {
				receive_res = rs_receive_msg(instance->ucast_socket, &from, msg,
				    sizeof(msg), &ttl, &rp_timestamp);
			}

			if (i == 1 && poll_res & 2) {
				receive_res = rs_receive_msg(instance->mcast_socket, &from, msg,
				    sizeof(msg), &ttl, &rp_timestamp);
			}

			switch (receive_res) {
			case -1:
				err(2, "Cannot receive message");
				/* NOTREACHED */
				break;
			case -2:
				return (-2);
				/* NOTREACHED */
				break;
			case -3:
				warn("Cannot receive message");
				break;
			case -4:
				VERBOSE_PRINTF("Received message too long");
				break;
			}

			if (receive_res > 0) {
				if (i == 0) {
					cast_type = SF_CT_UNI;
				} else {
					switch (instance->transport_method) {
					case SF_TM_ASM:
					case SF_TM_SSM:
						cast_type = SF_CT_MULTI;
						break;
					case SF_TM_IPBC:
						cast_type = SF_CT_BROAD;
						break;
					default:
						DEBUG_PRINTF("Internal error - unknown tm");
						errx(1, "Internal error - unknown tm");
						/* NOTREACHED */
					}
				}

				res = omping_process_msg(instance, msg, receive_res, &from, ttl,
				    cast_type, rp_timestamp);

				if (res == -2) {
					return (-2);
				}
			}
		}
	} while (poll_res > 0);

	return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10100, %rsp          # imm = 0x10100
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
leaq -0x100b0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2150
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
leaq -0x100b0(%rbp), %rsi
callq 0x8340
movl %eax, -0x100cc(%rbp)
cmpl $-0x2, -0x100cc(%rbp)
jne 0x7ea3
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x80f9
movl $0x0, -0x100c8(%rbp)
cmpl $0x2, -0x100c8(%rbp)
jge 0x80e3
movl $0x0, -0x100d0(%rbp)
cmpl $0x0, -0x100c8(%rbp)
jne 0x7f11
movl -0x100cc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7f11
movq -0x10(%rbp), %rax
movl 0x198(%rax), %edi
leaq -0x10020(%rbp), %rdx
leaq -0x100a0(%rbp), %rsi
movl $0xffff, %ecx           # imm = 0xFFFF
leaq -0x100d1(%rbp), %r8
leaq -0x100c0(%rbp), %r9
callq 0xa070
movl %eax, -0x100d0(%rbp)
cmpl $0x1, -0x100c8(%rbp)
jne 0x7f5e
movl -0x100cc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x7f5e
movq -0x10(%rbp), %rax
movl 0x17c(%rax), %edi
leaq -0x10020(%rbp), %rdx
leaq -0x100a0(%rbp), %rsi
movl $0xffff, %ecx           # imm = 0xFFFF
leaq -0x100d1(%rbp), %r8
leaq -0x100c0(%rbp), %r9
callq 0xa070
movl %eax, -0x100d0(%rbp)
movl -0x100d0(%rbp), %eax
addl $0x4, %eax
movl %eax, %ecx
movq %rcx, -0x100e0(%rbp)
subl $0x3, %eax
ja 0x7fda
movq -0x100e0(%rbp), %rax
leaq 0x6fb1(%rip), %rcx      # 0xef34
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, %edi
leaq 0x71eb(%rip), %rsi      # 0xf183
movb $0x0, %al
callq 0x2240
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x80f9
leaq 0x71d1(%rip), %rdi      # 0xf183
movb $0x0, %al
callq 0x2070
jmp 0x7fda
leaq 0x6fde(%rip), %rdi      # 0xefa0
movl $0x137, %esi            # imm = 0x137
movl $0x1, %edx
leaq 0x71c7(%rip), %rcx      # 0xf19a
movb $0x0, %al
callq 0x5dc0
cmpl $0x0, -0x100d0(%rbp)
jle 0x80cd
cmpl $0x0, -0x100c8(%rbp)
jne 0x7ffc
movl $0x0, -0x100c4(%rbp)
jmp 0x806c
movq -0x10(%rbp), %rax
movl 0x154(%rax), %eax
movl %eax, -0x100e4(%rbp)
subl $0x2, %eax
jb 0x8020
jmp 0x8013
movl -0x100e4(%rbp), %eax
subl $0x2, %eax
je 0x802c
jmp 0x8038
movl $0x1, -0x100c4(%rbp)
jmp 0x806a
movl $0x2, -0x100c4(%rbp)
jmp 0x806a
leaq 0x6f61(%rip), %rdi      # 0xefa0
movl $0x148, %esi            # imm = 0x148
movl $0x2, %edx
leaq 0x7164(%rip), %rcx      # 0xf1b4
movb $0x0, %al
callq 0x5dc0
movl $0x1, %edi
leaq 0x7151(%rip), %rsi      # 0xf1b4
movb $0x0, %al
callq 0x20d0
jmp 0x806c
movq -0x10(%rbp), %rdi
leaq -0x10020(%rbp), %rsi
movslq -0x100d0(%rbp), %rdx
movb -0x100d1(%rbp), %r8b
movl -0x100c4(%rbp), %r9d
leaq -0x100a0(%rbp), %rcx
leaq -0x100c0(%rbp), %rax
movzbl %r8b, %r8d
movq (%rax), %r10
movq %r10, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x8440
movl %eax, -0x100d8(%rbp)
cmpl $-0x2, -0x100d8(%rbp)
jne 0x80cb
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x80f9
jmp 0x80cd
jmp 0x80cf
movl -0x100c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100c8(%rbp)
jmp 0x7ead
jmp 0x80e5
cmpl $0x0, -0x100cc(%rbp)
jg 0x7e75
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10100, %rsp          # imm = 0x10100
popq %rbp
retq
nopw %cs:(%rax,%rax)