// File: /workspace/github_c_makefile_star2_O1/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
movl $0x11, %eax
subl %esi, %eax
shll $0x4, %eax
leal (%rax,%rax,2), %eax
movl %eax, 0x4(%rsp)
imull $0x56100, %edx, %ecx    # imm = 0x56100
shll $0x4, %edx
leal (%rdx,%rdx,2), %eax
movq %rax, 0x10(%rsp)
leal (%rdx,%rdx,8), %r9d
shll $0x4, %esi
leal (%rsi,%rsi,8), %eax
movl $0xa23, %edx            # imm = 0xA23
subl %eax, %edx
movl %edx, (%rsp)
subl %eax, %ecx
leal 0xa20(%rcx), %edx
leaq 0x2(%rdx), %r13
addl $0x1d40, %ecx           # imm = 0x1D40
xorl %esi, %esi
movq %r8, 0x30(%rsp)
movl %r9d, %r9d
movq 0x10(%rsp), %rax
addl %esi, %eax
leal (%rax,%rax,2), %ebp
leal 0x3(%rax,%rax,2), %ebx
movq %rcx, 0x28(%rsp)
movl %ecx, %r10d
movq %rdx, 0x20(%rsp)
movq %rdx, %r11
movq %r13, 0x18(%rsp)
xorl %edx, %edx
movl (%rsp), %r12d
movq %rsi, 0x38(%rsp)
movl %ebp, 0x8(%rsp)
movq %rdx, 0x40(%rsp)
movl %r10d, 0xc(%rsp)
movq %r8, %rdi
movq %r9, %r15
movq %r11, %rbp
callq 0x138d
movq %rbp, %r11
movl 0x8(%rsp), %ebp
movq %r15, %r9
movq 0x40(%rsp), %rdx
movl 0x4(%rsp), %ecx
movl %ecx, %esi
subl %edx, %esi
leal (%rsi,%rsi,2), %ecx
addl $0x90, %ecx
leal (%rsi,%rsi,2), %esi
addl $0x93, %esi
cmpl %esi, %ecx
jae 0x153e
movl %r11d, %r10d
cmpl $-0x4, %ebp
ja 0x1534
movl %r10d, %esi
movq %r9, %rdi
movl %esi, %r8d
movl %eax, (%r14,%r8,4)
incq %rdi
addl $0x990, %esi            # imm = 0x990
cmpq %rbx, %rdi
jb 0x151f
incl %ecx
incl %r10d
cmpl %r12d, %ecx
jne 0x1514
leaq (%rdx,%rdx,2), %rax
shlq $0x4, %rax
movq 0x38(%rsp), %rsi
addq %rsi, %rax
movq 0x30(%rsp), %r8
cmpb $0x0, 0x6c00(%r8,%rax)
movl 0xc(%rsp), %r10d
je 0x1581
xorl %eax, %eax
leal (%rax,%r13), %ecx
movl $0x636363, (%r14,%rcx,4) # imm = 0x636363
addq $0x990, %rax            # imm = 0x990
cmpq $0x1cb0, %rax           # imm = 0x1CB0
jne 0x1565
jmp 0x15a3
cmpb $0x0, 0x4800(%r8,%rax)
je 0x15c2
xorl %eax, %eax
leal (%r11,%rax), %ecx
movl $0x636363, (%r14,%rcx,4) # imm = 0x636363
incq %rax
cmpq $0x3, %rax
jne 0x158e
incq %rdx
addl $-0x3, %r12d
addq $-0x3, %r11
addq $-0x3, %r13
addl $-0x3, %r10d
cmpq $0x30, %rdx
jne 0x14cc
jmp 0x1628
movzwl 0x9000(%r8,%rax,2), %eax
testw %ax, %ax
je 0x15a3
movzwl %ax, %eax
cmpl $0x2edf, %eax           # imm = 0x2EDF
ja 0x15fc
movl $0x3, %eax
movl %r10d, %ecx
movl %ecx, %r15d
leal 0x636362(%rax), %edi
movl %edi, (%r14,%r15,4)
addl $0xfffff671, %ecx       # imm = 0xFFFFF671
decq %rax
jne 0x15e2
jmp 0x15a3
cmpl $0x5dbf, %eax           # imm = 0x5DBF
ja 0x15a3
movl $0x3, %eax
movl %r10d, %ecx
movl %ecx, %r15d
leal 0x636362(%rax), %edi
movl %edi, (%r14,%r15,4)
addl $0xfffff671, %ecx       # imm = 0xFFFFF671
decq %rax
jne 0x160b
jmp 0x15a3
incq %rsi
addl $0x3, %r9d
movq 0x18(%rsp), %r13
movl $0x1cb0, %eax           # imm = 0x1CB0
addq %rax, %r13
movq 0x20(%rsp), %rdx
addq %rax, %rdx
movq 0x28(%rsp), %rcx
addl $0x1cb0, %ecx           # imm = 0x1CB0
cmpq $0x30, %rsi
jne 0x1497
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq