// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/wri.c
// Function: do_text_paragraph
static void do_text_paragraph(deark *c, lctx *d, struct para_info *pinfo)
{
	i64 i, k;

	if(!d->html_outf) return;

	if((pinfo->papflags & 0x06)!=0) {
		// TODO: Decode headers and footers somehow.
		do_emit_raw_sz(c, d, pinfo, "<p class=r>");
		do_emit_raw_sz(c, d, pinfo, (pinfo->papflags&0x01)?"footer":"header");
		do_emit_raw_sz(c, d, pinfo, " definition</p>\n");
		return;
	}

	pinfo->in_para = 0;
	pinfo->xpos = 0;
	pinfo->space_count = 0;
	pinfo->has_content = 0;
	pinfo->in_span = 0;
	default_text_styles(&pinfo->text_styles_wanted);
	default_text_styles(&pinfo->text_styles_current);

	for(i=0; i<pinfo->thisparalen; i++) {
		u8 incp;

		incp = de_getbyte(pinfo->thisparapos+i);
		if(incp==0x0d && i<pinfo->thisparalen-1) {
			if(de_getbyte(pinfo->thisparapos+i+1)==0x0a) {
				// Found CR-LF combo
				i++;
				ensure_in_para(c, d, pinfo);
				end_para(c, d, pinfo);
				continue;
			}
		}

		if(incp!=32 && pinfo->space_count>0) {
			int nonbreaking_count, breaking_count;

			if(!pinfo->in_para && pinfo->space_count==1) {
				// If the paragraph starts with a single space, make it nonbreaking.
				nonbreaking_count = 1;
				breaking_count = 0;
			}
			else {
				// Else make all spaces but the last one nonbreaking
				nonbreaking_count = pinfo->space_count-1;
				breaking_count = 1;
			}

			ensure_in_para(c, d, pinfo);

			for(k=0; k<nonbreaking_count; k++) {
				do_emit_codepoint(c, d, pinfo, 0xa0);
			}

			if(breaking_count>0) {
				if(pinfo->xpos>70) {
					// We don't do proper word wrapping of the HTML source, but
					// maybe this is better than nothing.
					do_emit_raw_sz(c, d, pinfo, "\n");
				}
				else {
					do_emit_codepoint(c, d, pinfo, 32);
				}
			}

			pinfo->space_count=0;
		}

		if(incp>=33) {
			i32 outcp;

			// TODO: Decide if we ought to support multi-code-unit encodings
			// like UTF-8.
			outcp = de_char_to_unicode_ex((i32)incp, &d->es);
			do_emit_codepoint(c, d, pinfo, outcp);
		}
		else {
			switch(incp) {
			case 9: // tab
				pinfo->text_styles_wanted.tab_style = 1;
				do_emit_codepoint(c, d, pinfo, 0x2192);
				pinfo->text_styles_wanted.tab_style = 0;
				break;
			case 10:
			case 11:
				ensure_in_para(c, d, pinfo);
				do_emit_raw_sz(c, d, pinfo, "<br>\n");
				pinfo->has_content = 1;
				break;
			case 12: // page break
				end_para(c, d, pinfo);
				do_emit_raw_sz(c, d, pinfo, "<hr>\n");
				break;
			case 31:
				break;
			case 32:
				pinfo->space_count++;
				break;
			default:
				do_emit_codepoint(c, d, pinfo, 0xfffd);
			}
		}
	}

	end_para(c, d, pinfo);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jne 0x13cc04
jmp 0x13cfa0
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
andl $0x6, %eax
cmpl $0x0, %eax
je 0x13cc7d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x90a2b(%rip), %rcx     # 0x1cd652
callq 0x13d600
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %r8d
andl $0x1, %r8d
leaq 0x64b04(%rip), %rcx     # 0x1a1750
leaq 0x7fab3(%rip), %rax     # 0x1bc706
cmpl $0x0, %r8d
cmovneq %rax, %rcx
callq 0x13d600
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x90b49(%rip), %rcx     # 0x1cd7bc
callq 0x13d600
jmp 0x13cfa0
movq -0x18(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x24(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
callq 0x13da20
movq -0x18(%rbp), %rdi
addq $0x31, %rdi
callq 0x13da20
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x13cf8f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
addq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0xd, %eax
jne 0x13cd7a
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x13cd7a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
addq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x165060
movzbl %al, %eax
cmpl $0xa, %eax
jne 0x13cd78
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x13d900
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x13d6f0
jmp 0x13cf7e
jmp 0x13cd7a
movzbl -0x29(%rbp), %eax
cmpl $0x20, %eax
je 0x13ce64
movq -0x18(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jle 0x13ce64
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x13cdb9
movq -0x18(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jne 0x13cdb9
movl $0x1, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x13cdcd
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x13d900
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jge 0x13ce17
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl $0xa0, %ecx
callq 0x13d800
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x13cde6
cmpl $0x0, -0x34(%rbp)
jle 0x13ce59
movq -0x18(%rbp), %rax
cmpl $0x46, 0x20(%rax)
jle 0x13ce41
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x5f349(%rip), %rcx     # 0x19c183
callq 0x13d600
jmp 0x13ce57
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl $0x20, %ecx
callq 0x13d800
jmp 0x13ce59
movq -0x18(%rbp), %rax
movl $0x0, 0x28(%rax)
movzbl -0x29(%rbp), %eax
cmpl $0x21, %eax
jl 0x13ce9d
movzbl -0x29(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x80, %rsi
callq 0x160a30
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x38(%rbp), %ecx
callq 0x13d800
jmp 0x13cf7c
movzbl -0x29(%rbp), %eax
addl $-0x9, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x17, %eax
ja 0x13cf64
movq -0x40(%rbp), %rax
leaq 0x902ca(%rip), %rcx     # 0x1cd188
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movb $0x1, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl $0x2192, %ecx           # imm = 0x2192
callq 0x13d800
movq -0x18(%rbp), %rax
movb $0x0, 0x30(%rax)
jmp 0x13cf7a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x13d900
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x908b7(%rip), %rcx     # 0x1cd7cd
callq 0x13d600
movq -0x18(%rbp), %rax
movl $0x1, 0x24(%rax)
jmp 0x13cf7a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x13d6f0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x90887(%rip), %rcx     # 0x1cd7d3
callq 0x13d600
jmp 0x13cf7a
jmp 0x13cf7a
movq -0x18(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
jmp 0x13cf7a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl $0xfffd, %ecx           # imm = 0xFFFD
callq 0x13d800
jmp 0x13cf7c
jmp 0x13cf7e
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x13ccd6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x13d6f0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)