// File: /workspace/github_c_makefile_star2_O2/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 0x9320(%rip), %eax      # 0x109b8
testq %rax, %rax
je 0x77b6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebp
movl 0x92fd(%rip), %edx      # 0x109b4
leaq 0x9302(%rip), %r13      # 0x109c0
leaq (%rax,%r13), %rcx
decq %rcx
movq %rdx, %r12
decl %edx
xorl %ebx, %ebx
movq %rax, %rsi
addq %rbx, %rsi
je 0x7771
movzbl (%rcx,%rbx), %esi
cmpl $0x81, %esi
je 0x76e9
cmpl $0x20, %esi
jne 0x76f7
leal (%rdx,%rbx), %esi
movl %esi, 0x92c2(%rip)      # 0x109b4
decq %rbx
jmp 0x76cc
addl %ebx, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x92ae(%rip)      # 0x109b0
movb $0x0, (%rax,%r13)
sete %cl
movl %ecx, 0x92a0(%rip)      # 0x109b0
leaq 0x6c1d(%rip), %rax      # 0xe334
movl (%rax), %r14d
movl %r12d, %r15d
negl %r15d
addq %r14, %r15
subq %rbx, %r15
movl 0x928f(%rip), %r8d      # 0x109bc
leal -0x1(%r8), %eax
testl %r15d, %r15d
setle %dil
movl %eax, 0xc(%rsp)
testl %eax, %eax
setle %al
leaq 0x6c1c(%rip), %rcx      # 0xe364
cmpl $0x0, (%rcx)
setne %dl
leaq 0x6bbf(%rip), %rcx      # 0xe314
movl (%rcx), %ecx
cmpl $0x6c, %ecx
sete %sil
orb %dl, %sil
je 0x77b7
leaq 0x9256(%rip), %rdi      # 0x109c0
xorl %esi, %esi
callq 0x711c
movq 0x6848(%rip), %rax      # 0xdfc0
movq (%rax), %rsi
pushq $0xa
popq %rdi
callq 0x40d0
leaq 0x6bae(%rip), %rax      # 0xe338
incl (%rax)
andl $0x0, 0x9221(%rip)      # 0x109b4
andl $0x0, 0x921e(%rip)      # 0x109b8
andl $0x0, 0x921b(%rip)      # 0x109bc
movb $0x0, 0x9218(%rip)      # 0x109c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x63, %ecx
je 0x77e2
cmpl $0x72, %ecx
jne 0x7805
addq %rbx, %r12
movq 0x67f5(%rip), %rbx      # 0xdfc0
pushq $0x20
popq %rbp
cmpl %r14d, %r12d
je 0x7763
movq (%rbx), %rsi
movl %ebp, %edi
callq 0x40d0
decl %r14d
jmp 0x77ce
sarl %r15d
movq 0x67d4(%rip), %r14      # 0xdfc0
pushq $0x20
popq %rbx
subl $0x1, %r15d
jb 0x7763
movq (%r14), %rsi
movl %ebx, %edi
callq 0x40d0
jmp 0x77ef
orb %al, %dil
movb %dil, 0xb(%rsp)
movq %r8, %r15
callq 0x7246
addl %r15d, %r14d
notl %r12d
addl %r14d, %r12d
subl %ebx, %r12d
movq %r12, 0x10(%rsp)
testl %ebp, %ebp
sete %al
orb 0xb(%rsp), %al
movb %al, 0xb(%rsp)
movq 0x6786(%rip), %rbp      # 0xdfc0
leaq 0x25cb(%rip), %r14      # 0x9e0c
pushq $0x20
popq %r15
xorl %ebx, %ebx
movl %ebx, %eax
movzbl (%rax,%r13), %r12d
leal -0x80(%r12), %eax
cmpl $0x8, %eax
ja 0x786b
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movl %r12d, %edi
callq 0x6f02
jmp 0x78e5
testl %r12d, %r12d
je 0x7771
leaq 0x6afd(%rip), %rax      # 0xe378
cmpl $0x1, 0x20(%rax)
jne 0x78c9
leaq 0x6a98(%rip), %rax      # 0xe320
movl (%rax), %eax
cmpl $0x84, %eax
jne 0x78b2
movq (%rbp), %rsi
movl %r12d, %edi
callq 0x40d0
movq (%rbp), %rsi
pushq $0x8
popq %rdi
callq 0x40d0
leaq 0x6a70(%rip), %rax      # 0xe320
movl (%rax), %eax
cmpl $0x85, %eax
jne 0x78c9
movq (%rbp), %rsi
leaq 0x256c(%rip), %rdi      # 0x9e30
callq 0x40b0
movq (%rbp), %rsi
movl %r12d, %edi
jmp 0x78e0
cmpb $0x0, 0xb(%rsp)
je 0x78ec
movq (%rbp), %rsi
movl %r15d, %edi
callq 0x40d0
incl %ebx
jmp 0x7847
cmpl $0x0, 0x90bd(%rip)      # 0x109b0
je 0x7906
movq 0x10(%rsp), %rcx
movl %ecx, %eax
cltd
idivl 0xc(%rsp)
movl %eax, %r12d
jmp 0x7919
movq 0x10(%rsp), %rcx
leal -0x1(%rcx), %eax
cltd
idivl 0xc(%rsp)
movl %eax, %r12d
incl %r12d
subl %r12d, %ecx
movq %rcx, 0x10(%rsp)
testl %r12d, %r12d
movl $0x0, %eax
cmovlel %eax, %r12d
subl $0x1, %r12d
jb 0x7941
movq (%rbp), %rsi
movl %r15d, %edi
callq 0x40d0
jmp 0x792d
decl 0xc(%rsp)
jmp 0x78e5