// File: hunterlxt[P]swim-membership-protocol/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 0xa507
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, 0x13b0b(%rip)   # imm = 0x27F
je 0xa5cd
movl $0x0, 0x13a73(%rip)     # 0x1dfc0
movb $0x0, 0x13a9c(%rip)     # 0x1dff0
leaq 0x13ac5(%rip), %rdi     # 0x1e020
leaq 0x13a8e(%rip), %rsi     # 0x1dff0
callq 0x31d0
leaq 0x13a82(%rip), %rdi     # 0x1dff0
leaq 0x4ea4(%rip), %rsi      # 0xf419
callq 0x33c0
leaq 0x13a9f(%rip), %rdi     # 0x1e020
leaq 0x4e99(%rip), %rsi      # 0xf421
callq 0x33c0
leaq 0x13a5c(%rip), %rdi     # 0x1dff0
leaq 0x4e90(%rip), %rsi      # 0xf42b
callq 0x32a0
movq %rax, 0xc4d1(%rip)      # 0x16a78
leaq 0x13a72(%rip), %rdi     # 0x1e020
leaq 0x4e76(%rip), %rsi      # 0xf42b
callq 0x32a0
movq %rax, 0xc4bf(%rip)      # 0x16a80
movl $0x27f, 0x13a7d(%rip)   # imm = 0x27F
jmp 0xa60e
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 0x139d3(%rip), %rdi     # 0x1dfd0
leaq 0x4b7e(%rip), %rsi      # 0xf182
movl %eax, (%rsp)
movb $0x0, %al
callq 0x3050
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 0xc44f(%rip), %rdi      # 0x16a90
callq 0x30d0
movq -0x138(%rbp), %rax
leaq -0x30(%rbp), %rcx
testb $0x1, 0x10(%rax)
jne 0xa740
movl $0x0, -0x34(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x33b0
movq -0x140(%rbp), %rdx
leaq 0x4dad(%rip), %rsi      # 0xf42d
leaq -0x58(%rbp), %rdi
callq 0xa9e0
jmp 0xa68b
leaq -0x59(%rbp), %rdi
callq 0x3250
leaq -0x58(%rbp), %rdi
callq 0x3330
movl %eax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x70(%rbp), %eax
jge 0xa714
movslq -0x74(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3400
movq %rax, -0x148(%rbp)
jmp 0xa6c5
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 0xa6a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x3250
jmp 0xa86a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3110
jmp 0xa86a
movq 0xc35d(%rip), %rdi      # 0x16a78
movl -0x34(%rbp), %edx
leaq 0x4d0e(%rip), %rsi      # 0xf433
movb $0x0, %al
callq 0x3300
movq -0x138(%rbp), %rax
movb $0x1, 0x10(%rax)
leaq -0x58(%rbp), %rdi
callq 0x3110
leaq 0xc349(%rip), %rdi      # 0x16a90
leaq 0x4ce9(%rip), %rsi      # 0xf437
movl $0xa, %edx
callq 0x30c0
cmpl $0x0, %eax
jne 0xa7c5
movq 0xc31c(%rip), %rdi      # 0x16a80
leaq 0x4cd7(%rip), %rsi      # 0xf442
leaq 0x1385e(%rip), %rdx     # 0x1dfd0
movb $0x0, %al
callq 0x3300
movq -0x138(%rbp), %rax
movq 0xc2f9(%rip), %rcx      # 0x16a80
movq %rcx, -0x150(%rbp)
movq 0x8(%rax), %rdi
callq 0xae20
movq -0x150(%rbp), %rdi
movl %eax, %edx
leaq 0x4ca0(%rip), %rsi      # 0xf447
movb $0x0, %al
callq 0x3300
movq 0xc2cb(%rip), %rdi      # 0x16a80
leaq 0xc2d4(%rip), %rsi      # 0x16a90
movb $0x0, %al
callq 0x3300
jmp 0xa82b
movq 0xc2ac(%rip), %rdi      # 0x16a78
leaq 0x4c6f(%rip), %rsi      # 0xf442
leaq 0x137f6(%rip), %rdx     # 0x1dfd0
movb $0x0, %al
callq 0x3300
movq -0x138(%rbp), %rax
movq 0xc289(%rip), %rcx      # 0x16a78
movq %rcx, -0x158(%rbp)
movq 0x8(%rax), %rdi
callq 0xae20
movq -0x158(%rbp), %rdi
movl %eax, %edx
leaq 0x4c38(%rip), %rsi      # 0xf447
movb $0x0, %al
callq 0x3300
movq 0xc25b(%rip), %rdi      # 0x16a78
leaq 0xc26c(%rip), %rsi      # 0x16a90
movb $0x0, %al
callq 0x3300
movl 0x1378f(%rip), %eax     # 0x1dfc0
addl $0x1, %eax
movl %eax, 0x13786(%rip)     # 0x1dfc0
cmpl $0x1, %eax
jl 0xa861
movq 0xc232(%rip), %rdi      # 0x16a78
callq 0x3290
movq 0xc22e(%rip), %rdi      # 0x16a80
callq 0x3290
movl $0x0, 0x1375f(%rip)     # 0x1dfc0
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x33a0
nopw %cs:(%rax,%rax)