// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]rbtree/test/bitmap.c
// Function: calc_xy
static int calc_xy(draw_state_t *st)
{
	int i, w, h, x;
	dllist_t *list;
	dlitem_t *currItem, *nextItem;
	rbpoint_t *curr, *prev, *left, *right;

	st->radius = get_radius(st->maxValue);
	st->advanceX = (st->radius + CIRCLE_PADDING) * 2;
	st->advanceY = (int)((float)st->advanceX * GOLDEN_RATIO);

	w = 0;
	/* �ص�����ɨ�裬ʹ�ýڵ㲻�ص� */
	for (i = st->rowcount - 1; i >= 0; i--) {
		list = st->rows + i;
		x = -st->minX;
		dllist_foreach(list, currItem, nextItem, rbpoint_t, curr, dlentry) {

			if (!dllist_is_start(list, currItem->prev)) {
				prev = container_of(currItem->prev, rbpoint_t, dlentry);
				if ((curr->x + x) <= prev->x)
					x += prev->x - curr->x - x + 1;
				if (!rbnode_is_nil(curr->rbentry.left)) {
					left = container_of(curr->rbentry.left, rbpoint_t, rbentry);
					if ((curr->x + x) <= left->x)
						x += left->x - curr->x - x + 1;
				}
			}

			curr->x += x;

			move_x_fixup(st, curr);
		}
	}

	w = 0;
	h = 0;
	for (i = st->rowcount - 1; i >= 0; i--) {
		list = st->rows + i;
		dllist_foreach(list, currItem, nextItem, rbpoint_t, curr, dlentry) {

			if (!rbnode_is_leaf(&curr->rbentry)) {
				left = container_of(curr->rbentry.left, rbpoint_t, rbentry);
				right = container_of(curr->rbentry.right, rbpoint_t, rbentry);
				curr->x = left->x + (right->x - left->x) / 2;
			}
			else {
				curr->x *= st->advanceX;
				curr->x += st->advanceX; /* left margin */
				if (st->draw_nil)
					curr->x += 3 * ASC16_GYLPH_WIDTH + CIRCLE_PADDING * 2;
			}

			curr->y *= st->advanceY;
			curr->y += st->advanceX; /* top margin */

			if (w < curr->x)
				w = curr->x;
			if (h < curr->y)
				h = curr->y;
		}
	}

	w += st->advanceX;  /* right margin */
	h += st->advanceX; /* bottom margin */

	if (st->draw_nil) {
		w += 3 * ASC16_GYLPH_WIDTH + CIRCLE_PADDING * 2;
		h += st->advanceY - (st->radius - ASC16_GYLPH_HEIGHT);
	}


	st->bitmapW = w;
	st->bitmapH = h;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x3ff0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x2, %ecx
shll %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm0
movss 0x4557(%rip), %xmm1     # 0x700c
mulss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x2c27
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $-0x28, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq %rcx, %rax
sete %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b3f
jmp 0x2c17
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq %rcx, %rax
je 0x2bd9
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
addq $-0x28, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
addl -0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jg 0x2b91
movq -0x40(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x38(%rbp), %rcx
subl 0x38(%rcx), %eax
subl -0x18(%rbp), %eax
addl $0x1, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2bd7
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
addl -0x18(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jg 0x2bd5
movq -0x48(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x38(%rbp), %rcx
subl 0x38(%rcx), %eax
subl -0x18(%rbp), %eax
addl $0x1, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x2bd7
jmp 0x2bd9
movl -0x18(%rbp), %ecx
movq -0x38(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4060
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $-0x28, %rax
movq %rax, -0x38(%rbp)
jmp 0x2b26
jmp 0x2c19
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2ad8
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x2db5
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $-0x28, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq %rcx, %rax
sete %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c9e
jmp 0x2da5
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2cf4
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x2cf4
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x50(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x48(%rbp), %rdx
subl 0x38(%rdx), %eax
movl $0x2, %esi
cltd
idivl %esi
addl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
jmp 0x2d30
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
imull 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x2d2e
movq -0x38(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1c, %ecx
movl %ecx, 0x38(%rax)
jmp 0x2d30
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x38(%rbp), %rax
imull 0x3c(%rax), %ecx
movl %ecx, 0x3c(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x38(%rbp), %rax
addl 0x3c(%rax), %ecx
movl %ecx, 0x3c(%rax)
movl -0x10(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jge 0x2d69
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x10(%rbp)
movl -0x14(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jge 0x2d7f
movq -0x38(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x2d81
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $-0x28, %rax
movq %rax, -0x38(%rbp)
jmp 0x2c85
jmp 0x2da7
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2c42
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x2dfb
movl -0x10(%rbp), %eax
addl $0x1c, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x10, %ecx
subl %ecx, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)