// File: /workspace/github_c_makefile_star2_O3/ksherlock[P]nroff_man/render.c
// Function: append
void append(const unsigned char *cp) {

	unsigned start, end;
	unsigned i, j, k;
	unsigned xlen;
	uint_fast8_t c;

	xlen = 0;
	i = 0;
	j = 0;

	if (cp[0] == ' ') flush(0);

	k = buffer_offset;

	for(;;) {
		while (isspace(cp[i])) ++i;
		if (cp[i] == 0) { buffer_offset = k; return; }
		start = i;
		xlen = 0;
		for(;;++i) {
			c = cp[i];
			if (c == 0 || isspace(c)) {
				int avail;
				end = i;
				/* xlen = printed size */
				/* if word ends w [.?!], should add 2 spaces...
				*/
				/* flush() depends on buffer_offset, etc */
				avail = width - buffer_width;

				/* todo -- also check if k + end - start + 1 > sizeof(buffer) */

				if (buffer_width + xlen > width) {

					/* try to hyphenate */
					if (hy && avail > 2) {
						int cookie[2];
						int ok;
						ok = hyphenate(cp + start, avail, cookie);
						if (ok) {
							unsigned xend;
							xend = start + cookie[0];

							for (j = start; j < xend; ++j)
								buffer[k++] = cp[j];
							buffer[k++] = '-';
							buffer_width += cookie[1] + 1;
							buffer_words++;

							xlen -= cookie[1];
							start = xend;
						}
					}

					buffer_offset = k;
					buffer[k] = 0;
					flush(1);
					k = 0;
				}
				
				if (xlen > width) {
					man_warnx("Word is too long.");
					xlen = 0;
					continue;
				}
				for (j = start; j < end; ++j)
					buffer[k++] = cp[j];

				if (c == 0 && j > 1) {
					/* if word ends w/ [.?!] should add extra space */
					if (is_sentence(cp, j)) {
						buffer[k++] = ' ';
						xlen++;
					}
				}

				buffer[k++] = XSPACE;
				buffer[k] = 0;
				xlen++; /* space */
				buffer_width += xlen;
				buffer_words++;

				if (c == 0) {
					buffer_offset = k;
					return;
				}
				xlen = 0;
				break;

			} else {
				if (c <= NBSPACE) xlen++;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpb $0x20, (%rdi)
jne 0x7970
xorl %edi, %edi
callq 0x7bfd
movl 0x9041(%rip), %r13d     # 0x109b8
xorl %ebp, %ebp
callq 0x41c0
movq %rax, (%rsp)
leaq 0x9037(%rip), %r11      # 0x109c0
movq %rbx, 0x10(%rsp)
movq (%rsp), %rax
movq (%rax), %rax
movl %ebp, %ecx
movzbl (%rbx,%rcx), %r14d
incl %ebp
testb $0x20, 0x1(%rax,%r14,2)
jne 0x7995
testb %r14b, %r14b
je 0x7be5
decl %ebp
xorl %r15d, %r15d
movl %ebp, %r12d
testb %r14b, %r14b
je 0x79db
movq (%rsp), %rax
movq (%rax), %rax
movzbl %r14b, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x79db
cmpb $-0x7f, %r14b
adcl $0x0, %r15d
jmp 0x7b09
leaq 0x6952(%rip), %rax      # 0xe334
movl (%rax), %esi
movl 0x8fca(%rip), %eax      # 0x109b4
leal (%rax,%r15), %ecx
cmpl %esi, %ecx
jbe 0x7aec
subl %eax, %esi
cmpl $0x3, %esi
jl 0x7abc
leaq 0x6914(%rip), %rcx      # 0xe31c
cmpl $0x0, (%rcx)
je 0x7abc
movl %r12d, %ecx
movq %rcx, 0x8(%rsp)
leaq (%rbx,%rcx), %rdx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
xorl %ecx, %ecx
xorl %r9d, %r9d
movl %r8d, %r10d
movzbl (%rdx,%r10), %r10d
cmpq $0x20, %r10
ja 0x7a48
movabsq $0x100000201, %rdi      # imm = 0x100000201
btq %r10, %rdi
jb 0x7a6c
incl %r8d
cmpl $0x88, %r10d
je 0x7a64
cmpb $-0x80, %r10b
ja 0x7a2a
incl %r9d
cmpl %esi, %r9d
jb 0x7a2a
jmp 0x7a6c
movl %r8d, %ebx
movl %r9d, %ecx
jmp 0x7a2a
testl %ecx, %ecx
je 0x7abc
addl %r12d, %ebx
cmpl %ebx, %r12d
jae 0x7a9c
movl %ebx, %esi
subq 0x8(%rsp), %rsi
movl %r13d, %edi
xorl %r8d, %r8d
leal (%rdi,%r8), %r9d
movb (%rdx,%r8), %r10b
movb %r10b, (%r9,%r11)
incq %r8
cmpq %r8, %rsi
jne 0x7a85
addl %r8d, %r13d
movl %r13d, %edx
incl %r13d
movb $0x2d, (%rdx,%r11)
addl %ecx, %eax
incl %eax
movl %eax, 0x8f03(%rip)      # 0x109b4
incl 0x8f05(%rip)            # 0x109bc
subl %ecx, %r15d
jmp 0x7abf
movl %r12d, %ebx
movl %r13d, 0x8ef2(%rip)     # 0x109b8
movl %r13d, %eax
movb $0x0, (%rax,%r11)
movl $0x1, %edi
callq 0x7bfd
leaq 0x6855(%rip), %rax      # 0xe334
movl (%rax), %esi
xorl %r13d, %r13d
movl %ebx, %r12d
movq 0x10(%rsp), %rbx
cmpl %esi, %r15d
jbe 0x7b14
xorl %r15d, %r15d
xorl %edi, %edi
leaq 0x2336(%rip), %rsi      # 0x9e33
callq 0x41e0
leaq 0x8eb7(%rip), %r11      # 0x109c0
incl %ebp
movb (%rbx,%rbp), %r14b
jmp 0x79b7
cmpl %ebp, %r12d
jae 0x7b3d
movl %ebp, %eax
movl %r12d, %r12d
leaq 0x8e9b(%rip), %r11      # 0x109c0
movb (%rbx,%r12), %cl
movl %r13d, %edx
incl %r13d
movb %cl, (%rdx,%r11)
incq %r12
cmpq %rax, %r12
jb 0x7b25
jmp 0x7b44
leaq 0x8e7c(%rip), %r11      # 0x109c0
testb %r14b, %r14b
jne 0x7baf
cmpl $0x2, %r12d
jb 0x7baf
decl %r12d
movzbl (%rbx,%r12), %eax
leal -0x22(%rax), %ecx
cmpl $0x3b, %ecx
ja 0x7b6f
movabsq $0x8000000000001a1, %rdx # imm = 0x8000000000001A1
btq %rcx, %rdx
jb 0x7b79
addl $0xffffff7d, %eax       # imm = 0xFFFFFF7D
cmpl $0x4, %eax
jae 0x7b84
decq %r12
testl %r12d, %r12d
jne 0x7b52
xorl %r12d, %r12d
movl %r12d, %eax
movzbl (%rbx,%rax), %eax
cmpq $0x3f, %rax
ja 0x7baf
movabsq $-0x7fffbffe00000000, %rcx # imm = 0x8000400200000000
btq %rax, %rcx
jae 0x7baf
movl %r13d, %eax
incl %r13d
movb $0x20, (%rax,%r11)
incl %r15d
leal 0x1(%r13), %eax
incl 0x8e03(%rip)            # 0x109bc
movl %r13d, %ecx
movb $-0x7f, (%rcx,%r11)
movb $0x0, (%rax,%r11)
movl 0x8de8(%rip), %ecx      # 0x109b4
addl %r15d, %ecx
incl %ecx
movl %ecx, 0x8ddd(%rip)      # 0x109b4
movl %eax, %r13d
testb %r14b, %r14b
jne 0x798e
jmp 0x7be8
movl %r13d, %eax
movl %eax, 0x8dca(%rip)      # 0x109b8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq