// File: csMOOC[P]UIUC/Log.cpp
// Function: Log::LOG(Address*, char const*, ...)
void Log::LOG(Address *addr, const char * str, ...) {

	static FILE *fp;
	static FILE *fp2;
	va_list vararglist;
	static char buffer[30000];
	static int numwrites;
	static char stdstring[30];
	static char stdstring2[40];
	static char stdstring3[40]; 
	static int dbg_opened=0;

	if(dbg_opened != 639){
		numwrites=0;

		stdstring2[0]=0;

		strcpy(stdstring3, stdstring2);

		strcat(stdstring2, DBG_LOG);
		strcat(stdstring3, STATS_LOG);

		fp = fopen(stdstring2, "w");
		fp2 = fopen(stdstring3, "w");

		dbg_opened=639;
	}
	else 

	sprintf(stdstring, "%d.%d.%d.%d:%d ", addr->addr[0], addr->addr[1], addr->addr[2], addr->addr[3], *(short *)&addr->addr[4]);

	va_start(vararglist, str);
	vsprintf(buffer, str, vararglist);
	va_end(vararglist);

	if (!firstTime) {
		int magicNumber = 0;
		string magic = MAGIC_NUMBER;
		int len = magic.length();
		for ( int i = 0; i < len; i++ ) {
			magicNumber += (int)magic.at(i);
		}
		fprintf(fp, "%x\n", magicNumber);
		firstTime = true;
	}

	if(memcmp(buffer, "#STATSLOG#", 10)==0){
		fprintf(fp2, "\n %s", stdstring);
		fprintf(fp2, "[%d] ", par->getcurrtime());

		fprintf(fp2, buffer);
	}
	else{
		fprintf(fp, "\n %s", stdstring);
		fprintf(fp, "[%d] ", par->getcurrtime());
		fprintf(fp, buffer);

	}

	if(++numwrites >= MAXWRITES){
		fflush(fp);
		fflush(fp2);
		numwrites=0;
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
testb %al, %al
je 0x90d7
movaps %xmm0, -0x100(%rbp)
movaps %xmm1, -0xf0(%rbp)
movaps %xmm2, -0xe0(%rbp)
movaps %xmm3, -0xd0(%rbp)
movaps %xmm4, -0xc0(%rbp)
movaps %xmm5, -0xb0(%rbp)
movaps %xmm6, -0xa0(%rbp)
movaps %xmm7, -0x90(%rbp)
movq %r9, -0x108(%rbp)
movq %r8, -0x110(%rbp)
movq %rcx, -0x118(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
cmpl $0x27f, 0x1434b(%rip)   # imm = 0x27F
je 0x919d
movl $0x0, 0x142b3(%rip)     # 0x1d3d0
movb $0x0, 0x142dc(%rip)     # 0x1d400
leaq 0x14305(%rip), %rdi     # 0x1d430
leaq 0x142ce(%rip), %rsi     # 0x1d400
callq 0x31e0
leaq 0x142c2(%rip), %rdi     # 0x1d400
leaq 0x62b4(%rip), %rsi      # 0xf3f9
callq 0x33d0
leaq 0x142df(%rip), %rdi     # 0x1d430
leaq 0x62a9(%rip), %rsi      # 0xf401
callq 0x33d0
leaq 0x1429c(%rip), %rdi     # 0x1d400
leaq 0x62a0(%rip), %rsi      # 0xf40b
callq 0x32b0
movq %rax, 0xcd11(%rip)      # 0x15e88
leaq 0x142b2(%rip), %rdi     # 0x1d430
leaq 0x6286(%rip), %rsi      # 0xf40b
callq 0x32b0
movq %rax, 0xccff(%rip)      # 0x15e90
movl $0x27f, 0x142bd(%rip)   # imm = 0x27F
jmp 0x91de
movq -0x10(%rbp), %rax
movsbl (%rax), %edx
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %ecx
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %r8d
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %r9d
movq -0x10(%rbp), %rax
movswl 0x4(%rax), %eax
leaq 0x14213(%rip), %rdi     # 0x1d3e0
leaq 0x5f96(%rip), %rsi      # 0xf16a
movl %eax, (%rsp)
movb $0x0, %al
callq 0x3060
leaq -0x30(%rbp), %rax
leaq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x18, (%rax)
movq -0x18(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq 0xcc8f(%rip), %rdi      # 0x15ea0
callq 0x30e0
movq -0x138(%rbp), %rax
leaq -0x30(%rbp), %rcx
testb $0x1, 0x10(%rax)
jne 0x9310
movl $0x0, -0x34(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x33c0
movq -0x140(%rbp), %rdx
leaq 0x61bd(%rip), %rsi      # 0xf40d
leaq -0x58(%rbp), %rdi
callq 0x95b0
jmp 0x925b
leaq -0x59(%rbp), %rdi
callq 0x3260
leaq -0x58(%rbp), %rdi
callq 0x3340
movl %eax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x70(%rbp), %eax
jge 0x92e4
movslq -0x74(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3410
movq %rax, -0x148(%rbp)
jmp 0x9295
movq -0x148(%rbp), %rax
movsbl (%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x9277
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x3260
jmp 0x943a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3120
jmp 0x943a
movq 0xcb9d(%rip), %rdi      # 0x15e88
movl -0x34(%rbp), %edx
leaq 0x611e(%rip), %rsi      # 0xf413
movb $0x0, %al
callq 0x3310
movq -0x138(%rbp), %rax
movb $0x1, 0x10(%rax)
leaq -0x58(%rbp), %rdi
callq 0x3120
leaq 0xcb89(%rip), %rdi      # 0x15ea0
leaq 0x60f9(%rip), %rsi      # 0xf417
movl $0xa, %edx
callq 0x30d0
cmpl $0x0, %eax
jne 0x9395
movq 0xcb5c(%rip), %rdi      # 0x15e90
leaq 0x60e7(%rip), %rsi      # 0xf422
leaq 0x1409e(%rip), %rdx     # 0x1d3e0
movb $0x0, %al
callq 0x3310
movq -0x138(%rbp), %rax
movq 0xcb39(%rip), %rcx      # 0x15e90
movq %rcx, -0x150(%rbp)
movq 0x8(%rax), %rdi
callq 0x99f0
movq -0x150(%rbp), %rdi
movl %eax, %edx
leaq 0x60b0(%rip), %rsi      # 0xf427
movb $0x0, %al
callq 0x3310
movq 0xcb0b(%rip), %rdi      # 0x15e90
leaq 0xcb14(%rip), %rsi      # 0x15ea0
movb $0x0, %al
callq 0x3310
jmp 0x93fb
movq 0xcaec(%rip), %rdi      # 0x15e88
leaq 0x607f(%rip), %rsi      # 0xf422
leaq 0x14036(%rip), %rdx     # 0x1d3e0
movb $0x0, %al
callq 0x3310
movq -0x138(%rbp), %rax
movq 0xcac9(%rip), %rcx      # 0x15e88
movq %rcx, -0x158(%rbp)
movq 0x8(%rax), %rdi
callq 0x99f0
movq -0x158(%rbp), %rdi
movl %eax, %edx
leaq 0x6048(%rip), %rsi      # 0xf427
movb $0x0, %al
callq 0x3310
movq 0xca9b(%rip), %rdi      # 0x15e88
leaq 0xcaac(%rip), %rsi      # 0x15ea0
movb $0x0, %al
callq 0x3310
movl 0x13fcf(%rip), %eax     # 0x1d3d0
addl $0x1, %eax
movl %eax, 0x13fc6(%rip)     # 0x1d3d0
cmpl $0x1, %eax
jl 0x9431
movq 0xca72(%rip), %rdi      # 0x15e88
callq 0x32a0
movq 0xca6e(%rip), %rdi      # 0x15e90
callq 0x32a0
movl $0x0, 0x13f9f(%rip)     # 0x1d3d0
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x33b0
nopw %cs:(%rax,%rax)