// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x80(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movswl (%rdi), %ecx
movl %ecx, %eax
cwtd
movw $0x17, %si
idivw %si
addl $0x2, %eax
decl %eax
movswl %ax, %esi
imull $0x17, %esi, %edx
cmpl %ecx, %edx
jge 0x126f9
movl %esi, -0x30(%rbp)
movl %esi, %eax
imull %eax, %eax
leal (%rax,%rax,4), %eax
pushq $0x18
popq %rcx
cltd
idivl %ecx
movl %eax, -0x40(%rbp)
xorl %eax, %eax
leaq -0x88(%rbp), %r13
cmpl $0x17, %eax
je 0x12864
movl %eax, %ecx
movl -0x30(%rbp), %eax
movl %eax, %edx
imull %ecx, %edx
movl %edx, -0x38(%rbp)
incl %ecx
movl %ecx, -0x34(%rbp)
imull %eax, %ecx
movl %ecx, -0x48(%rbp)
xorl %r15d, %r15d
cmpl $0x17, %r15d
je 0x1285c
movq %rbx, -0x58(%rbp)
movl -0x30(%rbp), %eax
movl %eax, %ecx
imull %r15d, %ecx
movl %ecx, -0x44(%rbp)
incl %r15d
movl %r15d, -0x3c(%rbp)
imull %eax, %r15d
movl -0x38(%rbp), %eax
movl %eax, %ecx
movswl %cx, %eax
cmpl %eax, -0x48(%rbp)
jle 0x127b7
movl %ecx, -0x4c(%rbp)
movswq %cx, %rax
imulq $0x18, %rax, %rbx
movl -0x44(%rbp), %r12d
movswl %r12w, %eax
cmpl %eax, %r15d
jle 0x127b0
movq 0x8(%r14), %rax
movswq %r12w, %rsi
shlq $0x2, %rsi
addq (%rax,%rbx), %rsi
movq %r13, %rdi
callq 0x13b32
incw (%rax)
incl %r12d
jmp 0x12787
movl -0x4c(%rbp), %ecx
incl %ecx
jmp 0x12770
movq -0x70(%rbp), %r15
movq %r15, %rbx
leaq -0x80(%rbp), %rax
cmpq %rax, %rbx
je 0x1281f
movswl 0x24(%rbx), %r12d
cmpl %r12d, -0x40(%rbp)
jle 0x12812
leaq 0x20(%rbx), %rsi
callq 0x12656
movl %eax, -0x2c(%rbp)
movl %eax, %ecx
shrl $0x10, %ecx
cmpb %cl, 0x22(%rbx)
jne 0x127f0
shrl $0x18, %eax
cmpb %al, 0x23(%rbx)
je 0x12812
movq %r13, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x13b32
addw %r12w, (%rax)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x14df6
movq -0x70(%rbp), %r15
movq %r15, %rbx
movq %rbx, %rdi
callq 0x4260
movq %rax, %rbx
jmp 0x127be
movq %r15, %rdi
leaq -0x80(%rbp), %rsi
leaq 0x6d(%rip), %rdx        # 0x1289a
callq 0x13d1b
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
shrl $0x18, %eax
movq -0x58(%rbp), %rbx
movb %al, (%rbx)
movb -0x2a(%rbp), %al
movb %al, 0x1(%rbx)
addq $0x2, %rbx
movq %r13, %rdi
callq 0x14e58
movl -0x3c(%rbp), %r15d
jmp 0x12746
movl -0x34(%rbp), %eax
jmp 0x12722
leaq -0x88(%rbp), %rdi
callq 0x13db0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12883
jmp 0x12883
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x13db0
movq %rbx, %rdi
callq 0x4710