// File: /workspace/github_cpp_makefile_star2_O1/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 0x171f6
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, -0x60(%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, -0x68(%rbp)
movl -0x44(%rbp), %eax
cmpl %eax, -0x30(%rbp)
jle 0x172ce
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rcx
imull %ecx, %edx
leal 0x1(%rcx), %r12d
imull %eax, %r12d
movl %edx, -0x48(%rbp)
movswl %dx, %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %r13d
cmpl -0x4c(%rbp), %r12d
jle 0x172c2
movswq %r13w, %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 0x18a80
incw (%rax)
incl %r15d
movswl %r15w, %eax
cmpl %eax, %r12d
jg 0x17297
incl %r13d
movswl %r13w, %eax
cmpl %eax, -0x30(%rbp)
jg 0x17285
movq -0x88(%rbp), %r13
leaq -0x98(%rbp), %r15
cmpq %r15, %r13
movq -0x60(%rbp), %r15
je 0x17348
movswl 0x24(%r13), %ebx
cmpl %ebx, %r15d
jle 0x17331
leaq 0x20(%r13), %rsi
callq 0x1713e
movl %eax, -0x2c(%rbp)
movb -0x2a(%rbp), %al
cmpb 0x22(%r13), %al
jne 0x1730d
movb 0x23(%r13), %al
cmpb %al, -0x29(%rbp)
je 0x17331
movq %r14, %r12
movq %r14, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x18a80
addw %bx, (%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x19926
movq -0x88(%rbp), %r13
movq %r13, %rdi
callq 0x4260
movq %rax, %r13
leaq -0x98(%rbp), %rax
cmpq %rax, %r13
jne 0x172e5
movq -0x88(%rbp), %r13
leaq -0x98(%rbp), %r15
cmpq %r15, %r13
je 0x1738b
movq %r13, %rdi
callq 0x4260
cmpq %r15, %rax
je 0x1738b
movzwl 0x24(%r13), %ecx
movq %rax, %rbx
cmpw 0x24(%rax), %cx
jl 0x17379
movq %r13, %rbx
movq %rax, %rdi
callq 0x4260
movq %rbx, %r13
cmpq %r15, %rax
jne 0x17368
jmp 0x1738e
movq %r13, %rbx
movl 0x20(%rbx), %eax
movl %eax, -0x2c(%rbp)
movb -0x29(%rbp), %al
movq -0x68(%rbp), %rbx
movb %al, (%rbx)
movb -0x2a(%rbp), %al
movb %al, 0x1(%rbx)
addq $0x2, %rbx
movq %r14, %rdi
callq 0x1996c
movq -0x38(%rbp), %rax
incl %eax
movq %rax, -0x38(%rbp)
cmpl $0x17, %eax
jne 0x17257
movl -0x3c(%rbp), %eax
cmpl $0x17, %eax
movq -0x58(%rbp), %rsi
jne 0x17236
leaq -0xa0(%rbp), %rdi
callq 0x18aea
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x173ef
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x18aea
movq %rbx, %rdi
callq 0x4750