// File: /workspace/github_c_makefile_star2_O2/veltzer[P]xmeltdown/src/xmeltdown.c
// Function: do_planes
void do_planes() {
	int over=0;
	int finished=0;
	int width, xloc, yloc, dist, size, i;
	short** heights;

	heights=(short **) malloc(DisplayPlanes(dpy, screen));
	for (i=0; i < DisplayPlanes(dpy, screen); i++) {
		heights[i]=(short *) calloc(sizeof(short),
			DisplayWidth(dpy, screen));
	}
	while (!over) {
		depth=rnd(DisplayPlanes(dpy, screen));
		width=rnd(MIN_WIDTH)+WIDTH_ADD;

		xloc=calc_xloc(width);

		yloc=DisplayHeight(dpy, screen);
		for (i=xloc; i < (xloc+width); i++) {
			yloc=min(yloc, heights[depth][i]);
		}
		if (yloc == DisplayHeight(dpy, screen))
			continue;
		dist=rnd(yloc/10+MIN_DIST);
		size=rnd(max(yloc+MIN_SIZE, MAX_SIZE));

		XSetPlaneMask(dpy, copygc, 1<<depth);
		XSetPlaneMask(dpy, fillgc, 1<<depth);
		XCopyArea(dpy, win, win, copygc,
			xloc, yloc,
			width, size,
			xloc, yloc+dist);
		XFillRectangle(dpy, win, fillgc,
			xloc, yloc,
			width, dist);
		yloc+=dist;
		for (i=xloc; i < (xloc+width); i++) {
			if ((heights[depth][i] < (DisplayHeight(dpy, screen)-MIN_SIZE)) && (yloc >= (DisplayHeight(dpy, screen)-MIN_SIZE)))
				finished++;
			heights[depth][i]=max(heights[depth][i], yloc);
		}
		if (finished >= (DisplayWidth(dpy, screen)-FINISHED)) {
			XSync(dpy, 0);
			over=1;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x2c47(%rip), %rax      # 0x40c0
movq 0xe8(%rax), %rax
movslq 0x2c41(%rip), %rcx      # 0x40c8
shlq $0x7, %rcx
leaq (%rax,%rcx), %r15
addq $0x18, %r15
movslq 0x20(%r15), %r14
movq %r14, %rdi
callq 0x1050
movq %rax, %rbx
xorl %r12d, %r12d
testl %r14d, %r14d
movl $0x0, %r13d
cmovgl %r14d, %r13d
pushq $0x2
popq %r14
cmpq %r12, %r13
je 0x14cf
movslq (%r15), %rsi
movq %r14, %rdi
callq 0x1110
movq %rax, (%rbx,%r12,8)
incq %r12
jmp 0x14b6
movb $0x1, %bpl
movl $0x0, 0xc(%rsp)
pushq $0x1e
popq %r14
testb $0x1, %bpl
je 0x171c
callq 0x1130
movq 0x2bcc(%rip), %rcx      # 0x40c0
movq 0xe8(%rcx), %rcx
movslq 0x2bc6(%rip), %rdx      # 0x40c8
shlq $0x7, %rdx
movslq 0x38(%rcx,%rdx), %rcx
cqto
idivq %rcx
movl %edx, 0x2bd2(%rip)      # 0x40e8
callq 0x1130
cqto
idivq %r14
movq %rdx, %r12
leal 0x14(%rdx), %edi
movq %rdi, 0x18(%rsp)
callq 0x172b
movl %eax, %r15d
movq 0x2b86(%rip), %rax      # 0x40c0
movq 0xe8(%rax), %rax
movslq 0x2b80(%rip), %rcx      # 0x40c8
shlq $0x7, %rcx
movl 0x1c(%rax,%rcx), %eax
leal (%r12,%r15), %edx
addl $0x14, %edx
movslq 0x2b8a(%rip), %rcx      # 0x40e8
movslq %r15d, %r13
movslq %edx, %rbp
movq %r13, %rdx
movl %eax, %r12d
cmpq %rbp, %rdx
jge 0x1583
movq (%rbx,%rcx,8), %rsi
movswl (%rsi,%rdx,2), %esi
cmpl %esi, %r12d
cmovgel %esi, %r12d
incq %rdx
jmp 0x156a
cmpl %eax, %r12d
je 0x14e8
callq 0x1130
movq %rax, %rcx
movl %r12d, %eax
cltd
pushq $0xa
popq %rsi
idivl %esi
addl $0x2, %eax
movslq %eax, %rsi
movq %rcx, %rax
cqto
idivq %rsi
movq %rdx, 0x10(%rsp)
callq 0x1130
cmpl $0x5b, %r12d
pushq $0x5a
popq %rcx
cmovgel %r12d, %ecx
addl $0xa, %ecx
cqto
idivq %rcx
movq %rdx, 0x20(%rsp)
movb 0x2b15(%rip), %cl       # 0x40e8
pushq $0x1
popq %r14
movl %r14d, %eax
shll %cl, %eax
movq 0x2add(%rip), %rdi      # 0x40c0
movq 0x2aee(%rip), %rsi      # 0x40d8
movslq %eax, %rdx
callq 0x1120
movq 0x2ac7(%rip), %rdi      # 0x40c0
movq 0x2ae0(%rip), %rsi      # 0x40e0
movb 0x2ae2(%rip), %cl       # 0x40e8
movl %r14d, %eax
shll %cl, %eax
movslq %eax, %rdx
callq 0x1120
movq 0x2aa6(%rip), %rdi      # 0x40c0
movq 0x2aaf(%rip), %rdx      # 0x40d0
movq 0x2ab0(%rip), %rcx      # 0x40d8
movq 0x10(%rsp), %rax
leal (%r12,%rax), %r14d
movq %rdx, %rsi
movl %r15d, %r8d
movl %r12d, %r9d
pushq %r14
pushq %r15
pushq 0x30(%rsp)
pushq 0x30(%rsp)
callq 0x10a0
addq $0x20, %rsp
movq 0x2a6a(%rip), %rdi      # 0x40c0
movq 0x2a73(%rip), %rsi      # 0x40d0
movq 0x2a7c(%rip), %rdx      # 0x40e0
subq $0x8, %rsp
movl %r15d, %ecx
movl %r12d, %r8d
movq 0x20(%rsp), %r9
pushq 0x18(%rsp)
callq 0x10b0
addq $0x10, %rsp
movslq 0x2a61(%rip), %rcx      # 0x40e8
movq 0x2a32(%rip), %rdi      # 0x40c0
movslq 0x2a33(%rip), %rax      # 0x40c8
movl 0xc(%rsp), %r10d
cmpq %rbp, %r13
jge 0x16e8
movq (%rbx,%rcx,8), %rdx
movswl (%rdx,%r13,2), %esi
movq 0xe8(%rdi), %r8
movq %rax, %r9
shlq $0x7, %r9
movl 0x1c(%r8,%r9), %r8d
addl $-0xa, %r8d
cmpl %esi, %r8d
setg %r9b
cmpl %r8d, %r14d
setge %r8b
andb %r9b, %r8b
movzbl %r8b, %r8d
addl %r8d, %r10d
cmpl %esi, %r14d
cmovgel %r14d, %esi
movw %si, (%rdx,%r13,2)
incq %r13
jmp 0x169a
movq 0xe8(%rdi), %rcx
shlq $0x7, %rax
movl 0x18(%rcx,%rax), %eax
addl $-0x32, %eax
movl %r10d, 0xc(%rsp)
cmpl %eax, %r10d
setl %bpl
pushq $0x1e
popq %r14
jl 0x14de
xorl %esi, %esi
callq 0x1100
jmp 0x14de
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq