// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0xf, (%rax)
setbe %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpl $0xf, 0x4(%rax)
setbe %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movb $0x1, %al
cmpq $0x0, -0x20(%rbp)
movb %al, -0x61(%rbp)
je 0x16f384
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x80(%rcx), %eax
setne %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movb $0x1, %al
cmpq $0x0, -0x20(%rbp)
movb %al, -0x62(%rbp)
je 0x16f3b2
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x84(%rcx), %eax
setne %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x16f3d1
movl $0x0, -0x24(%rbp)
movl $0x1, -0x48(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x16f3e5
movl $0x0, -0x28(%rbp)
movl $0x1, -0x48(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzbl 0xa(%rax), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x16f452
cmpl $0x0, -0x48(%rbp)
jne 0x16f452
movq -0x18(%rbp), %rax
movb $0x1, 0xb(%rax)
jmp 0x16f69a
movq -0x18(%rbp), %rax
movb $0x0, 0xb(%rax)
movq -0x10(%rbp), %rdi
leaq 0x6635f(%rip), %rsi     # 0x1d57c4
callq 0x168da0
cmpl $0x0, -0x3c(%rbp)
jne 0x16f475
jmp 0x16f5e3
movq -0x10(%rbp), %rdi
leaq 0x6634a(%rip), %rsi     # 0x1d57ca
callq 0x168da0
cmpl $0x1, -0x3c(%rbp)
jle 0x16f49b
movq -0x10(%rbp), %rdi
leaq 0x6634b(%rip), %rsi     # 0x1d57e1
callq 0x168da0
cmpl $0x0, -0x24(%rbp)
je 0x16f4d2
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x160080
movq -0x70(%rbp), %rdi
movsbl %al, %edx
leaq 0x66310(%rip), %rsi     # 0x1d57d2
movb $0x0, %al
callq 0x167f00
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x16f520
cmpl $0x0, -0x38(%rbp)
je 0x16f4ee
movq -0x10(%rbp), %rdi
leaq 0x492c0(%rip), %rsi     # 0x1b87a9
callq 0x168da0
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x160080
movq -0x78(%rbp), %rdi
movsbl %al, %edx
leaq 0x662c6(%rip), %rsi     # 0x1d57d6
movb $0x0, %al
callq 0x167f00
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x16f559
cmpl $0x0, -0x38(%rbp)
je 0x16f540
movq -0x10(%rbp), %rdi
leaq 0x4926e(%rip), %rsi     # 0x1b87a9
callq 0x168da0
movq -0x10(%rbp), %rdi
leaq 0x31d72(%rip), %rsi     # 0x1a12bd
callq 0x168da0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x9(%rax)
je 0x16f592
cmpl $0x0, -0x38(%rbp)
je 0x16f579
movq -0x10(%rbp), %rdi
leaq 0x49235(%rip), %rsi     # 0x1b87a9
callq 0x168da0
movq -0x10(%rbp), %rdi
leaq 0x315ac(%rip), %rsi     # 0x1a0b30
callq 0x168da0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0xa(%rax)
je 0x16f5cb
cmpl $0x0, -0x38(%rbp)
je 0x16f5b2
movq -0x10(%rbp), %rdi
leaq 0x491fc(%rip), %rsi     # 0x1b87a9
callq 0x168da0
movq -0x10(%rbp), %rdi
leaq 0x2e6a6(%rip), %rsi     # 0x19dc63
callq 0x168da0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x1, -0x3c(%rbp)
jle 0x16f5e1
movq -0x10(%rbp), %rdi
leaq 0x66205(%rip), %rsi     # 0x1d57e1
callq 0x168da0
jmp 0x16f5e3
cmpl $0x0, -0x40(%rbp)
jne 0x16f5f3
cmpl $0x0, -0x44(%rbp)
je 0x16f68a
movq -0x10(%rbp), %rdi
leaq 0x661dc(%rip), %rsi     # 0x1d57da
callq 0x168da0
cmpl $0x0, -0x40(%rbp)
je 0x16f633
movq -0x18(%rbp), %rax
movl (%rax), %edi
leaq -0x60(%rbp), %rsi
movl $0x10, %edx
callq 0x161470
movq -0x10(%rbp), %rdi
leaq -0x60(%rbp), %rdx
leaq 0x661c2(%rip), %rsi     # 0x1d57ee
movb $0x0, %al
callq 0x167f00
cmpl $0x0, -0x44(%rbp)
je 0x16f67a
cmpl $0x0, -0x40(%rbp)
je 0x16f64f
movq -0x10(%rbp), %rdi
leaq 0x6522a(%rip), %rsi     # 0x1d4874
callq 0x168da0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x60(%rbp), %rsi
movl $0x10, %edx
callq 0x161470
movq -0x10(%rbp), %rdi
leaq -0x60(%rbp), %rdx
leaq 0x66170(%rip), %rsi     # 0x1d57e3
movb $0x0, %al
callq 0x167f00
movq -0x10(%rbp), %rdi
leaq 0x6615c(%rip), %rsi     # 0x1d57e1
callq 0x168da0
movq -0x10(%rbp), %rdi
leaq 0x669d4(%rip), %rsi     # 0x1d6069
callq 0x168da0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)