// File: /workspace/github_cpp_makefile_star2_O3/csMOOC[P]UIUC/EmulNet.cpp
// Function: EmulNet::ENsend(Address*, Address*, char*, int)
int EmulNet::ENsend(Address *myaddr, Address *toaddr, char *data, int size) {
	en_msg *em;
	static char temp[2048];
	int sendmsg = rand() % 100;

	if( (emulnet.currbuffsize >= ENBUFFSIZE) || (size + (int)sizeof(en_msg) >= par->MAX_MSG_SIZE) || (par->dropmsg && sendmsg < (int) (par->MSG_DROP_PROB * 100)) ) {
		return 0;
	}

	em = (en_msg *)malloc(sizeof(en_msg) + size);
	em->size = size;

	memcpy(&(em->from.addr), &(myaddr->addr), sizeof(em->from.addr));
	memcpy(&(em->to.addr), &(toaddr->addr), sizeof(em->from.addr));
	memcpy(em + 1, data, size);

	emulnet.buff[emulnet.currbuffsize++] = em;

	int src = *(int *)(myaddr->addr);
	int time = par->getcurrtime();

	assert(src <= MAX_NODES);
	assert(time < MAX_TIME);

	sent_msgs[src][time]++;

	#ifdef DEBUGLOG
		sprintf(temp, "Sending 4+%d B msg type %d to %d.%d.%d.%d:%d ", size-4, *(int *)data, toaddr->addr[0], toaddr->addr[1], toaddr->addr[2], toaddr->addr[3], *(short *)&toaddr->addr[4]);
	#endif

	return size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebx
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r12
callq 0x2060
movl %eax, %ecx
movslq 0x1b7e4a4(%r12), %rbp
xorl %eax, %eax
cmpq $0x752f, %rbp           # imm = 0x752F
jg 0x36c7
leal 0x10(%rbx), %esi
movq 0x8(%r12), %rdx
cmpl 0x1c(%rdx), %esi
jge 0x36c7
cmpl $0x0, 0x24(%rdx)
je 0x35eb
movslq %ecx, %rcx
imulq $0x51eb851f, %rcx, %rsi # imm = 0x51EB851F
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x25, %rsi
addl %edi, %esi
imull $0x64, %esi, %esi
movsd 0x8(%rdx), %xmm0
mulsd 0x3ab3(%rip), %xmm0     # 0x7090
subl %esi, %ecx
cvttsd2si %xmm0, %edx
cmpl %edx, %ecx
jl 0x36c7
movslq %ebx, %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rax), %rdi
callq 0x2240
movq %r15, %rsi
movq %rax, %r15
movl %ebx, (%rax)
movl (%r13), %eax
movl %eax, 0x4(%r15)
movzwl 0x4(%r13), %eax
movw %ax, 0x8(%r15)
movl (%r14), %eax
movl %eax, 0xa(%r15)
movzwl 0x4(%r14), %eax
movw %ax, 0xe(%r15)
leaq 0x10(%r15), %rdi
movq %rsi, 0x8(%rsp)
movq 0x10(%rsp), %rdx
callq 0x2130
leal 0x1(%rbp), %eax
movl %eax, 0x1b7e4a4(%r12)
movq %r15, 0x1b7e4b0(%r12,%rbp,8)
movslq (%r13), %r15
movq 0x8(%r12), %rdi
callq 0x4cf8
cmpq $0x3e9, %r15            # imm = 0x3E9
jge 0x36d6
cmpl $0xe10, %eax            # imm = 0xE10
jge 0x36f5
imulq $0x3840, %r15, %rcx     # imm = 0x3840
addq %rcx, %r12
cltq
incl 0x10(%r12,%rax,4)
leal -0x4(%rbx), %edx
movq 0x8(%rsp), %rax
movl (%rax), %ecx
movsbl (%r14), %r8d
movsbl 0x1(%r14), %r9d
movsbl 0x2(%r14), %r10d
movsbl 0x3(%r14), %r11d
movswl 0x4(%r14), %r14d
subq $0x8, %rsp
leaq 0x7f33(%rip), %rdi      # 0xb5e0
leaq 0x3a48(%rip), %rsi      # 0x70fc
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x2050
addq $0x20, %rsp
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39bb(%rip), %rdi      # 0x7098
leaq 0x39c5(%rip), %rsi      # 0x70a9
leaq 0x39ca(%rip), %rcx      # 0x70b5
movl $0x6c, %edx
callq 0x20f0
leaq 0x39f0(%rip), %rdi      # 0x70ec
leaq 0x39a6(%rip), %rsi      # 0x70a9
leaq 0x39ab(%rip), %rcx      # 0x70b5
movl $0x6d, %edx
callq 0x20f0