// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/src/deark-char.c
// Function: span_open
static void span_open(deark *c, dbuf *ofile, struct span_info *sp,
	const struct screen_stats *scrstats)
{
	int need_fgcol_attr, need_bgcol_attr;
	int need_underline, need_strikethru, need_blink;
	int attrindex = 0;
	int attrcount;
	int fgcol_is_24bit, bgcol_is_24bit;
	int need_style = 0;

	fgcol_is_24bit = !DE_IS_PAL_COLOR(sp->fgcol);
	bgcol_is_24bit = !DE_IS_PAL_COLOR(sp->bgcol);

	need_fgcol_attr = !scrstats || sp->fgcol!=scrstats->most_used_fgcol;
	need_bgcol_attr = !scrstats || sp->bgcol!=scrstats->most_used_bgcol;
	if(fgcol_is_24bit) { need_fgcol_attr=0; need_style=1; }
	if(bgcol_is_24bit) { need_bgcol_attr=0; need_style=1; }
	need_underline = (sp->underline!=0);
	need_strikethru = (sp->strikethru!=0);
	need_blink = (sp->blink!=0);

	attrcount = need_fgcol_attr + need_bgcol_attr + need_underline +
		need_strikethru + need_blink;
	if(attrcount==0 && !need_style) {
		sp->is_suppressed = 1;
		return;
	}

	sp->is_suppressed = 0;

	dbuf_puts(ofile, "<span");

	if(attrcount==0)
		goto no_class;

	dbuf_puts(ofile, " class=");
	if(attrcount>1) // Don't need quotes if there's only one attribute
		dbuf_puts(ofile, "\"");

	// Classes for foreground and background colors

	if(need_fgcol_attr) {
		dbuf_printf(ofile, "f%c", de_get_hexchar(sp->fgcol));
		attrindex++;
	}

	if(need_bgcol_attr) {
		if(attrindex) dbuf_puts(ofile, " ");
		dbuf_printf(ofile, "b%c", de_get_hexchar(sp->bgcol));
		attrindex++;
	}

	// Other attributes

	if(sp->underline) {
		if(attrindex) dbuf_puts(ofile, " ");
		dbuf_puts(ofile, "u");
		attrindex++;
	}
	if(sp->strikethru) {
		if(attrindex) dbuf_puts(ofile, " ");
		dbuf_puts(ofile, "s");
		attrindex++;
	}
	if(sp->blink) {
		if(attrindex) dbuf_puts(ofile, " ");
		dbuf_puts(ofile, "blink");
		attrindex++;
	}

	if(attrcount>1)
		dbuf_puts(ofile, "\"");

no_class:
	if(fgcol_is_24bit || bgcol_is_24bit) {
		char tmpbuf[16];

		dbuf_puts(ofile, " style=\"");
		if(fgcol_is_24bit) {
			de_color_to_css(sp->fgcol, tmpbuf, sizeof(tmpbuf));
			dbuf_printf(ofile, "color:%s", tmpbuf);
		}

		if(bgcol_is_24bit) {
			if(fgcol_is_24bit)
				dbuf_puts(ofile, ";");
			de_color_to_css(sp->bgcol, tmpbuf, sizeof(tmpbuf));
			dbuf_printf(ofile, "background-color:%s", tmpbuf);
		}
		dbuf_puts(ofile, "\"");
	}

	dbuf_puts(ofile, ">");
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl (%rsi), %r15d
movl 0x4(%rsi), %esi
testq %rdx, %rdx
je 0xf50eb
xorl %ebp, %ebp
cmpl 0x80(%rdx), %r15d
setne %bpl
xorl %r13d, %r13d
cmpl 0x84(%rdx), %esi
setne %r13b
jmp 0xf50f6
movl $0x1, %ebp
movl $0x1, %r13d
xorl %eax, %eax
cmpl $0x10, %r15d
setae %cl
cmovael %eax, %ebp
movl %esi, 0xc(%rsp)
cmpl $0x10, %esi
setae %dl
cmovael %eax, %r13d
orb %cl, %dl
leal (%r13,%rbp), %r12d
cmpb $0x1, 0x8(%r14)
sbbl $-0x1, %r12d
cmpb $0x1, 0x9(%r14)
sbbl $-0x1, %r12d
cmpb $0x1, 0xa(%r14)
movzbl %dl, %eax
sbbl $-0x1, %r12d
orl %r12d, %eax
je 0xf51b1
movb $0x0, 0xb(%r14)
leaq 0x54b46(%rip), %rsi     # 0x149c8c
movq %rbx, %rdi
callq 0xf10ed
testl %r12d, %r12d
je 0xf5265
leaq 0x54b34(%rip), %rsi     # 0x149c92
movq %rbx, %rdi
callq 0xf10ed
cmpl $0x1, %r12d
je 0xf517b
leaq 0x54b36(%rip), %rsi     # 0x149ca9
movq %rbx, %rdi
callq 0xf10ed
testl %ebp, %ebp
je 0xf51bb
movl (%r14), %edi
callq 0xebba8
movsbl %al, %edx
leaq 0x54b09(%rip), %rsi     # 0x149c9a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xf08da
testl %r13d, %r13d
je 0xf51e1
leaq 0x37b26(%rip), %rsi     # 0x12cccd
movq %rbx, %rdi
callq 0xf10ed
jmp 0xf51c4
movb $0x1, 0xb(%r14)
jmp 0xf5322
testl %r13d, %r13d
je 0xf5331
movl 0x4(%r14), %edi
callq 0xebba8
movsbl %al, %edx
leaq 0x54ac7(%rip), %rsi     # 0x149c9e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xf08da
cmpb $0x0, 0x8(%r14)
je 0xf5206
leaq 0x37ade(%rip), %rsi     # 0x12cccd
movq %rbx, %rdi
callq 0xf10ed
leaq 0x20277(%rip), %rsi     # 0x115475
movq %rbx, %rdi
callq 0xf10ed
cmpb $0x0, 0x9(%r14)
je 0xf522b
leaq 0x37ab9(%rip), %rsi     # 0x12cccd
movq %rbx, %rdi
callq 0xf10ed
leaq 0x1fb3d(%rip), %rsi     # 0x114d60
movq %rbx, %rdi
callq 0xf10ed
cmpb $0x0, 0xa(%r14)
je 0xf5250
leaq 0x37a94(%rip), %rsi     # 0x12cccd
movq %rbx, %rdi
callq 0xf10ed
leaq 0x1c95b(%rip), %rsi     # 0x111ba3
movq %rbx, %rdi
callq 0xf10ed
cmpl $0x1, %r12d
je 0xf5265
leaq 0x54a4c(%rip), %rsi     # 0x149ca9
movq %rbx, %rdi
callq 0xf10ed
movl 0xc(%rsp), %ebp
cmpl $0x10, %ebp
setae %al
cmpl $0x10, %r15d
setae %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xf5313
leaq 0x54a1a(%rip), %rsi     # 0x149ca2
movq %rbx, %rdi
callq 0xf10ed
cmpl $0x10, %r15d
jb 0xf52d5
movl (%r14), %edi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xec648
leaq 0x54a04(%rip), %rsi     # 0x149cb6
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xf08da
cmpl $0xf, %ebp
jbe 0xf5304
leaq 0x53a49(%rip), %rsi     # 0x148d14
movq %rbx, %rdi
callq 0xf10ed
jmp 0xf52da
cmpl $0xf, %ebp
jbe 0xf5304
movl 0x4(%r14), %edi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
movl $0x10, %edx
callq 0xec648
leaq 0x549b4(%rip), %rsi     # 0x149cab
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xf08da
leaq 0x5499e(%rip), %rsi     # 0x149ca9
movq %rbx, %rdi
callq 0xf10ed
leaq 0x5529f(%rip), %rsi     # 0x14a5b9
movq %rbx, %rdi
callq 0xf10ed
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x8(%r14)
jne 0xf51f7
cmpb $0x0, 0x9(%r14)
jne 0xf521c
cmpb $0x0, 0xa(%r14)
jne 0xf5241
jmp 0xf5250
nop