// File: csMOOC[P]UIUC/EmulNet.cpp
// Function: EmulNet::ENcleanup()
int EmulNet::ENcleanup() {
	emulnet.nextid=0;
	int i, j;
	int sent_total, recv_total;

	FILE* file = fopen("msgcount.log", "w+");

	while(emulnet.currbuffsize > 0) {
		free(emulnet.buff[--emulnet.currbuffsize]);
	}

	for ( i = 1; i <= par->EN_GPSZ; i++ ) {
		fprintf(file, "node %3d ", i);
		sent_total = 0;
		recv_total = 0;

		for (j = 0; j < par->getcurrtime(); j++) {

			sent_total += sent_msgs[i][j];
			recv_total += recv_msgs[i][j];
			if (i != 67) {
				fprintf(file, " (%4d, %4d)", sent_msgs[i][j], recv_msgs[i][j]);
				if (j % 10 == 9) {
					fprintf(file, "\n         ");
				}
			}
			else {
				fprintf(file, "special %4d %4d %4d\n", j, sent_msgs[i][j], recv_msgs[i][j]);
			}
		}
		fprintf(file, "\n");
		fprintf(file, "node %3d sent_total %6u  recv_total %6u\n\n", i, sent_total, recv_total);
	}

	fclose(file);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, 0x1b7e4a0(%rax)
leaq 0x7f02(%rip), %rdi      # 0xf1e7
leaq 0x7f08(%rip), %rsi      # 0xf1f4
callq 0x32b0
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x1b7e4a4(%rax)
jle 0x7327
movq -0x28(%rbp), %rax
movl 0x1b7e4a4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x1b7e4a4(%rax)
movslq %ecx, %rcx
movq 0x1b7e4b0(%rax,%rcx,8), %rdi
callq 0x32c0
jmp 0x72f5
movl $0x1, -0xc(%rbp)
movq -0x28(%rbp), %rcx
movl -0xc(%rbp), %eax
movq 0x8(%rcx), %rcx
cmpl 0x18(%rcx), %eax
jg 0x74e7
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %edx
leaq 0x7ea7(%rip), %rsi      # 0xf1f7
movb $0x0, %al
callq 0x3310
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x28(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
movq 0x8(%rax), %rdi
callq 0x99f0
movl %eax, %ecx
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
jge 0x74ab
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x10, %rcx
movslq -0xc(%rbp), %rdx
imulq $0x3840, %rdx, %rdx     # imm = 0x3840
addq %rdx, %rcx
movslq -0x10(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x14(%rbp), %ecx
movl %ecx, -0x14(%rbp)
addq $0xdbf250, %rax         # imm = 0xDBF250
movslq -0xc(%rbp), %rcx
imulq $0x3840, %rcx, %rcx     # imm = 0x3840
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x43, -0xc(%rbp)
je 0x744a
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rdi
movq %rax, %rcx
addq $0x10, %rcx
movslq -0xc(%rbp), %rdx
imulq $0x3840, %rdx, %rdx     # imm = 0x3840
addq %rdx, %rcx
movslq -0x10(%rbp), %rdx
movl (%rcx,%rdx,4), %edx
addq $0xdbf250, %rax         # imm = 0xDBF250
movslq -0xc(%rbp), %rcx
imulq $0x3840, %rcx, %rcx     # imm = 0x3840
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
leaq 0x7de2(%rip), %rsi      # 0xf201
movb $0x0, %al
callq 0x3310
movl -0x10(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x9, %edx
jne 0x7448
movq -0x20(%rbp), %rdi
leaq 0x7dcc(%rip), %rsi      # 0xf20d
movb $0x0, %al
callq 0x3310
jmp 0x749b
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %edx
movq %rax, %rcx
addq $0x10, %rcx
movslq -0xc(%rbp), %rsi
imulq $0x3840, %rsi, %rsi     # imm = 0x3840
addq %rsi, %rcx
movslq -0x10(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
addq $0xdbf250, %rax         # imm = 0xDBF250
movslq -0xc(%rbp), %rsi
imulq $0x3840, %rsi, %rsi     # imm = 0x3840
addq %rsi, %rax
movslq -0x10(%rbp), %rsi
movl (%rax,%rsi,4), %r8d
leaq 0x7d84(%rip), %rsi      # 0xf218
movb $0x0, %al
callq 0x3310
jmp 0x749d
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x736c
movq -0x20(%rbp), %rdi
leaq 0x7d9f(%rip), %rsi      # 0xf255
movb $0x0, %al
callq 0x3310
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
leaq 0x7d5b(%rip), %rsi      # 0xf22d
movb $0x0, %al
callq 0x3310
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x732e
movq -0x20(%rbp), %rdi
callq 0x3210
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)