// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-char.c
// Function: do_output_html_screen
static void do_output_html_screen(deark *c, struct de_char_context *charctx,
	struct charextractx *ectx, i64 screen_idx, dbuf *ofile)
{
	const struct de_char_cell *cell;
	struct de_char_cell blank_cell;
	struct de_char_screen *screen;
	int i, j;
	i32 n;
	int in_span = 0;
	int need_newline = 0;
	u32 active_fgcol = 0;
	u32 active_bgcol = 0;
	u8 active_underline = 0;
	u8 active_strikethru = 0;
	u8 active_blink = 0;
	int is_blank_char;
	struct span_info default_span;
	struct span_info cur_span;

	de_zeromem(&default_span, sizeof(struct span_info));
	de_zeromem(&cur_span, sizeof(struct span_info));

	screen = charctx->screens[screen_idx];

	// In case a cell is missing, we'll use this one:
	de_zeromem(&blank_cell, sizeof(struct de_char_cell));
	blank_cell.codepoint = 32;
	blank_cell.codepoint_unicode = 32;

	dbuf_puts(ofile, "<table class=mt><tr>\n<td>");
	dbuf_puts(ofile, "<pre>");

	// Containing <span> with default colors.
	default_span.fgcol = ectx->scrstats[screen_idx].most_used_fgcol;
	default_span.bgcol = ectx->scrstats[screen_idx].most_used_bgcol;
	span_open(c, ofile, &default_span, NULL);

	for(j=0; j<screen->height; j++) {
		for(i=0; i<screen->width; i++) {
			if(!screen->cell_rows || !screen->cell_rows[j]) {
				cell = &blank_cell;
			}
			else {
				cell = &screen->cell_rows[j][i];
				if(!cell) cell = &blank_cell;
			}

			n = cell->codepoint_unicode;

			if((cell->size_flags&DE_PAINTFLAG_RIGHTHALF) ||
				(cell->size_flags&DE_PAINTFLAG_BOTTOMHALF))
			{
				// We don't support double-size characters with HTML output.
				// Make the left / bottom parts of the cell blank so we don't
				// duplicate the foreground character.
				n = 0x20;
			}

			if(n==0x00) n=0x20;
			if(n<0x20) n='?';
			is_blank_char = (n==0x20 || n==0xa0) &&
				!cell->underline && !cell->strikethru;

			if(in_span) {
				// If we're in an incompatible 'span' context, close it.

				// Optimization: If this is a blank character, ignore a foreground color
				// mismatch, because it won't be visible anyway. (Many other similar
				// optimizations are also possible, but that could get very complex.)
				if((cell->fgcol!=active_fgcol && !is_blank_char) ||
					cell->bgcol!=active_bgcol ||
					cell->underline!=active_underline ||
					cell->strikethru!=active_strikethru ||
					cell->blink!=active_blink)
				{
					span_close(c, ofile, &cur_span);
					in_span=0;
				}
			}

			if(in_span==0) {
				if(need_newline) {
					dbuf_puts(ofile, "\n");
					need_newline = 0;
				}

				cur_span.fgcol = cell->fgcol;
				cur_span.bgcol = cell->bgcol;
				cur_span.underline = cell->underline;
				cur_span.strikethru = cell->strikethru;
				cur_span.blink = cell->blink;
				span_open(c, ofile, &cur_span, &ectx->scrstats[screen_idx]);

				in_span=1;
				active_fgcol = cell->fgcol;
				active_bgcol = cell->bgcol;
				active_underline = cell->underline;
				active_strikethru = cell->strikethru;
				active_blink = cell->blink;
			}

			if(need_newline) {
				dbuf_puts(ofile, "\n");
				need_newline = 0;
			}

			de_write_codepoint_to_html(c, ofile, n);
		}

		// Defer emitting a newline, so that we have more control over where
		// to put it. We prefer to put it after "</span>".
		need_newline = 1;
	}

	if(in_span) {
		span_close(c, ofile, &cur_span);
	}

	// Close containing <span>
	span_close(c, ofile, &default_span);

