// File: /workspace/github_c_makefile_star2_O1/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, (%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 $0x10, %edi
callq 0x1100
testq %rax, %rax
je 0x1d7d
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0x20(%rsp), %rdx
movq %rax, 0x10(%rsp)
movq %rax, 0x40(%rdx)
movq %r15, 0x48(%rdx)
leaq 0x40f(%rip), %rsi       # 0x1fab
movq %r14, %rdi
callq 0x16d0
testl %eax, %eax
jne 0x1dbd
movl 0x24(%rsp), %ecx
leal 0x9(%rcx), %edx
movl $0x1, %eax
cmpl $0x13, %edx
jb 0x1be1
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 0x1bbd
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 0x33f8(%rip), %xmm0     # 0x5008
cvttss2si %xmm0, %ecx
movl %eax, 0x2c(%rsp)
movl %ecx, 0x30(%rsp)
movslq 0x48(%rsp), %r12
testq %r12, %r12
jle 0x1cb0
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 0x1ca5
xorl %ebx, %ebx
subl 0x20(%rsp), %ebx
movq 0x8(%rax), %rdx
cmpq %r13, %rdx
je 0x1c8b
movl 0x10(%rax), %ecx
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 0x1c8b
addl %ebx, %ecx
movl 0x38(%rdx), %edx
cmpl %edx, %ecx
jg 0x1c8b
subl %ecx, %ebx
addl %edx, %ebx
incl %ebx
leaq -0x28(%rax), %rsi
movq (%rax), %r15
addl %ebx, 0x10(%rax)
movq %r14, %rdi
callq 0x2d74
movq %r15, %rax
cmpq %r13, %r15
jne 0x1c57
cmpq $0x2, %r12
movq 0x18(%rsp), %r12
jge 0x1c31
movslq 0x48(%rsp), %rax
testq %rax, %rax
jle 0x1d81
movq 0x40(%rsp), %rcx
movl 0x2c(%rsp), %edi
movl 0x30(%rsp), %r8d
xorl %r10d, %r10d
xorl %r11d, %r11d
movq %rax, %r9
decq %rax
movq %rax, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %r14
movq (%rcx,%rdx), %rbx
cmpq %r14, %rbx
je 0x1d65
movl 0x4c(%rsp), %ebp
movq -0x18(%rbx), %rdx
testq %rdx, %rdx
je 0x1d20
movq -0x10(%rbx), %rsi
testq %rsi, %rsi
je 0x1d20
movl 0x38(%rdx), %edx
movl 0x38(%rsi), %esi
subl %edx, %esi
movl %esi, %r15d
shrl $0x1f, %r15d
addl %esi, %r15d
sarl %r15d
addl %edx, %r15d
movl %r15d, 0x10(%rbx)
jmp 0x1d35
movl 0x10(%rbx), %edx
incl %edx
imull %edi, %edx
movl %edx, 0x10(%rbx)
testl %ebp, %ebp
je 0x1d35
addl $0x1c, %edx
movl %edx, 0x10(%rbx)
movq (%rbx), %r15
movl 0x14(%rbx), %edx
imull %r8d, %edx
addl %edi, %edx
movl %edx, 0x14(%rbx)
movl 0x10(%rbx), %esi
cmpl %esi, %r10d
cmovgl %r10d, %esi
cmpl %edx, %r11d
cmovgl %r11d, %edx
movl %esi, %r10d
movq %r15, %rbx
movl %edx, %r11d
cmpq %r14, %r15
jne 0x1cf0
jmp 0x1d6b
movl %r11d, %edx
movl %r10d, %esi
movl %esi, %r10d
movl %edx, %r11d
cmpq $0x2, %r9
jge 0x1cd2
jmp 0x1d85
xorl %ebx, %ebx
jmp 0x1dd3
xorl %edx, %edx
xorl %esi, %esi
movl 0x2c(%rsp), %eax
addl %eax, %esi
addl %eax, %edx
cmpl $0x0, 0x4c(%rsp)
je 0x1da2
addl 0x30(%rsp), %edx
addl $0x1c, %esi
subl 0x28(%rsp), %edx
addl $0x10, %edx
movq 0x10(%rsp), %rdi
movl %esi, 0x34(%rsp)
movl %edx, 0x38(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x224a
testl %eax, %eax
je 0x1de5
movq 0x10(%rsp), %rdi
callq 0x1030
xorl %ebx, %ebx
leaq 0x20(%rsp), %rdi
callq 0x21e0
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x48(%rsp)
jle 0x1e49
xorl %ebx, %ebx
movq 0x40(%rsp), %rax
movq %rbx, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %r14
movq (%rax,%rcx), %rax
cmpq %r14, %rax
je 0x1e3c
movq -0x8(%rax), %rcx
movq (%rax), %r15
testq %rcx, %rcx
je 0x1e34
movq 0x60(%rsp), %rdi
movl 0x38(%rcx), %esi
movl 0x3c(%rcx), %edx
movl 0x10(%rax), %ecx
movl 0x14(%rax), %r8d
movl $0xff333333, %r9d       # imm = 0xFF333333
callq 0x22db
testl %eax, %eax
jne 0x1dbd
movq %r15, %rax
cmpq %r14, %r15
jne 0x1e07
incq %rbx
movslq 0x48(%rsp), %rax
cmpq %rax, %rbx
jl 0x1dee
cmpl $0x0, 0x48(%rsp)
jle 0x1fa1
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), %r15
cmpq 0x18(%rsp), %r15
je 0x1f8b
movq %r15, %rbx
movq (%r15), %r15
movl 0x10(%rbx), %r13d
cmpl $-0x1, -0x28(%rbx)
movq 0x60(%rsp), %r14
movl 0x14(%rbx), %ebp
jne 0x1eee
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 0x2810
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x1f7e
addl $-0xb, %r13d
addl $-0x7, %ebp
movq %r14, %rdi
leaq 0x3148(%rip), %rsi      # 0x5023
movl %r13d, %edx
movl %ebp, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq %r12, %r9
jmp 0x1f70
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 0x2458
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x1f7e
movl -0x28(%rbx), %ecx
movl $0x80, %esi
leaq 0x61c0(%rip), %r14      # 0x80f0
movq %r14, %rdi
leaq 0x30ed(%rip), %rdx      # 0x5027
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 0x2a50
negl %eax
movl $0x0, %ecx
sbbl %ecx, %ecx
testl %ecx, %ecx
je 0x1e71
jmp 0x1dbd
movq 0x70(%rsp), %rcx
incq %rcx
movslq 0x48(%rsp), %rax
cmpq %rax, %rcx
jl 0x1e56
movq 0x10(%rsp), %rbx
jmp 0x1dc9