// File: /workspace/github_c_makefile_star2_O2/MikeGray-APH[P]LibLouisAPH/source/log.c
// Function: log_message
void log_message(const enum log_level level, const char *format, ...)
{
	va_list args;
	char message[LOG_MESSAGE_MAX], *arg_string;
	size_t fcrs, mcrs, len;
	unichar *arg_uchars, arg_uchar;
	unsigned int arg_unt;
	int arg_int;

	if(!log_callback)
		return;

	memset(message, 0, LOG_MESSAGE_MAX);
	va_start(args, format);
	for(fcrs = mcrs = 0; fcrs < strlen(format) - 1; fcrs++)
	{
		if(format[fcrs] != '%')
			message[mcrs++] = format[fcrs];
		else switch(format[++fcrs])
		{
		case 'd':

			arg_int = va_arg(args, int);
			len = snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, "%d", arg_int);
			mcrs += len;
			break;

		case 'u':

			arg_unt = va_arg(args, int);
			len = snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, "%u", arg_unt);
			mcrs += len;
			break;

		case 'x':

			arg_unt = va_arg(args, int);
			len = snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, "%x", arg_unt);
			mcrs += len;
			break;

		case 'o':

			arg_unt = va_arg(args, int);
			len = snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, "%o", arg_unt);
			mcrs += len;
			break;

		case 'b':

			arg_unt = va_arg(args, int);
			len = convert_number(&message[mcrs], LOG_MESSAGE_MAX - mcrs, arg_unt, 2);
			mcrs += len;
			break;

		case 'c':

			arg_int = va_arg(args, int);
			len = snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, "%c", arg_int);
			mcrs += len;
			break;

		case 's':

			arg_string = va_arg(args, char*);
			len = snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, "%s", arg_string);
			mcrs += len;
			break;

		case 'C':

			arg_uchar = (unichar)va_arg(args, int);
			len = utf16_convert_to_utf8(&message[mcrs], LOG_MESSAGE_MAX - mcrs, &arg_uchar, 1, NULL);
			mcrs += len;
			break;

		case 'S':

			arg_uchars = (unichar*)va_arg(args, unichar*);
			len = 0;
			while(arg_uchars[len])
				len++;
			len = utf16_convert_to_utf8(&message[mcrs], LOG_MESSAGE_MAX - mcrs, arg_uchars, len, NULL);
			mcrs += len;
			break;

		case '#':

			fcrs++;
			if(fcrs >= strlen(format))
			{
				/*   copy last chars to message   */
				message[mcrs++] = format[fcrs - 2];
				message[mcrs++] = format[fcrs - 1];
				break;
			}
			if(format[fcrs] == 'S')
			{
				arg_uchars = (unichar*)va_arg(args, unichar*);
				arg_int = va_arg(args, int);
				len = utf16_convert_to_utf8(&message[mcrs], LOG_MESSAGE_MAX - mcrs, arg_uchars, arg_int, NULL);
				mcrs += len;
			}
			else
			{
				snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, ":  ERROR:  unknown specifier %%#%c", format[fcrs]);
				message[LOG_MESSAGE_MAX - 1] = 0;
				goto return_message;
			}
			break;

		default:

			snprintf(&message[mcrs], LOG_MESSAGE_MAX - mcrs, ":  ERROR:  unknown specifier %%%c", format[fcrs]);
			message[LOG_MESSAGE_MAX - 1] = 0;
			goto return_message;
		}

		if(mcrs >= LOG_MESSAGE_MAX - 1)
		{
			mcrs = LOG_MESSAGE_MAX - 1;
			message[mcrs] = 0;
			goto return_message;
		}
	}
	va_end(args);

	/*   copy last char to message   */
	if(fcrs < strlen(format))
	if(mcrs < LOG_MESSAGE_MAX - 1)
		message[mcrs++] = format[fcrs];
	else
		mcrs = LOG_MESSAGE_MAX - 1;
	message[mcrs] = 0;

	return_message:
	OUTPUT_TO_FILE(level, message)
	log_callback(level, message);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1128, %rsp           # imm = 0x1128
movq %rdx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x48(%rsp)
testb %al, %al
je 0x91d4
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)
cmpq $0x0, 0x100ac(%rip)     # 0x19288
je 0x974b
movq %rsi, %r14
movl %edi, 0x18(%rsp)
leaq 0x120(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x1110
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
leaq 0x1160(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xd0(%rsp), %r15
leaq 0x890f(%rip), %rbp      # 0x11b40
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x10b0
leaq -0x1(%rax), %rcx
cmpq %rcx, %r13
jae 0x96c2
movb (%r14,%r13), %cl
cmpb $0x25, %cl
jne 0x92bd
leaq 0x1(%r13), %rbx
movzbl 0x1(%r14,%r13), %ecx
leal -0x6f(%rcx), %edx
cmpl $0x9, %edx
jbe 0x92d3
cmpl $0x23, %ecx
je 0x93dd
cmpl $0x43, %ecx
je 0x939d
cmpl $0x53, %ecx
je 0x93bd
cmpl $0x62, %ecx
je 0x935d
cmpl $0x63, %ecx
je 0x937d
cmpl $0x64, %ecx
jne 0x96ee
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x9570
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x957e
movb %cl, 0x120(%rsp,%r12)
incq %r12
movq %r13, %rbx
movq %r12, %rax
jmp 0x9642
movslq (%rbp,%rdx,4), %rax
addq %rbp, %rax
jmpq *%rax
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x9460
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x946e
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x9431
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x943f
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x948f
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x949d
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x94c6
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x94d4
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x94f5
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x9503
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x959c
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x95aa
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x95cf
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x95dd
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x9602
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x9610
addq $0x2, %r13
cmpq %rax, %r13
jae 0x965c
movsbl (%r14,%r13), %ecx
cmpl $0x53, %ecx
jne 0x970d
movl (%rsp), %ecx
cmpq $0x29, %rcx
jae 0x967c
movq 0x10(%rsp), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, (%rsp)
movq (%rdx,%rcx), %rdx
cmpl $0x20, %ecx
ja 0x968d
addq 0x10(%rsp), %rax
addl $0x10, %ecx
movl %ecx, (%rsp)
jmp 0x969b
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x8710(%rip), %rdx      # 0x11b6b
jmp 0x95c6
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x86e4(%rip), %rdx      # 0x11b6e
jmp 0x95c6
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rcx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x8618(%rip), %rdx      # 0x11ad2
xorl %eax, %eax
callq 0x10e0
jmp 0x963d
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x8678(%rip), %rdx      # 0x11b68
jmp 0x95c6
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %edx
movq %r12, %rax
leaq 0xcf(%rsp), %rdi
movl %edx, %esi
movq %rdi, %rcx
incq %rdi
movl %edx, %r8d
andb $0x1, %r8b
orb $0x30, %r8b
movb %r8b, 0x1(%rcx)
shrl %esi
incq %rax
cmpl $0x1, %edx
movl %esi, %edx
ja 0x9512
leaq (%rsp,%r12), %rdx
addq $0x120, %rdx            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subl %r12d, %esi
cmpl $0x1, %esi
adcl $-0x1, %esi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x9673
movb 0x1(%rcx), %r8b
movb %r8b, (%rdx,%rdi)
cmpq %r15, %rcx
jb 0x9670
incq %rdi
decq %rcx
jmp 0x954e
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x8be8(%rip), %rdx      # 0x12182
jmp 0x95c6
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x85cb(%rip), %rdx      # 0x11b91
xorl %eax, %eax
callq 0x10e0
jmp 0x963d
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movzwl (%rax), %eax
movw %ax, 0x1e(%rsp)
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subl %r12d, %esi
leaq 0x1e(%rsp), %rdx
pushq $0x1
popq %rcx
jmp 0x9635
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
xorl %ecx, %ecx
cmpw $0x0, (%rdx,%rcx,2)
leaq 0x1(%rcx), %rcx
jne 0x9615
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subl %r12d, %esi
decl %ecx
xorl %r8d, %r8d
callq 0x16db
cltq
addq %r12, %rax
incq %rbx
movq %rbx, %r13
movq %rax, %r12
cmpq $0xfff, %rax            # imm = 0xFFF
jb 0x9237
jmp 0x972e
movw $0x2325, 0x120(%rsp,%r12) # imm = 0x2325
addq $0x2, %r12
jmp 0x92c8
movq %rdi, %rsi
movl %esi, %ecx
movb $0x0, 0x1(%rdx,%rcx)
jmp 0x9642
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subl %r12d, %esi
xorl %r8d, %r8d
callq 0x16db
cltq
addq %r12, %rax
movq %r13, %rbx
jmp 0x9642
movq %r14, %rdi
callq 0x10b0
cmpq %rax, %r13
jae 0x96de
movb (%r14,%r13), %al
movb %al, 0x120(%rsp,%r12)
incq %r12
movl 0x18(%rsp), %edi
leaq (%rsp,%r12), %rax
addq $0x120, %rax            # imm = 0x120
jmp 0x973a
movsbl %cl, %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x8489(%rip), %rdx      # 0x11b94
jmp 0x9727
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x844a(%rip), %rdx      # 0x11b71
xorl %eax, %eax
callq 0x10e0
leaq 0x111f(%rsp), %rax
movl 0x18(%rsp), %edi
movb $0x0, (%rax)
leaq 0x120(%rsp), %rsi
callq *0xfb3d(%rip)           # 0x19288
addq $0x1128, %rsp           # imm = 0x1128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)