// File: /workspace/github_c_makefile_star2_O1/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 0xa3cc
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, 0xfea4(%rip)      # 0x1a278
je 0xa965
movq %rsi, %r14
movl %edi, %ebx
leaq 0x120(%rsp), %rdi
xorl %ebp, %ebp
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)
movq %r14, %rdi
callq 0x10b0
cmpq $0x1, %rax
jne 0xa456
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x10b0
cmpq %rax, %rbp
jae 0xa447
movb (%r14,%rbp), %al
movb %al, 0x120(%rsp,%r12)
incq %r12
leaq (%rsp,%r12), %rax
addq $0x120, %rax            # imm = 0x120
jmp 0xa952
leaq 0xd0(%rsp), %r13
xorl %r12d, %r12d
xorl %r15d, %r15d
movb (%r14,%r15), %sil
cmpb $0x25, %sil
jne 0xa4b6
leaq 0x1(%r15), %rbp
movb 0x1(%r14,%r15), %cl
movzbl %cl, %edx
cmpl $0x62, %edx
jg 0xa4c9
cmpl $0x52, %edx
jg 0xa501
cmpl $0x23, %edx
je 0xa565
cmpl $0x43, %edx
jne 0xa90a
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa68e
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa69c
movb %sil, 0x120(%rsp,%r12)
incq %r12
movq %r15, %rbp
jmp 0xa87c
leal -0x6f(%rdx), %eax
cmpl $0x9, %eax
ja 0xa533
leaq 0x9628(%rip), %rdx      # 0x13b00
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa7bf
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa7cd
cmpl $0x53, %edx
je 0xa5a0
cmpl $0x62, %edx
jne 0xa90a
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa6ce
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa6dc
cmpl $0x63, %edx
je 0xa620
cmpl $0x64, %edx
jne 0xa90a
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa846
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa854
addq $0x2, %r15
cmpq %rax, %r15
jae 0xa640
movsbl (%r14,%r15), %ecx
cmpl $0x53, %ecx
jne 0xa929
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa8ab
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa8b9
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa659
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa667
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa759
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa767
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa788
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa796
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa7ee
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa7fc
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa81a
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa828
movb %sil, 0x120(%rsp,%r12)
movb %cl, 0x121(%rsp,%r12)
addq $0x2, %r12
jmp 0xa4c1
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 0xa66c
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subl %r12d, %esi
decl %ecx
jmp 0xa6c1
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
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x16c6
jmp 0xa877
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
leaq (%rsp,%r12), %rcx
addq $0x120, %rcx            # imm = 0x120
movq %r12, %rax
leaq 0xcf(%rsp), %r8
movl %esi, %edi
movq %r8, %rdx
incq %r8
movl %esi, %r9d
andb $0x1, %r9b
orb $0x30, %r9b
movb %r9b, 0x1(%rdx)
shrl %edi
incq %rax
cmpl $0x1, %esi
movl %edi, %esi
ja 0xa6f6
leal -0x1001(%r12), %esi
cmpl $-0x3, %esi
jg 0xa74a
movl $0xfff, %edi            # imm = 0xFFF
subl %r12d, %edi
xorl %esi, %esi
movb 0x1(%rdx), %r8b
movb %r8b, (%rcx,%rsi)
cmpq %r13, %rdx
jb 0xa746
incq %rsi
decq %rdx
cmpq %rsi, %rdi
jne 0xa72e
movl %esi, %edx
jmp 0xa74c
xorl %edx, %edx
movb $0x0, 0x1(%rcx,%rdx)
movq %rax, %r12
jmp 0xa87c
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 0x93a8(%rip), %rdx      # 0x13b2b
jmp 0xa870
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 0x92df(%rip), %rdx      # 0x13a92
xorl %eax, %eax
callq 0x10e0
jmp 0xa877
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 0x9345(%rip), %rdx      # 0x13b2e
jmp 0xa870
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 0x9310(%rip), %rdx      # 0x13b28
jmp 0xa870
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 0x930d(%rip), %rdx      # 0x13b51
jmp 0xa870
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 0x98d2(%rip), %rdx      # 0x14142
xorl %eax, %eax
callq 0x10e0
cltq
addq %rax, %r12
cmpq $0xfff, %r12            # imm = 0xFFF
jae 0xa94a
incq %rbp
movq %r14, %rdi
callq 0x10b0
movq %rax, %rcx
decq %rcx
movq %rbp, %r15
cmpq %rcx, %rbp
jb 0xa464
jmp 0xa42b
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0xa8d5
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0xa8e3
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 0x16c6
cltq
addq %rax, %r12
jmp 0xa4c1
movsbl %cl, %ecx
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x922d(%rip), %rdx      # 0x13b54
jmp 0xa943
leaq (%rsp,%r12), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1000, %esi           # imm = 0x1000
subq %r12, %rsi
leaq 0x91ee(%rip), %rdx      # 0x13b31
xorl %eax, %eax
callq 0x10e0
leaq 0x111f(%rsp), %rax
movb $0x0, (%rax)
leaq 0x120(%rsp), %rsi
movl %ebx, %edi
callq *0xf913(%rip)           # 0x1a278
addq $0x1128, %rsp           # imm = 0x1128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop