// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/logger.c
// Function: LOGGER_clean_output
int LOGGER_clean_output( char *string, char **buffer )
{
	char *newstr;
	char *p, *q;
	char *next_space;

	int pc;
	int slen = strlen( string );
	int line_size;
	int maxsize = slen *2;

	// First up, allocate maxsize bytes for a temporary new string.
	newstr = malloc(slen *2 +1); 
	if ( newstr == NULL )
	{
		// FIXME - Report an error here ... to -somewhere-
		return -1;
	}

	p = newstr;
	q = string;
	pc = 0;
	line_size = 0;

	while (slen--)
	{

		// Do we need to apply any wrapping to the output? If so then we
		//		shall embark on a journey of strange space and distance
		//		evaluations to determine if we should wrap now or later

		if ( LOGGER_glb.wrap > 0 )
		{
			if (isspace((int)*q))
			{
				next_space = strpbrk( (q+1), "\t\r\n\v " );
				if (next_space != NULL)
				{
					if ((line_size +(next_space -q)) >= LOGGER_glb.wraplength)
					{
						*p = '\n';
						p++;
						pc++;
						line_size = 0;
					}
				}
			}

			if ( line_size >= LOGGER_glb.wraplength )
			{
				*p = '\n';
				p++;
				pc++;
				line_size = 0;
			}
		}

		// If the string has a % in it, then we need to encode it as
		//	a DOUBLE % symbol.

		if (*q == '%') {
//			if (strchr("fdlsxXn",*(q+1)))
//			{
				*p = '%';
				p++;
				pc++;
//			}
		}

		// Copy the character of the string in
		*p = *q;

		// Move everything along.
		q++;
		p++;
		pc++;
		line_size++;

		if ( pc > (maxsize -1) ) {
			break;
		}
	}

	*p = '\0';

	// This will have to be deallocated later!
	if (newstr) *buffer = newstr;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2100
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
shll %eax
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x2290
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1162b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x117b0
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x40(%rbp)
cmpl $0x0, %eax
je 0x11790
cmpl $0x0, 0x242c4(%rip)     # 0x35928
jle 0x1171e
callq 0x23c0
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x116ee
movq -0x30(%rbp), %rdi
addq $0x1, %rdi
leaq 0xd429(%rip), %rsi      # 0x1eac2
callq 0x22e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x116ec
movslq -0x44(%rbp), %rax
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movslq 0x2426a(%rip), %rcx     # 0x3592c
cmpq %rcx, %rax
jl 0x116ea
movq -0x28(%rbp), %rax
movb $0xa, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
jmp 0x116ec
jmp 0x116ee
movl -0x44(%rbp), %eax
cmpl 0x24235(%rip), %eax     # 0x3592c
jl 0x1171c
movq -0x28(%rbp), %rax
movb $0xa, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
jmp 0x1171e
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x11746
movq -0x28(%rbp), %rax
movb $0x25, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movb (%rax), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
movl -0x48(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x1178b
jmp 0x11790
jmp 0x11649
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x117a9
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)