// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movq %rsi, %r14
movl %edi, %r15d
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x58(%rsp)
testb %al, %al
je 0x740f
movaps %xmm0, 0x60(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm2, 0x80(%rsp)
movaps %xmm3, 0x90(%rsp)
movaps %xmm4, 0xa0(%rsp)
movaps %xmm5, 0xb0(%rsp)
movaps %xmm6, 0xc0(%rsp)
movaps %xmm7, 0xd0(%rsp)
xorl %edi, %edi
callq 0x32b0
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
callq 0x3390
movq %rax, %r12
leaq 0x4e73(%rip), %rdi      # 0xc2a0
leaq 0x2fd2(%rip), %rsi      # 0xa406
callq 0x3290
testq %rax, %rax
je 0x7587
movq %rax, %rbx
movq %rax, %rdi
callq 0x32c0
movl %eax, %ebp
pushq $0x2
popq %rsi
movl %eax, %edi
callq 0x33e0
testl %eax, %eax
jne 0x7590
movl $0x76c, %edx            # imm = 0x76C
addl 0x14(%r12), %edx
movl 0x10(%r12), %ecx
incl %ecx
movl 0xc(%r12), %r8d
movl 0x8(%r12), %r9d
movl (%r12), %r10d
movl 0x4(%r12), %r11d
leaq 0x4e98(%rip), %rsi      # 0xc324
movq %rbx, %rdi
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0x3280
popq %rcx
popq %rdx
cmpl $0x7, %r15d
ja 0x7571
movl %r15d, %eax
leaq 0x4dd0(%rip), %rcx      # 0xc280
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4e8a(%rip), %rdi      # 0xc34a
jmp 0x74fc
leaq 0x4e99(%rip), %rdi      # 0xc362
pushq $0x9
jmp 0x74fe
leaq 0x4e7e(%rip), %rdi      # 0xc352
pushq $0x6
jmp 0x74fe
leaq 0x4e7a(%rip), %rdi      # 0xc359
jmp 0x74e8
leaq 0x4e94(%rip), %rdi      # 0xc37c
pushq $0x8
jmp 0x74fe
leaq 0x4e79(%rip), %rdi      # 0xc36c
jmp 0x74fc
leaq 0x4e78(%rip), %rdi      # 0xc374
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x3410
leaq 0x30(%rsp), %rax
leaq 0x10(%rsp), %rdx
movq %rax, 0x10(%rdx)
leaq 0x110(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rdx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33a0
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x3220
pushq $0x8
popq %rsi
movl %ebp, %edi
callq 0x33e0
testl %eax, %eax
jne 0x75a0
movq %rbx, %rdi
callq 0x3140
testl %eax, %eax
jne 0x75cd
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e0d(%rip), %rsi      # 0xc385
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3280
jmp 0x750a
leaq 0x4d2a(%rip), %rbx      # 0xc2b8
jmp 0x75e0
leaq 0x4d60(%rip), %rbx      # 0xc2f7
leaq 0x4d47(%rip), %rdi      # 0xc2e5
jmp 0x75db
leaq 0x4d3e(%rip), %rdi      # 0xc2e5
callq 0x3380
movq 0x8a3d(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x4dd3(%rip), %rsi      # 0xc390
leaq 0x4cdc(%rip), %rdx      # 0xc2a0
xorl %eax, %eax
callq 0x3280
jmp 0x7555
leaq 0x4dfc(%rip), %rbx      # 0xc3d0
leaq 0x4de2(%rip), %rdi      # 0xc3bd
callq 0x3380
movq 0x8a09(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x4caf(%rip), %rdx      # 0xc2a0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3280
jmp 0x7561