// File: /workspace/github_c_makefile_star2_O2/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 0xe9aa1
xorl %r13d, %r13d
cmpl 0x80(%rdx), %r15d
setne %r13b
xorl %ebp, %ebp
cmpl 0x84(%rdx), %esi
setne %bpl
jmp 0xe9aa8
pushq $0x1
popq %r13
movl %r13d, %ebp
xorl %eax, %eax
cmpl $0x10, %r15d
setae %cl
cmovael %eax, %r13d
movl %esi, 0xc(%rsp)
cmpl $0x10, %esi
setae %dl
cmovael %eax, %ebp
orb %cl, %dl
leal (%rbp,%r13), %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 0xe9b63
movb $0x0, 0xb(%r14)
leaq 0x52cc4(%rip), %rsi     # 0x13c7bc
movq %rbx, %rdi
callq 0xe5fe4
testl %r12d, %r12d
je 0xe9c16
leaq 0x52cb2(%rip), %rsi     # 0x13c7c2
movq %rbx, %rdi
callq 0xe5fe4
cmpl $0x1, %r12d
je 0xe9b2d
leaq 0x52cb4(%rip), %rsi     # 0x13c7d9
movq %rbx, %rdi
callq 0xe5fe4
testl %r13d, %r13d
je 0xe9b6d
movl (%r14), %edi
callq 0xe11b0
movsbl %al, %edx
leaq 0x52c86(%rip), %rsi     # 0x13c7ca
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe5905
testl %ebp, %ebp
je 0xe9b92
leaq 0x35f04(%rip), %rsi     # 0x11fa5d
movq %rbx, %rdi
callq 0xe5fe4
jmp 0xe9b75
movb $0x1, 0xb(%r14)
jmp 0xe9ccf
testl %ebp, %ebp
je 0xe9cde
movl 0x4(%r14), %edi
callq 0xe11b0
movsbl %al, %edx
leaq 0x52c46(%rip), %rsi     # 0x13c7ce
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe5905
cmpb $0x0, 0x8(%r14)
je 0xe9bb7
leaq 0x35ebd(%rip), %rsi     # 0x11fa5d
movq %rbx, %rdi
callq 0xe5fe4
leaq 0x1e836(%rip), %rsi     # 0x1083e5
movq %rbx, %rdi
callq 0xe5fe4
cmpb $0x0, 0x9(%r14)
je 0xe9bdc
leaq 0x35e98(%rip), %rsi     # 0x11fa5d
movq %rbx, %rdi
callq 0xe5fe4
leaq 0x1e12c(%rip), %rsi     # 0x107d00
movq %rbx, %rdi
callq 0xe5fe4
cmpb $0x0, 0xa(%r14)
je 0xe9c01
leaq 0x35e73(%rip), %rsi     # 0x11fa5d
movq %rbx, %rdi
callq 0xe5fe4
leaq 0x1af8a(%rip), %rsi     # 0x104b83
movq %rbx, %rdi
callq 0xe5fe4
cmpl $0x1, %r12d
je 0xe9c16
leaq 0x52bcb(%rip), %rsi     # 0x13c7d9
movq %rbx, %rdi
callq 0xe5fe4
movl 0xc(%rsp), %ebp
cmpl $0x10, %ebp
setae %al
cmpl $0x10, %r15d
setae %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xe9cc0
leaq 0x52b99(%rip), %rsi     # 0x13c7d2
movq %rbx, %rdi
callq 0xe5fe4
cmpl $0x10, %r15d
jb 0xe9c84
movl (%r14), %edi
leaq 0x10(%rsp), %r15
pushq $0x10
popq %rdx
movq %r15, %rsi
callq 0xe1be6
leaq 0x52b85(%rip), %rsi     # 0x13c7e6
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe5905
cmpl $0xf, %ebp
jbe 0xe9cb1
leaq 0x51bca(%rip), %rsi     # 0x13b844
movq %rbx, %rdi
callq 0xe5fe4
jmp 0xe9c89
cmpl $0xf, %ebp
jbe 0xe9cb1
movl 0x4(%r14), %edi
leaq 0x10(%rsp), %r14
pushq $0x10
popq %rdx
movq %r14, %rsi
callq 0xe1be6
leaq 0x52b37(%rip), %rsi     # 0x13c7db
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xe5905
leaq 0x52b21(%rip), %rsi     # 0x13c7d9
movq %rbx, %rdi
callq 0xe5fe4
leaq 0x53422(%rip), %rsi     # 0x13d0e9
movq %rbx, %rdi
callq 0xe5fe4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x8(%r14)
jne 0xe9ba8
cmpb $0x0, 0x9(%r14)
jne 0xe9bcd
cmpb $0x0, 0xa(%r14)
jne 0xe9bf2
jmp 0xe9c01