// File: /workspace/github_c_makefile_star2_O2/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 0x7419
xorl %edi, %edi
callq 0x7692
movl 0x9598(%rip), %r13d     # 0x109b8
xorl %r12d, %r12d
callq 0x41c0
movq %rax, 0x10(%rsp)
leaq 0x958c(%rip), %r11      # 0x109c0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl %r12d, %ecx
movzbl (%rbx,%rcx), %r14d
incl %r12d
testb $0x20, 0x1(%rax,%r14,2)
jne 0x743c
testb %r14b, %r14b
je 0x767a
decl %r12d
xorl %r15d, %r15d
movl %r12d, %ebp
testb %r14b, %r14b
je 0x7486
movq 0x10(%rsp), %rax
movq (%rax), %rax
movzbl %r14b, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x7486
cmpb $-0x7f, %r14b
adcl $0x0, %r15d
jmp 0x75a3
leaq 0x6ea7(%rip), %rax      # 0xe334
movl (%rax), %ecx
movl 0x951f(%rip), %eax      # 0x109b4
leal (%rax,%r15), %edx
cmpl %ecx, %edx
jbe 0x7586
subl %eax, %ecx
cmpl $0x3, %ecx
jl 0x7519
leaq 0x6e6d(%rip), %rdx      # 0xe31c
cmpl $0x0, (%rdx)
je 0x7519
movl %ebp, 0x4(%rsp)
movl %ebp, %esi
leaq (%rbx,%rsi), %rdi
xorl %r8d, %r8d
pushq $-0x1
popq %rdx
movl %edx, %ebp
movq $0x0, 0x8(%rsp)
xorl %r9d, %r9d
movl %r8d, %r10d
movzbl (%rdi,%r10), %r10d
cmpq $0x20, %r10
ja 0x74f0
movabsq $0x100000201, %rdx      # imm = 0x100000201
btq %r10, %rdx
jb 0x751b
incl %r8d
cmpl $0x88, %r10d
je 0x750c
cmpb $-0x80, %r10b
ja 0x74d2
incl %r9d
cmpl %ecx, %r9d
jb 0x74d2
jmp 0x751b
movl %r8d, %ebp
movl %r9d, %edx
movq %rdx, 0x8(%rsp)
jmp 0x74d2
jmp 0x7563
movq 0x8(%rsp), %rdx
testl %edx, %edx
je 0x755d
addl 0x4(%rsp), %ebp
movl %r13d, %ecx
cmpq %rbp, %rsi
jae 0x7540
movb (%rbx,%rsi), %dil
incl %r13d
movb %dil, (%rcx,%r11)
incq %rsi
jmp 0x7528
incl %r13d
movb $0x2d, (%rcx,%r11)
addl %edx, %eax
incl %eax
movl %eax, 0x9462(%rip)      # 0x109b4
incl 0x9464(%rip)            # 0x109bc
subl %edx, %r15d
jmp 0x7563
movl 0x4(%rsp), %eax
movl %eax, %ebp
movl %r13d, 0x944e(%rip)     # 0x109b8
movl %r13d, %eax
movb $0x0, (%rax,%r11)
pushq $0x1
popq %rdi
callq 0x7692
leaq 0x6db3(%rip), %rax      # 0xe334
movl (%rax), %ecx
xorl %r13d, %r13d
cmpl %ecx, %r15d
jbe 0x75af
xorl %r15d, %r15d
xorl %edi, %edi
leaq 0x289c(%rip), %rsi      # 0x9e33
callq 0x4726
leaq 0x941d(%rip), %r11      # 0x109c0
incl %r12d
movb (%rbx,%r12), %r14b
jmp 0x7461
movl %r12d, %esi
movl %ebp, %edx
leaq -0x1(%rdx), %rcx
leaq 0x9401(%rip), %r11      # 0x109c0
movl %r13d, %eax
cmpq %rsi, %rdx
jae 0x75da
movb (%rbx,%rdx), %dil
incl %r13d
movb %dil, (%rax,%r11)
incq %rdx
incq %rcx
jmp 0x75bf
testb %r14b, %r14b
jne 0x7644
cmpq $0x2, %rdx
jb 0x7644
movq %rcx, %rsi
subq $0x1, %rsi
jb 0x761f
movb (%rbx,%rcx), %dl
movzbl %dl, %edi
leal -0x22(%rdi), %ecx
cmpl $0x3b, %ecx
ja 0x760f
movabsq $0x8000000000001a1, %r8 # imm = 0x8000000000001A1
btq %rcx, %r8
movq %rsi, %rcx
jb 0x75e5
addl $0xffffff7d, %edi       # imm = 0xFFFFFF7D
movq %rsi, %rcx
cmpl $0x4, %edi
jb 0x75e5
jmp 0x7621
movb (%rbx), %dl
cmpb $0x3f, %dl
ja 0x7644
movzbl %dl, %ecx
movabsq $-0x7fffbffe00000000, %rdx # imm = 0x8000400200000000
btq %rcx, %rdx
jae 0x7644
incl %r13d
movb $0x20, (%rax,%r11)
incl %r15d
leal 0x1(%r13), %eax
incl 0x936e(%rip)            # 0x109bc
movl %r13d, %ecx
movb $-0x7f, (%rcx,%r11)
movb $0x0, (%rax,%r11)
movl 0x9353(%rip), %ecx      # 0x109b4
addl %r15d, %ecx
incl %ecx
movl %ecx, 0x9348(%rip)      # 0x109b4
movl %eax, %r13d
testb %r14b, %r14b
jne 0x7434
jmp 0x767d
movl %r13d, %eax
movl %eax, 0x9335(%rip)      # 0x109b8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq