// File: /workspace/github_c_makefile_star2_O0/sTeeLM[P]dwipe/logging.c
// Function: dwipe_log
void dwipe_log( dwipe_log_t level, const char* format, ... )
{
/**
 *  Writes a message to the program log file.
 *
 */


	/* A result buffer. */
	int r;

	/* A time buffer. */
	time_t t;

	/* A pointer to the system time struct. */
	struct tm* p;

	/* The log file pointer. */
	FILE* fp;

	/* The log file descriptor. */
	int fd;

	/* The variable argument pointer. */
	va_list ap;

	/* Get the current time. */
	t = time( NULL );
	p = gmtime( &t );

	/* Open the log file for appending. */
	fp = fopen( DWIPE_KNOB_LOGFILE, "a" );

	if( fp == NULL )
	{
		fprintf( stderr, "dwipe_log: Unable to open '%s' for logging.\n", DWIPE_KNOB_LOGFILE );
		return;
	}
	
	/* Get the file descriptor of the log file. */
	fd = fileno( fp );

	/* Block and lock. */
	r = flock( fd, LOCK_EX );

	if( r != 0 )
	{
		perror( "dwipe_log: flock:" );
		fprintf( stderr, "dwipe_log: Unable to lock '%s' for logging.\n", DWIPE_KNOB_LOGFILE );
		return;
	}

	/* Print the date. The rc script uses the same format. */
	fprintf( fp, "[%i/%02i/%02i %02i:%02i:%02i] dwipe: ", \
	  1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec );

	switch( level )
	{

		case DWIPE_LOG_NONE:
			/* Do nothing. */
			break;

		case DWIPE_LOG_DEBUG:
			fprintf( fp, "debug: " );
			break;

		case DWIPE_LOG_INFO:
			fprintf( fp, "info: " );
			break;

		case DWIPE_LOG_NOTICE:
			fprintf( fp, "notice: " );
			break;

		case DWIPE_LOG_WARNING:
			fprintf( fp, "warning: " );
			break;

		case DWIPE_LOG_ERROR:
			fprintf( fp, "error: " );
			break;

		case DWIPE_LOG_FATAL:
			fprintf( fp, "fatal: " );
			break;

		case DWIPE_LOG_SANITY:
			/* TODO: Request that the user report the log. */
			fprintf( fp, "sanity: " );
			break;

		default:
			fprintf( fp, "level %i: ", level );

	}

	/* Fetch the argument list. */
	va_start( ap, format );

	/* Print the event. */
	vfprintf( fp, format, ap );

/*
	if( level >= DWIPE_LOG_WARNING )
	{
		vfprintf( stderr, format, ap );
	}
*/

	/* Release the argument list. */
	va_end( ap );

	/* Append a newline. */
	fprintf( fp, "\n" );

/*
	if( level >= DWIPE_LOG_WARNING )
	{
		fprintf( stderr, "\n" );
	}
*/

	/* Unlock the file. */
	r = flock( fd, LOCK_UN );

	if( r != 0 )
	{
		perror( "dwipe_log: flock:" );
		fprintf( stderr, "Error: Unable to unlock '%s' after logging.\n", DWIPE_KNOB_LOGFILE );
	}

	/* Close the stream. */
	r = fclose( fp );

	if( r != 0 )
	{
		perror( "dwipe_log: fclose:" );
		fprintf( stderr, "Error: Unable to close '%s' after logging.\n", DWIPE_KNOB_LOGFILE );
	}

}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
testb %al, %al
je 0xae22
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %r9, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movl %edi, 0x124(%rsp)
movq %rsi, 0x118(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x32a0
movq %rax, 0x108(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x3370
movq %rax, 0x100(%rsp)
leaq 0x63c6(%rip), %rdi      # 0x11238
leaq 0x45a5(%rip), %rsi      # 0xf41e
callq 0x3280
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
jne 0xaeb5
movq 0x9160(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x63ae(%rip), %rsi      # 0x11250
leaq 0x638f(%rip), %rdx      # 0x11238
movb $0x0, %al
callq 0x3270
jmp 0xb154
movq 0xf8(%rsp), %rdi
callq 0x32b0
movl %eax, 0xf4(%rsp)
movl 0xf4(%rsp), %edi
movl $0x2, %esi
callq 0x33c0
movl %eax, 0x114(%rsp)
cmpl $0x0, 0x114(%rsp)
je 0xaf1b
leaq 0x638b(%rip), %rdi      # 0x1127d
callq 0x3360
movq 0x90fa(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x6387(%rip), %rsi      # 0x1128f
leaq 0x6329(%rip), %rdx      # 0x11238
movb $0x0, %al
callq 0x3270
jmp 0xb154
movq 0xf8(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x14(%rax), %edx
addl $0x76c, %edx            # imm = 0x76C
movl 0x10(%rax), %ecx
incl %ecx
movl 0xc(%rax), %r8d
movl 0x8(%rax), %r9d
movl (%rax), %r10d
movl 0x4(%rax), %esi
movq %rsp, %rax
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
leaq 0x6365(%rip), %rsi      # 0x112bc
xorl %eax, %eax
callq 0x3270
movl 0x124(%rsp), %eax
movq %rax, 0x18(%rsp)
subq $0x7, %rax
ja 0xb03c
movq 0x18(%rsp), %rax
leaq 0x6298(%rip), %rcx      # 0x11218
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x6345(%rip), %rsi      # 0x112e2
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x6332(%rip), %rsi      # 0x112ea
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x631e(%rip), %rsi      # 0x112f1
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x630f(%rip), %rsi      # 0x112fa
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x6301(%rip), %rsi      # 0x11304
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x62f1(%rip), %rsi      # 0x1130c
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
leaq 0x62e1(%rip), %rsi      # 0x11314
movb $0x0, %al
callq 0x3270
jmp 0xb059
movq 0xf8(%rsp), %rdi
movl 0x124(%rsp), %edx
leaq 0x62cb(%rip), %rsi      # 0x1131d
movb $0x0, %al
callq 0x3270
leaq 0xd0(%rsp), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x130(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq 0xf8(%rsp), %rdi
movq 0x118(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x3380
leaq 0xd0(%rsp), %rax
movq 0xf8(%rsp), %rdi
leaq 0x68cb(%rip), %rsi      # 0x11982
movb $0x0, %al
callq 0x3270
movl 0xf4(%rsp), %edi
movl $0x8, %esi
callq 0x33c0
movl %eax, 0x114(%rsp)
cmpl $0x0, 0x114(%rsp)
je 0xb10b
leaq 0x6196(%rip), %rdi      # 0x1127d
callq 0x3360
movq 0x8f05(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x622b(%rip), %rsi      # 0x11328
leaq 0x6134(%rip), %rdx      # 0x11238
movb $0x0, %al
callq 0x3270
movq 0xf8(%rsp), %rdi
callq 0x3140
movl %eax, 0x114(%rsp)
cmpl $0x0, 0x114(%rsp)
je 0xb154
leaq 0x6225(%rip), %rdi      # 0x11355
callq 0x3360
movq 0x8ebc(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x6222(%rip), %rsi      # 0x11368
leaq 0x60eb(%rip), %rdx      # 0x11238
movb $0x0, %al
callq 0x3270
addq $0x128, %rsp            # imm = 0x128
retq
nopl (%rax)