// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]rbtree/test/bitmap.c
// Function: bitmap_draw_line
int bitmap_draw_line(bitmap_t *bitmap, int x1, int y1, int x2, int y2, color_t color)
{
	int ix, iy, cx, cy, n2dy, n2dydx, d;
	int dx, dy, yy;
	int r = 0;
	
	dx = abs(x2 - x1);
	dy = abs(y2 - y1);
	yy = 0;

	if (dx < dy) {
		yy = 1;
		swap_int(&x1, &y1);
		swap_int(&x2, &y2);
		swap_int(&dx, &dy);
	}

	ix = (x2 - x1) > 0 ? 1 : -1;
	iy = (y2 - y1) > 0 ? 1 : -1;
	cx = x1;
	cy = y1;
	n2dy = dy * 2;
	n2dydx = (dy - dx) * 2;
	d = dy * 2 - dx;

	if (yy) { /* ����ֱ���� x ���ļнǴ��� 45 �� */
		while (cx != x2) {
			if (d < 0) {
				d += n2dy;
			}
			else {
				cy += iy;
				d += n2dydx;
			}
			if (bitmap_draw_point(bitmap, cy, cx, color) != 0)
				r = -1;
			cx += ix;
		}
	}
	else { /* ����ֱ���� x ���ļн�С�� 45 �� */
		while (cx != x2) {
			if (d < 0) {
				d += n2dy;
			}
			else {
				cy += iy;
				d += n2dydx;
			}
			if (bitmap_draw_point(bitmap, cx, cy, color) != 0)
				r = -1;
			cx += ix;
		}
	}

	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x14(%rbp), %eax
subl -0xc(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %eax
subl -0x10(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x3041
movl $0x1, -0x44(%rbp)
leaq -0xc(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x3160
leaq -0x14(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x3160
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3160
movl -0x14(%rbp), %edx
subl -0xc(%rbp), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl $0x0, %edx
cmovgl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %edx
subl -0x10(%rbp), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl $0x0, %edx
cmovgl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x40(%rbp), %eax
shll %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
shll %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
shll %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x30fb
jmp 0x30a5
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x30f9
cmpl $0x0, -0x38(%rbp)
jge 0x30be
movl -0x30(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x30d0
movl -0x24(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x2f40
cmpl $0x0, %eax
je 0x30ee
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl -0x20(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x30a5
jmp 0x3153
jmp 0x30fd
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x3151
cmpl $0x0, -0x38(%rbp)
jge 0x3116
movl -0x30(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x3128
movl -0x24(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x2f40
cmpl $0x0, %eax
je 0x3146
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl -0x20(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x30fd
jmp 0x3153
movl -0x48(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)