// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/map.cpp
// Function: Map::gen_miniview(char*) const
void Map::gen_miniview(char *target) const
{
	short x, y, ax, ay, F;
	map<Tile, short> amounts;
	map<Tile, short>::iterator it;
	Tile t;
	
	// sample F*F map tiles for each miniview tile
	F = mapsize/VIEWSIZE + 1;
	while(VIEWSIZE*F >= mapsize)
		--F;

	for(y = 0; y < VIEWSIZE; ++y)
	{
		for(x = 0; x < VIEWSIZE; ++x)
		{
			// collect tile amounts in this area:
			for(ay = y*F; ay < (y+1)*F; ++ay)
			{
				for(ax = x*F; ax < (x+1)*F; ++ax)
					amounts[data[ay][ax]]++;
			}
			// Do some reduction. Think of this as a "crude sinc filter"
			for(it = amounts.begin(); it != amounts.end(); ++it)
			{
				// The reference value here is the fact that there are a total
				// of F*F tiles!
				if(it->second < 5*F*F/24
					&& (t = subsample_tile(it->first)) != it->first)
				{
					amounts[t] += it->second;
					amounts.erase(it);
					it = amounts.begin(); // start over!
				}
			}
			// now just represent this area by the most common tile:
			t = max_element(amounts.begin(), amounts.end(), pred)->first;
			*(target++) = t.cpair;
			*(target++) = t.symbol;
			amounts.clear();
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
leaq -0x98(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %rdi, -0x70(%rbp)
movswl (%rdi), %eax
imull $0xffffb217, %eax, %ecx # imm = 0xFFFFB217
shrl $0x10, %ecx
addl %eax, %ecx
movswl %cx, %ecx
movzwl %cx, %edx
sarl $0x4, %ecx
shrl $0xf, %edx
addl %edx, %ecx
addl $0x2, %ecx
decl %ecx
movswl %cx, %esi
leal (%rsi,%rsi,2), %edx
shll $0x3, %edx
subl %esi, %edx
cmpl %eax, %edx
jge 0x170ce
movl %esi, %eax
imull %eax, %eax
leal (%rax,%rax,4), %eax
cltq
imulq $0x2aaaaaab, %rax, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x22, %rcx
addl %eax, %ecx
movq %rcx, -0x68(%rbp)
xorl %eax, %eax
leaq -0xa0(%rbp), %r14
movq %rsi, -0x58(%rbp)
movl %esi, %ecx
imull %eax, %ecx
incl %eax
movl %eax, -0x3c(%rbp)
imull %esi, %eax
movl %eax, -0x30(%rbp)
movl %ecx, -0x40(%rbp)
movswl %cx, %eax
movl %eax, -0x44(%rbp)
movq $0x0, -0x38(%rbp)
movq %rbx, -0x60(%rbp)
movl -0x44(%rbp), %eax
cmpl %eax, -0x30(%rbp)
jle 0x171a6
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rcx
imull %ecx, %edx
leal 0x1(%rcx), %r13d
imull %eax, %r13d
movl %edx, -0x48(%rbp)
movswl %dx, %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %r12d
cmpl -0x4c(%rbp), %r13d
jle 0x1719a
movswq %r12w, %rax
leaq (%rax,%rax,2), %rbx
movl -0x48(%rbp), %r15d
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movswq %r15w, %rsi
shlq $0x2, %rsi
addq (%rax,%rbx,8), %rsi
movq %r14, %rdi
callq 0x18950
incw (%rax)
incl %r15d
movswl %r15w, %eax
cmpl %eax, %r13d
jg 0x1716f
incl %r12d
movswl %r12w, %eax
cmpl %eax, -0x30(%rbp)
jg 0x1715d
movq -0x88(%rbp), %r12
leaq -0x98(%rbp), %r15
cmpq %r15, %r12
je 0x1721d
movq %r12, %r13
movswl 0x24(%r13), %ebx
cmpl %ebx, -0x68(%rbp)
jle 0x1720d
leaq 0x20(%r13), %rsi
callq 0x17016
movl %eax, -0x2c(%rbp)
movl %eax, %ecx
shrl $0x10, %ecx
cmpb %cl, 0x22(%r13)
jne 0x171e6
shrl $0x18, %eax
cmpb %al, 0x23(%r13)
je 0x1720d
movq %r14, %r12
movq %r14, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x18950
addw %bx, (%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x197f2
movq -0x88(%rbp), %r12
movq %r12, %r13
movq %r13, %rdi
callq 0x4260
movq %rax, %r13
cmpq %r15, %rax
jne 0x171bc
cmpq %r15, %r12
je 0x17253
movq %r12, %rdi
callq 0x4260
cmpq %r15, %rax
je 0x17253
movzwl 0x24(%r12), %ecx
movq %rax, %rbx
cmpw 0x24(%rax), %cx
jl 0x17241
movq %r12, %rbx
movq %rax, %rdi
callq 0x4260
movq %rbx, %r12
cmpq %r15, %rax
jne 0x1722f
jmp 0x17256
movq %r12, %rbx
movl 0x20(%rbx), %eax
movl %eax, -0x2c(%rbp)
shrl $0x18, %eax
movq -0x60(%rbp), %rbx
movb %al, (%rbx)
movb -0x2a(%rbp), %al
movb %al, 0x1(%rbx)
addq $0x2, %rbx
movq %r14, %rdi
callq 0x19838
movq -0x38(%rbp), %rax
incl %eax
movq %rax, -0x38(%rbp)
cmpl $0x17, %eax
jne 0x1712f
movl -0x3c(%rbp), %eax
cmpl $0x17, %eax
movq -0x58(%rbp), %rsi
jne 0x1710e
leaq -0xa0(%rbp), %rdi
callq 0x189ba
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x172b7
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x189ba
movq %rbx, %rdi
callq 0x4740