// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-font.c
// Function: paint_character_internal
static void paint_character_internal(deark *c, de_bitmap *img,
	struct de_bitmap_font_char *ch,
	i64 xpos, i64 ypos, u32 fgcol, unsigned int flags)
{
	i64 i, j;
	i64 num_x_pixels_to_paint;
	int vga9col_flag = 0;

	num_x_pixels_to_paint = (i64)ch->width;
	if((flags&DE_PAINTFLAG_VGA9COL) && ch->width==8) {
		vga9col_flag = 1;
		num_x_pixels_to_paint = 9;
	}

	for(j=0; j<ch->height; j++) {
		i64 j_src;

		j_src = j;
		if(flags&DE_PAINTFLAG_TOPHALF) {
			j_src = j/2;
		}
		else if(flags&DE_PAINTFLAG_BOTTOMHALF) {
			j_src = (ch->height+j)/2;
		}

		for(i=0; i<num_x_pixels_to_paint; i++) {
			i64 i_src; // -1 = No source position
			int is_fg = 0;
			u8 x;

			i_src = i;
			if(flags&DE_PAINTFLAG_LEFTHALF) {
				i_src = i/2;
			}
			else if(flags&DE_PAINTFLAG_RIGHTHALF) {
				i_src = (num_x_pixels_to_paint+i)/2;
			}

			if(i_src==8 && vga9col_flag) {
				// Manufacture a column 8.
				if(ch->codepoint_nonunicode>=0xb0 && ch->codepoint_nonunicode<=0xdf) {
					i_src = 7; // Make this pixel a duplicate of the one in col #7.
				}
				else {
					i_src = -1; // Make this pixel a background pixel.
				}
			}

			if(i_src>=0 && i_src<ch->width) {
				x = ch->bitmap[j_src*ch->rowspan + i_src/8];
				if(x & (1<<(7-i_src%8))) {
					is_fg = 1;
				}
			}

			if(is_fg) {
				u32 clr = fgcol;

				de_bitmap_setpixel_rgba(img, xpos+i, ypos+j, clr);
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl 0x10(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x16fb1d
movq -0x18(%rbp), %rax
cmpl $0x8, 0x8(%rax)
jne 0x16fb1d
movl $0x1, -0x4c(%rbp)
movq $0x9, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0xc(%rcx), %rcx
cmpq %rcx, %rax
jge 0x16fd02
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movl 0x10(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x16fb61
movq -0x40(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x58(%rbp)
jmp 0x16fb88
movl 0x10(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x16fb86
movq -0x18(%rbp), %rax
movslq 0xc(%rax), %rax
addq -0x40(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x58(%rbp)
jmp 0x16fb88
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jge 0x16fcef
movl $0x0, -0x64(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movl 0x10(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x16fbcc
movq -0x38(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x60(%rbp)
jmp 0x16fbef
movl 0x10(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x16fbed
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x60(%rbp)
jmp 0x16fbef
cmpq $0x8, -0x60(%rbp)
jne 0x16fc28
cmpl $0x0, -0x4c(%rbp)
je 0x16fc28
movq -0x18(%rbp), %rax
cmpl $0xb0, (%rax)
jl 0x16fc1e
movq -0x18(%rbp), %rax
cmpl $0xdf, (%rax)
jg 0x16fc1e
movq $0x7, -0x60(%rbp)
jmp 0x16fc26
movq $-0x1, -0x60(%rbp)
jmp 0x16fc28
cmpq $0x0, -0x60(%rbp)
jl 0x16fcb4
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
jge 0x16fcb4
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
imulq 0x18(%rax), %rcx
movq -0x60(%rbp), %rax
movl $0x8, %esi
cqto
idivq %rsi
movq %rax, %rdx
movq -0x78(%rbp), %rax
addq %rdx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x65(%rbp)
movzbl -0x65(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movl -0x70(%rbp), %eax
movl $0x7, %ecx
subq %rdx, %rcx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x16fcb2
movl $0x1, -0x64(%rbp)
jmp 0x16fcb4
cmpl $0x0, -0x64(%rbp)
je 0x16fcdc
movl -0x2c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rdx
addq -0x40(%rbp), %rdx
movl -0x6c(%rbp), %ecx
callq 0x16b350
jmp 0x16fcde
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x16fb90
jmp 0x16fcf1
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x16fb25
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)