// File: /workspace/github_c_makefile_star2_O0/uobikiemukot[P]yaft/./ctrlseq/dcs.h
// Function: sixel_copy2cell
void sixel_copy2cell(struct terminal_t *term, struct sixel_canvas_t *sc)
{
	int y, x, h, cols, lines;
	int src_offset, dst_offset;
	struct cell_t *cellp;

	if (sc->height > term->height)
		sc->height = term->height;

	cols  = my_ceil(sc->width, CELL_WIDTH);
	lines = my_ceil(sc->height, CELL_HEIGHT);

	if (cols + term->cursor.x > term->cols)
		cols -= (cols + term->cursor.x - term->cols);

	for (y = 0; y < lines; y++) {
		for (x = 0; x < cols; x++) {
			erase_cell(term, term->cursor.y, term->cursor.x + x);
			cellp = &term->cells[term->cursor.y][term->cursor.x + x];
			cellp->has_pixmap = true;
			for (h = 0; h < CELL_HEIGHT; h++) {
				src_offset = (y * CELL_HEIGHT + h) * sc->line_length + (CELL_WIDTH * x) * BYTES_PER_PIXEL;
				dst_offset = h * CELL_WIDTH * BYTES_PER_PIXEL;
				if (src_offset >= BYTES_PER_PIXEL * term->width * term->height)
					break;
				memcpy(cellp->pixmap + dst_offset, sc->pixmap + src_offset, CELL_WIDTH * BYTES_PER_PIXEL);
			}
		}
		move_cursor(term, 1, 0);
		//set_cursor(term, term->cursor.y + 1, term->cursor.x);
	}
	cr(term);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x85de
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edi
movl $0x8, %esi
callq 0x3180
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
movl $0x10, %esi
callq 0x3180
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x24(%rcx), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jle 0x8638
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movzwl 0x24(%rax), %eax
addl %eax, %ecx
movq -0x8(%rbp), %rax
subl 0xc(%rax), %ecx
movl -0x20(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x877f
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x8761
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movzwl 0x26(%rax), %esi
movq -0x8(%rbp), %rax
movzwl 0x24(%rax), %edx
addl -0x18(%rbp), %edx
callq 0x46f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movzwl 0x24(%rcx), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x218, %rcx, %rcx      # imm = 0x218
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x1, 0x14(%rax)
movl $0x0, -0x1c(%rbp)
cmpl $0x10, -0x1c(%rbp)
jge 0x8751
movl -0x14(%rbp), %eax
shll $0x4, %eax
addl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0x14(%rcx), %eax
movl -0x18(%rbp), %ecx
shll $0x3, %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
shll $0x3, %eax
shll $0x2, %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
shll $0x2, %ecx
movq -0x8(%rbp), %rdx
imull 0x8(%rdx), %ecx
cmpl %ecx, %eax
jl 0x8709
jmp 0x8751
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
movslq -0x28(%rbp), %rsi
movq (%rdx,%rsi), %rdi
movq %rdi, 0x15(%rax,%rcx)
movq 0x8(%rdx,%rsi), %rdi
movq %rdi, 0x1d(%rax,%rcx)
movq 0x10(%rdx,%rsi), %rdi
movq %rdi, 0x25(%rax,%rcx)
movq 0x18(%rdx,%rsi), %rdx
movq %rdx, 0x2d(%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x86b9
jmp 0x8753
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x8652
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x4cd0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x863f
movq -0x8(%rbp), %rdi
callq 0x5a20
addq $0x40, %rsp
popq %rbp
retq
nop