	dbuf_puts(ofile, "</pre>");
	dbuf_puts(ofile, "</td>\n</tr></table>\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movb $0x0, -0x6d(%rbp)
movb $0x0, -0x6e(%rbp)
movb $0x0, -0x6f(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x19140
leaq -0x8c(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x19140
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
leaq -0x44(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x19140
movl $0x20, -0x44(%rbp)
movl $0x20, -0x40(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x66bc1(%rip), %rsi     # 0x1d5788
callq 0x168da0
movq -0x28(%rbp), %rdi
leaq 0x66bcb(%rip), %rsi     # 0x1d57a2
callq 0x168da0
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x88, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x80(%rax), %eax
movl %eax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x88, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x84(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x80(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x16f310
movl $0x0, -0x58(%rbp)
movslq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x16eed0
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x16eebb
movq -0x50(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x16ec78
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x16ec82
leaq -0x44(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x16ecb2
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x16ecb0
leaq -0x44(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x16ecb2
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x30(%rbp), %rax
movzbl 0x13(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x16ecdc
movq -0x30(%rbp), %rax
movzbl 0x13(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x16ece3
movl $0x20, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x16ecf0
movl $0x20, -0x5c(%rbp)
cmpl $0x20, -0x5c(%rbp)
jge 0x16ecfd
movl $0x3f, -0x5c(%rbp)
cmpl $0x20, -0x5c(%rbp)
je 0x16ed14
xorl %eax, %eax
cmpl $0xa0, -0x5c(%rbp)
movb %al, -0x8d(%rbp)
jne 0x16ed39
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, 0x10(%rcx)
movb %al, -0x8d(%rbp)
jne 0x16ed39
movq -0x30(%rbp), %rax
cmpb $0x0, 0x11(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x8d(%rbp)
movb -0x8d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x16edb8
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x68(%rbp), %eax
je 0x16ed5f
cmpl $0x0, -0x74(%rbp)
je 0x16ed9b
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x6c(%rbp), %eax
jne 0x16ed9b
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
movzbl -0x6d(%rbp), %ecx
cmpl %ecx, %eax
jne 0x16ed9b
movq -0x30(%rbp), %rax
movzbl 0x11(%rax), %eax
movzbl -0x6e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x16ed9b
movq -0x30(%rbp), %rax
movzbl 0x12(%rax), %eax
movzbl -0x6f(%rbp), %ecx
cmpl %ecx, %eax
je 0x16edb6
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x8c(%rbp), %rdx
callq 0x16f6b0
movl $0x0, -0x60(%rbp)
jmp 0x16edb8
cmpl $0x0, -0x60(%rbp)
jne 0x16ee80
cmpl $0x0, -0x64(%rbp)
je 0x16eddf
movq -0x28(%rbp), %rdi
leaq 0x2d3b0(%rip), %rsi     # 0x19c183
callq 0x168da0
movl $0x0, -0x64(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movb 0x10(%rax), %al
movb %al, -0x84(%rbp)
movq -0x30(%rbp), %rax
movb 0x11(%rax), %al
movb %al, -0x83(%rbp)
movq -0x30(%rbp), %rax
movb 0x12(%rax), %al
movb %al, -0x82(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
imulq $0x88, -0x20(%rbp), %rax
addq %rax, %rcx
leaq -0x8c(%rbp), %rdx
callq 0x16f310
movl $0x1, -0x60(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x30(%rbp), %rax
movb 0x10(%rax), %al
movb %al, -0x6d(%rbp)
movq -0x30(%rbp), %rax
movb 0x11(%rax), %al
movb %al, -0x6e(%rbp)
movq -0x30(%rbp), %rax
movb 0x12(%rax), %al
movb %al, -0x6f(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x16ee9d
movq -0x28(%rbp), %rdi
leaq 0x2d2f2(%rip), %rsi     # 0x19c183
callq 0x168da0
movl $0x0, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x5c(%rbp), %edx
callq 0x161d10
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x16ec49
movl $0x1, -0x64(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x16ec30
cmpl $0x0, -0x60(%rbp)
je 0x16eeea
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x8c(%rbp), %rdx
callq 0x16f6b0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x16f6b0
movq -0x28(%rbp), %rdi
leaq 0x668a2(%rip), %rsi     # 0x1d57a8
callq 0x168da0
movq -0x28(%rbp), %rdi
leaq 0x66899(%rip), %rsi     # 0x1d57af
callq 0x168da0
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)