// File: /workspace/github_c_makefile_star2_O1/ksherlock[P]nroff_man/render.c
// Function: flush
void flush(unsigned justify) {
	unsigned i;
	int padding;
	int holes;


	/* removing trailing whitespace. */
	i = buffer_offset;
	if (!i) return;
	while (i) {
		uint_fast8_t c;
		c = buffer[i-1];
		if (c == ' ' || c == XSPACE ){ --i; --buffer_width; }
		else break;
	}
	if (!i) goto exit;
	buffer[i] = 0;


	buffer_flip_flop = !buffer_flip_flop;
	padding = width - buffer_width;
	holes = buffer_words - 1;
	if (padding <= 0 || holes <= 0) justify = 0;


	if (na || ad == 'l') {
		print(buffer, 0);
		goto exit;
	}
	if (ad == 'r') {
		while(padding--) fputc(' ', stdout);
		print(buffer, 0);
		goto exit;
	}
	if (ad == 'c') {
		/* if (buffer_flip_flop) ++padding; */
		padding >>= 1;
		while(padding--) fputc(' ', stdout);
		print(buffer, 0);
		goto exit;
	}

	/* indent. */
	indent();
	padding += holes;

	for (i = 0; ; ++i) {
		uint_fast8_t c = buffer[i];
		if (c == 0) break;
		switch(c) {
			case XSPACE:
				if (justify) {
					int j;
					int fudge;
					/* taken from rosenkrantz nroff
					 * which was taken from Software Tools
					 * which was taken from Doug McIlroy's BCPL roff.
					 */
					if (buffer_flip_flop) 
						fudge = padding / holes;
					else
						fudge = (padding - 1) / holes + 1;

					padding -= fudge;
					holes -= 1;
					for (j = 0; j < fudge; ++j) fputc(' ', stdout);


				} else fputc(' ', stdout);
				break;

			case FONT_R: case FONT_B: case FONT_I: case FONT_P: case FONT_X:
				set_font(c);
				break;
			case HYPHEN: case ZWSPACE: break;
			case NBSPACE: fputc(' ', stdout); break;
			default:
				if (flags.T == FMT_ASCII) {
					if (ft == FONT_B) {
						fputc(c, stdout);
						fputc(8, stdout);
					}
					if (ft == FONT_I) {
						fputs("_\x08", stdout);
					}
				}
				fputc(c, stdout);
				break;
		}
	}


exit:
	fputc('\n', stdout); ++line;

	buffer_width = 0;
	buffer_offset = 0;
	buffer_words = 0;
	buffer[0] = 0;
	return;

}

// Assembly:
movl 0x8b40(%rip), %edx      # 0x109b8
testl %edx, %edx
je 0x7f8e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebp
movl 0x8b21(%rip), %eax      # 0x109b4
leaq 0x8b26(%rip), %r12      # 0x109c0
testl %edx, %edx
je 0x7ecd
leal -0x1(%rdx), %ecx
movzbl (%rcx,%r12), %esi
cmpl $0x81, %esi
je 0x7eb3
cmpl $0x20, %esi
jne 0x7ec0
decl %eax
movl %eax, 0x8af9(%rip)      # 0x109b4
movb $0x1, %sil
jmp 0x7ec4
xorl %esi, %esi
movl %edx, %ecx
movl %ecx, %edx
testb %sil, %sil
jne 0x7e9a
jmp 0x7ecf
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x7f48
movl %ecx, %eax
movb $0x0, (%rax,%r12)
xorl %eax, %eax
cmpl $0x0, 0x8acd(%rip)      # 0x109b0
sete %al
movl %eax, 0x8ac4(%rip)      # 0x109b0
leaq 0x6441(%rip), %rax      # 0xe334
movl (%rax), %eax
movl 0x8ab8(%rip), %r14d     # 0x109b4
movl %eax, %ebx
subl %r14d, %ebx
movl 0x8ab4(%rip), %r13d     # 0x109bc
decl %r13d
testl %ebx, %ebx
setle %r15b
testl %r13d, %r13d
setle %cl
leaq 0x6446(%rip), %rdx      # 0xe364
cmpl $0x0, (%rdx)
setne %sil
leaq 0x63e8(%rip), %rdx      # 0xe314
movl (%rdx), %edx
cmpl $0x6c, %edx
sete %dil
orb %sil, %dil
je 0x7f8f
leaq 0x8a7f(%rip), %rdi      # 0x109c0
xorl %esi, %esi
callq 0x7836
movq 0x6071(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x40e0
leaq 0x63d5(%rip), %rax      # 0xe338
incl (%rax)
xorl %eax, %eax
movl %eax, 0x8a47(%rip)      # 0x109b4
movl %eax, 0x8a45(%rip)      # 0x109b8
movl %eax, 0x8a43(%rip)      # 0x109bc
movb $0x0, 0x8a40(%rip)      # 0x109c0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x63, %edx
je 0x7fbe
cmpl $0x72, %edx
jne 0x7fe6
testl %ebx, %ebx
je 0x7f3a
subl %eax, %r14d
movq 0x6019(%rip), %rbx      # 0xdfc0
movq (%rbx), %rsi
movl $0x20, %edi
callq 0x40e0
incl %r14d
jne 0x7fa7
jmp 0x7f3a
cmpl $0x2, %ebx
jb 0x7f3a
sarl %ebx
movq 0x5ff0(%rip), %r14      # 0xdfc0
movq (%r14), %rsi
movl $0x20, %edi
callq 0x40e0
decl %ebx
jne 0x7fd0
jmp 0x7f3a
orb %cl, %r15b
callq 0x797e
movl %r13d, 0x4(%rsp)
addl %r13d, %ebx
testl %ebp, %ebp
sete %bpl
orb %r15b, %bpl
xorl %r14d, %r14d
leaq 0x1e13(%rip), %r13      # 0x9e1c
movb %bpl, 0x3(%rsp)
movl %r14d, %eax
movzbl (%rax,%r12), %r15d
leal -0x80(%r15), %eax
cmpl $0x8, %eax
ja 0x8036
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl %r15d, %edi
callq 0x761c
jmp 0x80d6
testl %r15d, %r15d
jne 0x805d
xorl %r15d, %r15d
jmp 0x80d9
testb %bpl, %bpl
je 0x80ea
movq 0x5f6d(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl $0x20, %edi
jmp 0x80d1
leaq 0x6314(%rip), %rax      # 0xe378
cmpl $0x1, 0x20(%rax)
jne 0x80c4
leaq 0x62af(%rip), %rax      # 0xe320
cmpl $0x84, (%rax)
jne 0x809f
movq 0x5f40(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl %r15d, %edi
callq 0x40e0
movq 0x5f2e(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl $0x8, %edi
callq 0x40e0
leaq 0x627a(%rip), %rax      # 0xe320
cmpl $0x85, (%rax)
jne 0x80c4
movq 0x5f0b(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
leaq 0x1d81(%rip), %rdi      # 0x9e40
callq 0x40c0
movq 0x5ef5(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl %r15d, %edi
callq 0x40e0
movb $0x1, %r15b
incl %r14d
testb %r15b, %r15b
jne 0x800e
jmp 0x7f48
cmpl $0x0, 0x88bf(%rip)      # 0x109b0
je 0x8100
movl %ebx, %eax
cltd
movl 0x4(%rsp), %ecx
idivl %ecx
movl %eax, %ebp
jmp 0x810e
leal -0x1(%rbx), %eax
cltd
movl 0x4(%rsp), %ecx
idivl %ecx
movl %eax, %ebp
incl %ebp
subl %ebp, %ebx
decl %ecx
movl %ecx, 0x4(%rsp)
movb $0x1, %r15b
testl %ebp, %ebp
jle 0x8135
movq 0x5e9c(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl $0x20, %edi
callq 0x40e0
decl %ebp
jne 0x811d
movb 0x3(%rsp), %bpl
jmp 0x80d9