// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
cmpb $0x20, (%rdi)
jne 0x7b74
xorl %edi, %edi
callq 0x7e72
movl 0x8e3d(%rip), %r14d     # 0x109b8
xorl %r12d, %r12d
callq 0x41d0
leaq 0x8e36(%rip), %r10      # 0x109c0
movq %rcx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq (%rax), %rdx
movl %r12d, %ecx
movzbl (%rbx,%rcx), %ecx
incl %r12d
testb $0x20, 0x1(%rdx,%rcx,2)
jne 0x7b9c
testb %cl, %cl
je 0x7e5c
decl %r12d
xorl %r15d, %r15d
movl %r12d, %edi
movl %r12d, %ebp
movzbl (%rbx,%rbp), %r8d
testq %r8, %r8
je 0x7be8
movq 0x20(%rsp), %rax
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r8,2)
jne 0x7be8
cmpb $-0x7f, %r8b
adcl $0x0, %r15d
jmp 0x7e45
leaq 0x6745(%rip), %rax      # 0xe334
movl (%rax), %esi
movl 0x8dbd(%rip), %eax      # 0x109b4
leal (%rax,%r15), %ecx
cmpl %esi, %ecx
jbe 0x7d33
subl %eax, %esi
cmpl $0x3, %esi
movq %r8, 0x30(%rsp)
jl 0x7cae
leaq 0x6702(%rip), %rcx      # 0xe31c
cmpl $0x0, (%rcx)
je 0x7cae
movq %rdi, 0x8(%rsp)
movl %edi, %ecx
movq %rcx, 0x28(%rsp)
addq %rbx, %rcx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
xorl %r8d, %r8d
xorl %r10d, %r10d
movl %r9d, %r11d
movzbl (%rcx,%r11), %r11d
cmpq $0x20, %r11
ja 0x7c5e
movabsq $0x100000201, %rdx      # imm = 0x100000201
btq %r11, %rdx
jb 0x7c82
incl %r9d
cmpl $0x88, %r11d
je 0x7c7a
cmpb $-0x80, %r11b
ja 0x7c40
incl %r10d
cmpl %esi, %r10d
jb 0x7c40
jmp 0x7c82
movl %r9d, %edi
movl %r10d, %r8d
jmp 0x7c40
testl %r8d, %r8d
je 0x7c9a
xorl %esi, %esi
movl %r8d, %edx
movq %rdx, 0x18(%rsp)
movl %edi, %edx
movq %rdx, 0x10(%rsp)
jmp 0x7c9d
movb $0x1, %sil
leaq 0x8d1c(%rip), %r10      # 0x109c0
movq 0x8(%rsp), %rdi
testb %sil, %sil
je 0x7cb3
movl %edi, %r13d
jmp 0x7d0f
movq 0x10(%rsp), %rdx
addl %edi, %edx
cmpl %edx, %edi
jae 0x7ce6
movl %edx, %r11d
movl %edx, %esi
subq 0x28(%rsp), %rsi
movl %r14d, %edx
xorl %edi, %edi
leal (%rdx,%rdi), %r8d
movb (%rcx,%rdi), %r9b
movb %r9b, (%r8,%r10)
incq %rdi
cmpq %rdi, %rsi
jne 0x7ccd
addl %edi, %r14d
jmp 0x7ce9
movl %edx, %r11d
movl %r14d, %ecx
incl %r14d
movb $0x2d, (%rcx,%r10)
movq 0x18(%rsp), %rcx
addl %ecx, %eax
incl %eax
movl %eax, 0x8cb1(%rip)      # 0x109b4
incl 0x8cb3(%rip)            # 0x109bc
subl %ecx, %r15d
movl %r11d, %r13d
movl %r14d, 0x8ca2(%rip)     # 0x109b8
movl %r14d, %eax
movb $0x0, (%rax,%r10)
movl $0x1, %edi
callq 0x7e72
xorl %r14d, %r14d
movl %r13d, %edi
movq 0x30(%rsp), %r8
leaq 0x65fa(%rip), %rax      # 0xe334
cmpl (%rax), %r15d
jbe 0x7d64
movq %rdi, %rbp
xorl %r15d, %r15d
xorl %edi, %edi
leaq 0x20f5(%rip), %rsi      # 0x9e43
callq 0x41f0
movl $0x8, %eax
leaq 0x8c61(%rip), %r10      # 0x109c0
jmp 0x7e3d
cmpl %r12d, %edi
leaq 0x8c52(%rip), %r10      # 0x109c0
jae 0x7d93
movl %edi, %eax
movabsq $0x8000000000001a1, %rsi # imm = 0x8000000000001A1
movb (%rbx,%rax), %cl
movl %r14d, %edx
incl %r14d
movb %cl, (%rdx,%r10)
incq %rax
cmpq %rbp, %rax
jb 0x7d7c
jmp 0x7d9f
movl %edi, %eax
movabsq $0x8000000000001a1, %rsi # imm = 0x8000000000001A1
testq %r8, %r8
jne 0x7dff
cmpl $0x2, %eax
jb 0x7dff
decl %eax
je 0x7dd5
movl %eax, %eax
movzbl (%rbx,%rax), %ecx
leal -0x22(%rcx), %edx
cmpl $0x3b, %edx
ja 0x7dc1
btq %rdx, %rsi
jb 0x7dcc
addl $0xffffff7d, %ecx       # imm = 0xFFFFFF7D
cmpl $0x4, %ecx
jae 0x7dd5
decq %rax
testl %eax, %eax
jne 0x7daf
xorl %eax, %eax
movl %eax, %eax
movzbl (%rbx,%rax), %eax
cmpq $0x3f, %rax
ja 0x7dff
movabsq $-0x7fffbffe00000000, %rcx # imm = 0x8000400200000000
btq %rax, %rcx
jae 0x7dff
movl %r14d, %eax
incl %r14d
movb $0x20, (%rax,%r10)
incl %r15d
movq %rdi, %rbp
incl %r15d
addl %r15d, 0x8ba8(%rip)     # 0x109b4
incl 0x8baa(%rip)            # 0x109bc
movl %r14d, %eax
incl %r14d
movb $-0x7f, (%rax,%r10)
movb $0x0, (%r14,%r10)
testq %r8, %r8
je 0x7e31
xorl %r15d, %r15d
movl $0x6, %eax
jmp 0x7e3d
movl %r14d, 0x8b80(%rip)     # 0x109b8
movl $0x1, %eax
cmpl $0x8, %eax
jne 0x7e4d
movq %rbp, %rdi
incl %r12d
jmp 0x7bbe
cmpl $0x6, %eax
jne 0x7e63
movq 0x20(%rsp), %rax
jmp 0x7b99
movl %r14d, 0x8b55(%rip)     # 0x109b8
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq