// File: /workspace/github_c_makefile_star2_O3/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 0x8db5(%rip), %eax      # 0x109b8
testq %rax, %rax
je 0x7d21
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebp
movl 0x8d92(%rip), %edx      # 0x109b4
leaq 0x8d97(%rip), %r12      # 0x109c0
leaq (%rax,%r12), %rcx
decq %rcx
movq %rdx, %r13
decl %edx
xorl %ebx, %ebx
movzbl (%rcx,%rbx), %esi
cmpl $0x81, %esi
je 0x7c48
cmpl $0x20, %esi
jne 0x7c5e
leal (%rdx,%rbx), %esi
movl %esi, 0x8d63(%rip)      # 0x109b4
decq %rbx
movq %rax, %rsi
addq %rbx, %rsi
jne 0x7c37
jmp 0x7cdb
addl %ebx, %eax
movb $0x0, (%rax,%r12)
xorl %eax, %eax
cmpl $0x0, 0x8d42(%rip)      # 0x109b0
sete %al
movl %eax, 0x8d39(%rip)      # 0x109b0
leaq 0x66b6(%rip), %rax      # 0xe334
movl (%rax), %r14d
movq %r13, %rax
negl %eax
addq %r14, %rax
movq %rax, %r15
subq %rbx, %r15
movl 0x8d26(%rip), %r9d      # 0x109bc
leal -0x1(%r9), %ecx
testl %r15d, %r15d
setle %r8b
movl %ecx, 0xc(%rsp)
testl %ecx, %ecx
setle %cl
leaq 0x66b3(%rip), %rdx      # 0xe364
cmpl $0x0, (%rdx)
setne %sil
leaq 0x6655(%rip), %rdx      # 0xe314
movl (%rdx), %edx
cmpl $0x6c, %edx
sete %dil
orb %sil, %dil
je 0x7d22
leaq 0x8cec(%rip), %rdi      # 0x109c0
xorl %esi, %esi
callq 0x766e
movq 0x62de(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x40d0
leaq 0x6642(%rip), %rax      # 0xe338
incl (%rax)
xorl %eax, %eax
movl %eax, 0x8cb4(%rip)      # 0x109b4
movl %eax, 0x8cb2(%rip)      # 0x109b8
movl %eax, 0x8cb0(%rip)      # 0x109bc
movb $0x0, 0x8cad(%rip)      # 0x109c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x63, %edx
je 0x7d54
cmpl $0x72, %edx
jne 0x7d7f
cmpl %ebx, %eax
je 0x7ccd
addq %rbx, %r13
movq 0x6286(%rip), %rbx      # 0xdfc0
movq (%rbx), %rsi
movl $0x20, %edi
callq 0x40d0
decl %r14d
cmpl %r14d, %r13d
jne 0x7d3a
jmp 0x7ccd
cmpl $0x2, %r15d
jb 0x7ccd
sarl %r15d
movq 0x6258(%rip), %rbx      # 0xdfc0
movq (%rbx), %rsi
movl $0x20, %edi
callq 0x40d0
decl %r15d
jne 0x7d68
jmp 0x7ccd
orb %cl, %r8b
movb %r8b, 0xb(%rsp)
movq %r9, %r15
callq 0x77a3
addl %r15d, %r14d
notl %r13d
addl %r14d, %r13d
subl %ebx, %r13d
movq %r13, 0x10(%rsp)
testl %ebp, %ebp
sete %bpl
orb 0xb(%rsp), %bpl
xorl %r14d, %r14d
movq 0x620b(%rip), %r13      # 0xdfc0
leaq 0x2050(%rip), %rbx      # 0x9e0c
movl %r14d, %eax
movzbl (%rax,%r12), %r15d
leal -0x80(%r15), %eax
cmpl $0x8, %eax
ja 0x7de0
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movl %r15d, %edi
callq 0x7454
jmp 0x7e5c
testl %r15d, %r15d
je 0x7cdb
leaq 0x6588(%rip), %rax      # 0xe378
cmpl $0x1, 0x20(%rax)
jne 0x7e40
leaq 0x6523(%rip), %rax      # 0xe320
movl (%rax), %eax
cmpl $0x84, %eax
jne 0x7e29
movq (%r13), %rsi
movl %r15d, %edi
callq 0x40d0
movq (%r13), %rsi
movl $0x8, %edi
callq 0x40d0
leaq 0x64f9(%rip), %rax      # 0xe320
movl (%rax), %eax
cmpl $0x85, %eax
jne 0x7e40
movq (%r13), %rsi
leaq 0x1ff5(%rip), %rdi      # 0x9e30
callq 0x40b0
movq (%r13), %rsi
movl %r15d, %edi
jmp 0x7e57
testb %bpl, %bpl
je 0x7e64
movq (%r13), %rsi
movl $0x20, %edi
callq 0x40d0
incl %r14d
jmp 0x7dbc
movl %ebp, %r15d
cmpl $0x0, 0x8b42(%rip)      # 0x109b0
movq 0x10(%rsp), %rcx
je 0x7e82
movl %ecx, %eax
cltd
movl 0xc(%rsp), %esi
idivl %esi
movl %eax, %ebp
jmp 0x7e90
leal -0x1(%rcx), %eax
cltd
movl 0xc(%rsp), %esi
idivl %esi
movl %eax, %ebp
incl %ebp
subl %ebp, %ecx
decl %esi
testl %ebp, %ebp
movq %rcx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
jle 0x7eb3
movq (%r13), %rsi
movl $0x20, %edi
callq 0x40d0
decl %ebp
jne 0x7ea1
movl %r15d, %ebp
jmp 0x7e5c