// File: /workspace/github_c_makefile_star2_O1/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), %r12d
movl $0x1, %ebp
movl $0x1, %r13d
testq %rdx, %rdx
je 0xf5570
xorl %r13d, %r13d
cmpl 0x80(%rdx), %r12d
setne %r13b
movl 0x4(%r14), %esi
testq %rdx, %rdx
je 0xf5585
xorl %ebp, %ebp
cmpl 0x84(%rdx), %esi
setne %bpl
xorl %eax, %eax
cmpl $0x10, %r12d
setae %cl
cmovael %eax, %r13d
cmpl $0x10, %esi
setae %dl
cmovael %eax, %ebp
orb %cl, %dl
leal (%rbp,%r13), %r15d
cmpb $0x1, 0x8(%r14)
sbbl $-0x1, %r15d
cmpb $0x1, 0x9(%r14)
sbbl $-0x1, %r15d
cmpb $0x1, 0xa(%r14)
movzbl %dl, %eax
sbbl $-0x1, %r15d
orl %r15d, %eax
je 0xf5638
movl %esi, 0x8(%rsp)
movb $0x0, 0xb(%r14)
leaq 0x54117(%rip), %rsi     # 0x1496ec
movq %rbx, %rdi
callq 0xf16f0
testl %r15d, %r15d
je 0xf571e
leaq 0x54105(%rip), %rsi     # 0x1496f2
movq %rbx, %rdi
callq 0xf16f0
cmpl $0x2, %r15d
jl 0xf560a
leaq 0x54107(%rip), %rsi     # 0x149709
movq %rbx, %rdi
callq 0xf16f0
movl %r12d, 0xc(%rsp)
testl %r13d, %r13d
je 0xf5642
movl (%r14), %edi
callq 0xec1b8
movsbl %al, %edx
leaq 0x540d4(%rip), %rsi     # 0x1496fa
movq %rbx, %rdi
xorl %eax, %eax
callq 0xf0ec4
movl $0x1, %r12d
jmp 0xf5645
movb $0x1, 0xb(%r14)
jmp 0xf57da
xorl %r12d, %r12d
testl %ebp, %ebp
je 0xf567d
testl %r13d, %r13d
je 0xf565d
leaq 0x37390(%rip), %rsi     # 0x12c9e5
movq %rbx, %rdi
callq 0xf16f0
movl 0x4(%r14), %edi
callq 0xec1b8
movsbl %al, %edx
leaq 0x5408e(%rip), %rsi     # 0x1496fe
movq %rbx, %rdi
xorl %eax, %eax
callq 0xf0ec4
incl %r12d
cmpb $0x0, 0x8(%r14)
je 0xf56aa
testl %r12d, %r12d
je 0xf5698
leaq 0x37355(%rip), %rsi     # 0x12c9e5
movq %rbx, %rdi
callq 0xf16f0
leaq 0x1fd26(%rip), %rsi     # 0x1153c5
movq %rbx, %rdi
callq 0xf16f0
incl %r12d
cmpb $0x0, 0x9(%r14)
je 0xf56da
testl %r12d, %r12d
je 0xf56c5
leaq 0x37328(%rip), %rsi     # 0x12c9e5
movq %rbx, %rdi
callq 0xf16f0
leaq 0x1f5e4(%rip), %rsi     # 0x114cb0
movq %rbx, %rdi
callq 0xf16f0
movl $0x1, %r12d
cmpb $0x0, 0xa(%r14)
je 0xf5704
testl %r12d, %r12d
je 0xf56f5
leaq 0x372f8(%rip), %rsi     # 0x12c9e5
movq %rbx, %rdi
callq 0xf16f0
leaq 0x1c497(%rip), %rsi     # 0x111b93
movq %rbx, %rdi
callq 0xf16f0
cmpl $0x2, %r15d
movl 0xc(%rsp), %r12d
jl 0xf571e
leaq 0x53ff3(%rip), %rsi     # 0x149709
movq %rbx, %rdi
callq 0xf16f0
cmpl $0x10, 0x8(%rsp)
setae %al
cmpl $0x10, %r12d
setae %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xf57cb
leaq 0x53fc3(%rip), %rsi     # 0x149702
movq %rbx, %rdi
callq 0xf16f0
cmpl $0x10, %r12d
jb 0xf5776
movl (%r14), %edi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xeccaa
leaq 0x53fad(%rip), %rsi     # 0x149716
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xf0ec4
cmpl $0x10, 0x8(%rsp)
jb 0xf57bc
cmpl $0x10, %r12d
jb 0xf5792
leaq 0x52ff2(%rip), %rsi     # 0x14877c
movq %rbx, %rdi
callq 0xf16f0
movl 0x4(%r14), %edi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
movl $0x10, %edx
callq 0xeccaa
leaq 0x53f5c(%rip), %rsi     # 0x14970b
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xf0ec4
leaq 0x53f46(%rip), %rsi     # 0x149709
movq %rbx, %rdi
callq 0xf16f0
leaq 0x54837(%rip), %rsi     # 0x14a009
movq %rbx, %rdi
callq 0xf16f0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)