// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x30, -0x1c(%rbp)
jae 0x186c
movl $0x0, -0x20(%rbp)
cmpl $0x30, -0x20(%rbp)
jae 0x185c
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x1410
movl %eax, -0x3c(%rbp)
movl $0x11, %eax
subl -0xc(%rbp), %eax
imull $0x30, %eax, %eax
movl $0x30, %ecx
subl -0x20(%rbp), %ecx
addl %ecx, %eax
imull $0x3, %eax, %eax
movl %eax, -0x24(%rbp)
imull $0x30, -0x10(%rbp), %eax
addl -0x1c(%rbp), %eax
imull $0x3, %eax, %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
imull $0x30, -0x20(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x24(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jae 0x1664
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jae 0x1657
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
imull $0x990, -0x30(%rbp), %esi # imm = 0x990
addl %esi, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1627
jmp 0x1659
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1614
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movzbl 0x6c00(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x172d
cmpl $0x0, -0x1c(%rbp)
jbe 0x16e5
movq -0x18(%rbp), %rax
addq $0xfc00, %rax           # imm = 0xFC00
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
imull $0x30, -0x20(%rbp), %edx
addl %edx, %ecx
movl %ecx, %ecx
imulq $0x900, %rcx, %rcx      # imm = 0x900
addq %rcx, %rax
cmpq $0x0, %rax
jne 0x16e5
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jae 0x16e3
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
subl $0x2, %ecx
movl -0x28(%rbp), %edx
addl -0x38(%rbp), %edx
imull $0x990, %edx, %edx      # imm = 0x990
addl %edx, %ecx
movl %ecx, %ecx
movl $0x636363, (%rax,%rcx,4) # imm = 0x636363
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x16b1
jmp 0x1728
cmpl $0x30, -0x1c(%rbp)
jae 0x1726
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jae 0x1724
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
movl -0x28(%rbp), %edx
addl -0x38(%rbp), %edx
imull $0x990, %edx, %edx      # imm = 0x990
addl %edx, %ecx
movl %ecx, %ecx
movl $0x636363, (%rax,%rcx,4) # imm = 0x636363
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x16f2
jmp 0x1726
jmp 0x1728
jmp 0x184c
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movzbl 0x4800(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x177a
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jae 0x1775
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl -0x38(%rbp), %ecx
imull $0x990, -0x28(%rbp), %edx # imm = 0x990
addl %edx, %ecx
movl %ecx, %ecx
movl $0x636363, (%rax,%rcx,4) # imm = 0x636363
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1748
jmp 0x184a
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movzwl 0x9000(%rax,%rcx,2), %eax
cmpl $0x0, %eax
je 0x1848
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movzwl 0x9000(%rax,%rcx,2), %eax
cmpl $0x2ee0, %eax           # imm = 0x2EE0
jge 0x17eb
movl $0x2, -0x38(%rbp)
cmpl $-0x1, -0x38(%rbp)
je 0x17e9
movl -0x38(%rbp), %edx
addl $0x636363, %edx         # imm = 0x636363
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
subl -0x38(%rbp), %ecx
movl -0x28(%rbp), %esi
addl -0x38(%rbp), %esi
imull $0x990, %esi, %esi      # imm = 0x990
addl %esi, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x17af
jmp 0x1846
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movzwl 0x9000(%rax,%rcx,2), %eax
cmpl $0x5dc0, %eax           # imm = 0x5DC0
jge 0x1844
movl $0x2, -0x38(%rbp)
cmpl $-0x1, -0x38(%rbp)
je 0x1842
movl -0x38(%rbp), %edx
addl $0x636363, %edx         # imm = 0x636363
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
subl -0x38(%rbp), %ecx
movl -0x28(%rbp), %esi
addl -0x38(%rbp), %esi
imull $0x990, %esi, %esi      # imm = 0x990
addl %esi, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1808
jmp 0x1844
jmp 0x1846
jmp 0x1848
jmp 0x184a
jmp 0x184c
jmp 0x184e
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x15be
jmp 0x185e
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x15ad
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)