// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]rbtree/test/bitmap.c
// Function: rbtree_save_as_bitmap
bitmap_t *rbtree_save_as_bitmap(rbtree_t *tree, asc16_t *asc16, int nil)
{
	bitmap_t *bitmap;
	draw_state_t st = { 0 };

	st.draw_nil = nil;
	dllist_init(&st.nils);

	bitmap = malloc(sizeof(bitmap_t));
	if (bitmap == NULL)
		return NULL;

	memset(bitmap, 0, sizeof(bitmap_t));

	st.bitmap = bitmap;
	st.asc16 = asc16;

	if (rbtree_foreach_preorder(tree, predraw, &st) != 0) {
		free(bitmap);
		free_draw_state(&st);
		return NULL;
	}

	calc_xy(&st);

	if (bitmap_init(bitmap, st.bitmapW, st.bitmapH, COLOR_WHITE) != 0) {
		free(bitmap);
		free_draw_state(&st);
		return NULL;
	}

	if (draw_rbtree(&st) != 0) {
		free(bitmap);
		free_draw_state(&st);
		return NULL;
	}

	free_draw_state(&st);

	return bitmap;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movaps %xmm0, -0x10(%rax)
movaps %xmm0, -0x20(%rax)
movaps %xmm0, -0x30(%rax)
movl %edx, -0x4(%rax)
movq %rax, (%rax)
movq %rax, 0x8(%rax)
pushq $0x1
popq %rdi
pushq $0x10
popq %rsi
callq 0x10d0
testq %rax, %rax
je 0x1b8b
movq %rax, %rbx
leaq 0x10(%rsp), %rdx
movq %rax, 0x40(%rdx)
movq %r15, 0x48(%rdx)
leaq 0x393(%rip), %rsi       # 0x1ef5
movq %r14, %rdi
callq 0x16cd
testl %eax, %eax
jne 0x1d25
pushq $0x1
popq %rcx
movl 0x14(%rsp), %eax
pushq $0xa
popq %rsi
leal 0x9(%rax), %edx
cmpl $0x13, %edx
jb 0x1b92
cltd
idivl %esi
incl %ecx
jmp 0x1b7c
xorl %ebx, %ebx
jmp 0x1d39
movq %rbx, 0x8(%rsp)
cmpl $0x4, %ecx
pushq $0x3
popq %rax
cmovael %ecx, %eax
leal 0x2(,%rax,4), %ecx
shll $0x2, %eax
leaq 0x10(%rsp), %r14
movl %ecx, 0x8(%r14)
leal 0x8(,%rax,2), %eax
cvtsi2ss %eax, %xmm0
mulss 0x2442(%rip), %xmm0     # 0x4008
cvttss2si %xmm0, %ecx
movl %eax, 0xc(%r14)
movl %ecx, 0x10(%r14)
movl 0x28(%r14), %r15d
xorl %ebp, %ebp
testl %r15d, %r15d
jle 0x1c56
decq %r15
movq 0x30(%rsp), %rax
movq %r15, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %r12
xorl %r13d, %r13d
subl 0x10(%rsp), %r13d
movq (%rax,%rcx), %rbx
movq %rbx, %rax
leaq -0x28(%rbx), %rsi
movq (%rbx), %rbx
cmpq %r12, %rax
je 0x1bd8
movq 0x8(%rax), %rdx
movl 0x10(%rax), %ecx
cmpq %r12, %rdx
je 0x1c46
leal (%rcx,%r13), %edi
movl 0x10(%rdx), %edx
subl %edi, %edx
leal 0x1(%rdx), %edx
cmovll %ebp, %edx
addl %edx, %r13d
movq -0x18(%rax), %rdx
testq %rdx, %rdx
je 0x1c46
leal (%rcx,%r13), %edi
movl 0x38(%rdx), %edx
cmpl %edx, %edi
jg 0x1c46
subl %edi, %r13d
addl %edx, %r13d
incl %r13d
addl %r13d, %ecx
movl %ecx, 0x10(%rax)
movq %r14, %rdi
callq 0x2a11
jmp 0x1bfc
movl 0x38(%rsp), %edi
movq 0x30(%rsp), %r9
xorl %r8d, %r8d
movl 0x1c(%rsp), %ecx
pushq $0x2
popq %r10
xorl %esi, %esi
movl 0x3c(%rsp), %r11d
testl %edi, %edi
jle 0x1cea
decq %rdi
movq %rdi, %rax
shlq $0x4, %rax
leaq (%r9,%rax), %r14
movq (%r9,%rax), %rbx
movl 0x20(%rsp), %ebp
movq (%rbx), %r15
cmpq %r14, %rbx
je 0x1c6c
movq -0x18(%rbx), %rax
testq %rax, %rax
je 0x1cb8
movq -0x10(%rbx), %rdx
testq %rdx, %rdx
je 0x1cb8
movl 0x38(%rax), %r12d
movl 0x38(%rdx), %eax
subl %r12d, %eax
cltd
idivl %r10d
addl %r12d, %eax
jmp 0x1ccb
movl 0x10(%rbx), %eax
incl %eax
imull %ecx, %eax
movl %eax, 0x10(%rbx)
testl %r11d, %r11d
je 0x1cce
addl $0x1c, %eax
movl %eax, 0x10(%rbx)
movl 0x14(%rbx), %edx
imull %ebp, %edx
addl %ecx, %edx
movl %edx, 0x14(%rbx)
cmpl %eax, %esi
cmovlel %eax, %esi
cmpl %edx, %r8d
cmovlel %edx, %r8d
movq %r15, %rbx
jmp 0x1c8b
addl %ecx, %esi
addl %ecx, %r8d
testl %r11d, %r11d
je 0x1d05
addl 0x20(%rsp), %r8d
addl $0x1c, %esi
subl 0x18(%rsp), %r8d
addl $0x10, %r8d
movq 0x8(%rsp), %rbx
movl %esi, 0x24(%rsp)
movl %r8d, 0x28(%rsp)
pushq $-0x1
popq %rcx
movq %rbx, %rdi
movl %r8d, %edx
callq 0x2132
testl %eax, %eax
je 0x1d4b
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
leaq 0x10(%rsp), %rdi
callq 0x20cb
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
movslq 0x38(%rsp), %rax
cmpq %rax, %rbx
jge 0x1daa
movq 0x30(%rsp), %rax
movq %rbx, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %r14
movq (%rax,%rcx), %r15
cmpq %r14, %r15
je 0x1da5
movq %r15, %rax
movq (%r15), %r15
movq -0x8(%rax), %rcx
testq %rcx, %rcx
je 0x1d6b
movq 0x50(%rsp), %rdi
movl 0x38(%rcx), %esi
movl 0x3c(%rcx), %edx
movl 0x10(%rax), %ecx
movl 0x14(%rax), %r8d
movl $0xff333333, %r9d       # imm = 0xFF333333
callq 0x21c1
testl %eax, %eax
je 0x1d6b
jmp 0x1ee1
incq %rbx
jmp 0x1d4d
xorl %ecx, %ecx
cltq
cmpq %rax, %rcx
jge 0x1eeb
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rsp)
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x70(%rsp)
movq (%rax,%rcx), %rbx
cmpq 0x70(%rsp), %rbx
je 0x1ed0
movq (%rbx), %r12
movl 0x10(%rbx), %r14d
cmpl $-0x1, -0x28(%rbx)
movq 0x50(%rsp), %r15
movl 0x14(%rbx), %r13d
jne 0x1e44
movq 0x58(%rsp), %rbp
leal -0xe(%r14), %esi
leal -0x8(%r13), %edx
leal 0xe(%r14), %ecx
leal 0x8(%r13), %r8d
movl $0xff333333, (%rsp)     # imm = 0xFF333333
movq %r15, %rdi
pushq $0x1
popq %r9
callq 0x25cc
testl %eax, %eax
jne 0x1ee1
addl $-0xb, %r14d
addl $-0x7, %r13d
movq %r15, %rdi
leaq 0x21da(%rip), %rsi      # 0x400f
movl %r14d, %edx
movl %r13d, %ecx
pushq $-0x1
popq %r8
movq %rbp, %r9
jmp 0x1ebe
cmpl $0x1, -0x20(%rbx)
movl 0x18(%rsp), %ecx
movl $0xff333333, %r9d       # imm = 0xFF333333
movl $0xffff3333, %eax       # imm = 0xFFFF3333
cmovel %eax, %r9d
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
pushq $0x1
popq %r8
callq 0x230b
testl %eax, %eax
jne 0x1ee1
movl -0x28(%rbx), %ecx
movl $0x80, %esi
leaq 0x5280(%rip), %r14      # 0x7100
movq %r14, %rdi
leaq 0x2189(%rip), %rdx      # 0x4013
xorl %eax, %eax
callq 0x10c0
movq %r14, %rdi
callq 0x10a0
shll $0x3, %eax
sarl %eax
movl 0x10(%rbx), %edx
movl 0x14(%rbx), %ecx
negl %eax
addl %eax, %edx
incl %edx
addl $-0x7, %ecx
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %r9
movq %r14, %rsi
pushq $-0x1
popq %r8
callq 0x2748
movq %r12, %rbx
testl %eax, %eax
je 0x1dd2
jmp 0x1ee1
movq 0x68(%rsp), %rcx
incq %rcx
movl 0x38(%rsp), %eax
jmp 0x1dac
movq 0x8(%rsp), %rdi
jmp 0x1d28
movq 0x8(%rsp), %rbx
jmp 0x1d2f