// File: /workspace/github_c_makefile_star2_O2/cath-mawr[P]rscmapgen/mapdump.c
// Function: write_chunk
int
write_chunk(uint32_t *pixels, unsigned chunkx, unsigned chunky, const struct chunk *c)
{
	unsigned x, y;
	unsigned ox, oy;
	unsigned dx, dy;
	unsigned pos;
	unsigned i;
	uint32_t colour;

	for (x = 0; x < CHUNKSIZE; ++x) {
		for (y = 0; y < CHUNKSIZE; ++y) {
			colour = get_tile_colour(c, x, y);
			/*ox = ((MAPSIZE - chunkx) * CHUNKSIZE) + (CHUNKSIZE - y);
			oy = (chunky * CHUNKSIZE) + x;*/

			/*pixels[ox + oy * XSIZE] = colour;*/

			ox = (((MAPSIZE - chunkx) * CHUNKSIZE) + (CHUNKSIZE - y)) * TILESIZE;
			oy = ((chunky * CHUNKSIZE) + x) * TILESIZE;
			pos = x + y * CHUNKSIZE;

			for (dx = ox; dx < (ox + TILESIZE); ++dx) {
				for (dy = oy; dy < (oy + TILESIZE); ++dy) {
					pixels[dx + dy * XSIZE] = colour;
				}
			}

			if (c->h_boundaries[0][pos] != 0) {
				/* vertical */
				if (x > 0 && c->overlays[(x - 1) + y * CHUNKSIZE] == 0) {
					for (i = 0; i < TILESIZE; ++i) {
						pixels[(ox - (TILESIZE - 1)) + (oy + i) * XSIZE] = 0x636363;
					}
				} else if (x < CHUNKSIZE) {
					for (i = 0; i < TILESIZE; ++i) {
						pixels[(ox + (TILESIZE - 1)) + (oy + i) * XSIZE] = 0x636363;
					}
				}
			} else if (c->v_boundaries[0][pos] != 0) {
				/* horizontal */
				for (i = 0; i < TILESIZE; ++i) {
					pixels[(ox + i) + oy * XSIZE] = 0x636363;
				}
			} else if (c->d_boundaries[0][pos] != 0) {
				if (c->d_boundaries[0][pos] < 12000) {
					/*pixels[(ox + 0) + (oy + 1) * XSIZE] = 0x636363;
					pixels[(ox + 1) + (oy + 0) * XSIZE] = 0x636363;*/
					for (i = (TILESIZE - 1); i != UINT_MAX; --i) {
						pixels[(ox + (TILESIZE - 1) - i) + (oy + i) * XSIZE] = 0x636363 + i;
					}
				} else if (c->d_boundaries[0][pos] < 24000) {
					for (i = (TILESIZE - 1); i != UINT_MAX; --i) {
						pixels[(ox + (TILESIZE - 1) - i) + (oy + i) * XSIZE] = 0x636363 + i;
					}
				}
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r8
movq %rdi, %r14
pushq $0x11
popq %rax
subl %esi, %eax
imull $0x30, %eax, %eax
movl %eax, 0xc(%rsp)
imull $0x30, %edx, %eax
movq %rax, 0x18(%rsp)
imull $0x90, %edx, %r13d
imull $0x56100, %edx, %ecx    # imm = 0x56100
imull $0x90, %esi, %eax
subl %eax, %ecx
leal 0xa20(%rcx), %ebx
leaq 0x2(%rbx), %r15
xorl %esi, %esi
movq %r8, 0x38(%rsp)
cmpq $0x30, %rsi
je 0x160f
movl %r13d, %r13d
movq 0x18(%rsp), %rax
addl %esi, %eax
leal 0x3(%rax,%rax,2), %ebp
movq %rcx, 0x30(%rsp)
movl %ecx, %r9d
movq %rbx, 0x28(%rsp)
movq %r15, 0x20(%rsp)
xorl %r12d, %r12d
movq %rsi, 0x40(%rsp)
cmpq $0x30, %r12
je 0x15e3
movq %r9, 0x10(%rsp)
movq %r8, %rdi
movl %r12d, %edx
callq 0x137b
movl 0xc(%rsp), %ecx
movl %ecx, %esi
subl %r12d, %esi
leal (%rsi,%rsi,2), %edx
addl $0x90, %edx
imulq $0x30, %r12, %rcx
leal (%rsi,%rsi,2), %esi
addl $0x93, %esi
movl %ebx, %edi
cmpl %esi, %edx
jae 0x1502
movl %edi, %r8d
movq %r13, %r9
cmpq %rbp, %r9
jae 0x14fc
movl %r8d, %r10d
movl %eax, (%r14,%r10,4)
incq %r9
addl $0x990, %r8d            # imm = 0x990
jmp 0x14e4
incl %edx
incl %edi
jmp 0x14da
movq 0x40(%rsp), %rsi
addq %rsi, %rcx
movq 0x38(%rsp), %r8
cmpb $0x0, 0x6c00(%r8,%rcx)
je 0x1541
xorl %eax, %eax
movq 0x10(%rsp), %r9
cmpq $0x1cb0, %rax           # imm = 0x1CB0
je 0x15cf
leal (%r15,%rax), %ecx
movl $0x636363, (%r14,%rcx,4) # imm = 0x636363
addq $0x990, %rax            # imm = 0x990
jmp 0x1521
cmpb $0x0, 0x4800(%r8,%rcx)
movq 0x10(%rsp), %r9
je 0x1569
xorl %eax, %eax
cmpq $0x3, %rax
je 0x15cf
leal (%rbx,%rax), %ecx
movl $0x636363, (%r14,%rcx,4) # imm = 0x636363
incq %rax
jmp 0x1553
movzwl 0x9000(%r8,%rcx,2), %eax
testw %ax, %ax
je 0x15cf
cmpw $0x2edf, %ax            # imm = 0x2EDF
ja 0x15a3
movl $0x1d40, %eax           # imm = 0x1D40
pushq $0x2
popq %rcx
cmpl $0x93, %eax
je 0x15cf
leal 0x636363(%rcx), %edx
leal (%r9,%rax), %edi
movl %edx, (%r14,%rdi,4)
decl %ecx
addl $0xfffff671, %eax       # imm = 0xFFFFF671
jmp 0x1585
cmpw $0x5dbf, %ax            # imm = 0x5DBF
ja 0x15cf
movl $0x1d40, %eax           # imm = 0x1D40
pushq $0x2
popq %rcx
cmpl $0x93, %eax
je 0x15cf
leal 0x636363(%rcx), %edx
leal (%r9,%rax), %edi
movl %edx, (%r14,%rdi,4)
decl %ecx
addl $0xfffff671, %eax       # imm = 0xFFFFF671
jmp 0x15b1
incq %r12
addq $-0x3, %rbx
addq $-0x3, %r15
addl $-0x3, %r9d
jmp 0x149f
incq %rsi
addl $0x3, %r13d
movq 0x20(%rsp), %r15
movl $0x1cb0, %eax           # imm = 0x1CB0
addq %rax, %r15
movq 0x28(%rsp), %rbx
addq %rax, %rbx
movq 0x30(%rsp), %rcx
addl $0x1cb0, %ecx           # imm = 0x1CB0
jmp 0x146d
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq