// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x10(%rsi), %edx
movl 0x8(%rdi), %eax
cmpl %eax, %edx
jle 0x6833
movl %eax, 0x10(%r14)
movl %eax, %edx
movl 0xc(%r14), %eax
leal 0x7(%rax), %ecx
addl $0xe, %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
sarl $0x3, %eax
addl $0xf, %edx
movzwl 0x24(%rbx), %ecx
addl %eax, %ecx
movl 0xc(%rbx), %ebp
xorl %r12d, %r12d
subl %ecx, %ebp
cmovgel %r12d, %ebp
cmpl $0x10, %edx
jl 0x698a
addl %eax, %ebp
shrl $0x4, %edx
movabsq $0x100000000, %r13      # imm = 0x100000000
movb $0x1, %r15b
xorl %eax, %eax
movq %rdx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
jle 0x6961
xorl %eax, %eax
movl $0x15, %ecx
movzwl 0x26(%rbx), %edx
movzwl 0x24(%rbx), %esi
addl %eax, %esi
movq 0x18(%rbx), %rdi
movq (%rdi,%rdx,8), %rdi
imulq $0x218, %rsi, %rsi      # imm = 0x218
movq 0x588(%rbx), %r8
movq %r8, (%rdi,%rsi)
movzwl 0x4c(%rbx), %r8d
movw %r8w, 0x8(%rdi,%rsi)
movq %r13, 0xc(%rdi,%rsi)
movb $0x0, 0x14(%rdi,%rsi)
movq 0x28(%rbx), %rsi
movb %r15b, (%rsi,%rdx)
movq 0x18(%rbx), %rdx
movzwl 0x26(%rbx), %esi
movq (%rdx,%rsi,8), %rdi
movzwl 0x24(%rbx), %esi
leal (%rsi,%rax), %edx
imulq $0x218, %rdx, %rdx      # imm = 0x218
movb %r15b, 0x14(%rdi,%rdx)
movl %eax, %edx
shll $0x5, %edx
imulq $0x218, %rsi, %rsi      # imm = 0x218
addq %rcx, %rsi
addq %rdi, %rsi
movl %r12d, %edi
xorl %r8d, %r8d
movl 0x14(%r14), %r9d
imull %edi, %r9d
addl %edx, %r9d
movl 0x4(%rbx), %r10d
imull 0x8(%rbx), %r10d
shll $0x2, %r10d
cmpl %r10d, %r9d
jge 0x6950
movq (%r14), %r10
movslq %r9d, %r9
movups (%r10,%r9), %xmm0
movups 0x10(%r10,%r9), %xmm1
movups %xmm1, 0x10(%rsi,%r8)
movups %xmm0, (%rsi,%r8)
addq $0x20, %r8
incl %edi
cmpq $0x200, %r8             # imm = 0x200
jne 0x6908
incl %eax
addq $0x218, %rcx            # imm = 0x218
cmpl %ebp, %eax
jl 0x6890
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x4026
movq 0x10(%rsp), %rax
incq %rax
addl $0x10, %r12d
movq 0x8(%rsp), %rdx
cmpq %rdx, %rax
jne 0x687c
movzwl 0x26(%rbx), %esi
movq %rbx, %rdi
xorl %edx, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40bd