// File: /workspace/github_c_makefile_star2_O3/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 0x50(%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)
movl $0x1, %edi
movl $0x10, %esi
callq 0x10d0
testq %rax, %rax
je 0x1edc
movq %rax, %rbx
leaq 0x20(%rsp), %rdx
movq %rax, 0x40(%rdx)
movq %r15, 0x48(%rdx)
leaq 0x40d(%rip), %rsi       # 0x210f
movq %r14, %rdi
callq 0x18fb
testl %eax, %eax
jne 0x1f21
movl 0x24(%rsp), %ecx
leal 0x9(%rcx), %edx
movl $0x1, %eax
cmpl $0x13, %edx
jb 0x1d47
movslq %ecx, %rcx
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
leal (%rdx,%rsi), %ecx
incl %eax
addl %esi, %edx
addl $0x9, %edx
cmpl $0x12, %edx
ja 0x1d23
cmpl $0x4, %eax
movl $0x3, %ecx
cmovael %eax, %ecx
leal 0x2(,%rcx,4), %eax
shll $0x2, %ecx
movl %eax, 0x28(%rsp)
leal 0x8(,%rcx,2), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x3292(%rip), %xmm0     # 0x5008
cvttss2si %xmm0, %ecx
movl %eax, 0x2c(%rsp)
movl %ecx, 0x30(%rsp)
movslq 0x48(%rsp), %r12
testq %r12, %r12
jle 0x1ee0
movq %rbx, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %r14
leaq -0x1(%r12), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x18(%rsp)
shlq $0x4, %rcx
leaq (%rax,%rcx), %r13
movq (%rax,%rcx), %rax
cmpq %r13, %rax
je 0x1e13
xorl %ebx, %ebx
subl 0x20(%rsp), %ebx
movq 0x8(%rax), %rdx
movl 0x10(%rax), %ecx
cmpq %r13, %rdx
je 0x1df7
leal (%rcx,%rbx), %esi
movl 0x10(%rdx), %edx
subl %esi, %edx
leal 0x1(%rdx), %edx
cmovll %ebp, %edx
addl %edx, %ebx
movq -0x18(%rax), %rdx
testq %rdx, %rdx
je 0x1df7
leal (%rbx,%rcx), %esi
movl 0x38(%rdx), %edx
cmpl %edx, %esi
jg 0x1df7
subl %esi, %ebx
addl %edx, %ebx
incl %ebx
leaq -0x28(%rax), %rsi
movq (%rax), %r15
addl %ebx, %ecx
movl %ecx, 0x10(%rax)
movq %r14, %rdi
callq 0x2f55
movq %r15, %rax
cmpq %r13, %r15
jne 0x1dc2
cmpq $0x2, %r12
movq 0x18(%rsp), %r12
jge 0x1d9c
movslq 0x48(%rsp), %rcx
movl 0x2c(%rsp), %eax
testq %rcx, %rcx
jle 0x1ee6
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl 0x30(%rsp), %r8d
xorl %edx, %edx
movq %rcx, %r9
decq %rcx
movq %rcx, %r11
shlq $0x4, %r11
leaq (%rdi,%r11), %r10
movq (%rdi,%r11), %r14
cmpq %r10, %r14
je 0x1ed0
movl 0x4c(%rsp), %r11d
movl %esi, %ebx
movl %edx, %ebp
movq -0x18(%r14), %rdx
testq %rdx, %rdx
je 0x1e90
movq -0x10(%r14), %rsi
testq %rsi, %rsi
je 0x1e90
movl 0x38(%rdx), %edx
movl 0x38(%rsi), %r15d
subl %edx, %r15d
movl %r15d, %esi
shrl $0x1f, %esi
addl %r15d, %esi
sarl %esi
addl %edx, %esi
jmp 0x1ea5
movl 0x10(%r14), %esi
incl %esi
imull %eax, %esi
movl %esi, 0x10(%r14)
testl %r11d, %r11d
je 0x1ea9
addl $0x1c, %esi
movl %esi, 0x10(%r14)
movq (%r14), %r15
movl 0x14(%r14), %edx
imull %r8d, %edx
addl %eax, %edx
cmpl %esi, %ebx
cmovgl %ebx, %esi
movl %edx, 0x14(%r14)
cmpl %edx, %ebp
cmovgl %ebp, %edx
movl %esi, %ebx
movq %r15, %r14
movl %edx, %ebp
cmpq %r10, %r15
jne 0x1e65
cmpq $0x2, %r9
jge 0x1e42
jmp 0x1eea
xorl %ebx, %ebx
jmp 0x1f35
xorl %edx, %edx
xorl %esi, %esi
jmp 0x1eef
xorl %edx, %edx
xorl %esi, %esi
movq 0x10(%rsp), %rbx
addl %eax, %esi
addl %eax, %edx
cmpl $0x0, 0x4c(%rsp)
je 0x1f08
addl 0x30(%rsp), %edx
addl $0x1c, %esi
subl 0x28(%rsp), %edx
addl $0x10, %edx
movl %esi, 0x34(%rsp)
movl %edx, 0x38(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x2378
testl %eax, %eax
je 0x1f47
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdi
callq 0x2311
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x48(%rsp), %eax
testl %eax, %eax
jle 0x1f2b
movq %rbx, 0x10(%rsp)
xorl %ebx, %ebx
movq 0x40(%rsp), %rcx
movq %rbx, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %r14
movq (%rcx,%rdx), %r8
cmpq %r14, %r8
je 0x1fad
movq -0x8(%r8), %rax
movq (%r8), %r15
testq %rax, %rax
je 0x1fa1
movq 0x60(%rsp), %rdi
movl 0x38(%rax), %esi
movl 0x3c(%rax), %edx
movl 0x10(%r8), %ecx
movl 0x14(%r8), %r8d
movl $0xff333333, %r9d       # imm = 0xFF333333
callq 0x24ea
testl %eax, %eax
jne 0x2105
movq %r15, %r8
cmpq %r14, %r15
jne 0x1f6f
movl 0x48(%rsp), %eax
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x1f56
testl %eax, %eax
jle 0x20fb
xorl %ecx, %ecx
movq 0x40(%rsp), %rax
movq %rcx, 0x70(%rsp)
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq (%rax,%rcx), %rbx
cmpq 0x18(%rsp), %rbx
je 0x20e5
movq (%rbx), %r15
movl 0x10(%rbx), %r13d
cmpl $-0x1, -0x28(%rbx)
movq 0x60(%rsp), %r14
movl 0x14(%rbx), %ebp
jne 0x2052
movq 0x68(%rsp), %r12
leal -0xe(%r13), %esi
leal -0x8(%rbp), %edx
leal 0xe(%r13), %ecx
leal 0x8(%rbp), %r8d
movl $0xff333333, (%rsp)     # imm = 0xFF333333
movq %r14, %rdi
movl $0x1, %r9d
callq 0x29f1
testl %eax, %eax
jne 0x2105
addl $-0xb, %r13d
addl $-0x7, %ebp
movq %r14, %rdi
leaq 0x3014(%rip), %rsi      # 0x5053
movl %r13d, %edx
movl %ebp, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq %r12, %r9
jmp 0x20d3
cmpl $0x1, -0x20(%rbx)
movl 0x28(%rsp), %ecx
movl $0xff333333, %r9d       # imm = 0xFF333333
movl $0xffff3333, %eax       # imm = 0xFFFF3333
cmovel %eax, %r9d
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
movl $0x1, %r8d
callq 0x2667
testl %eax, %eax
jne 0x2105
movl -0x28(%rbx), %ecx
movl $0x80, %esi
leaq 0x606d(%rip), %r14      # 0x8100
movq %r14, %rdi
leaq 0x2fba(%rip), %rdx      # 0x5057
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 0x60(%rsp), %rdi
movq 0x68(%rsp), %r9
movq %r14, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x2c31
movq %r15, %rbx
testl %eax, %eax
je 0x1fdd
jmp 0x2105
movq 0x70(%rsp), %rcx
incq %rcx
movslq 0x48(%rsp), %rax
cmpq %rax, %rcx
jl 0x1fc2
movq 0x10(%rsp), %rbx
jmp 0x1f2b
movq 0x10(%rsp), %rdi
jmp 0x1f24