// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: owallmost
static int owallmost(short *mostbuf, int w, int z)
{
	int bad, inty, xcross, y, yinc;
	int s1, s2, s3, s4, ix1, ix2, iy1, iy2, t;
	int i;

	z <<= 7;
	s1 = mulscale20(globaluclip,yb1[w]); s2 = mulscale20(globaluclip,yb2[w]);
	s3 = mulscale20(globaldclip,yb1[w]); s4 = mulscale20(globaldclip,yb2[w]);
	bad = (z<s1)+((z<s2)<<1)+((z>s3)<<2)+((z>s4)<<3);

	ix1 = xb1[w]; iy1 = yb1[w];
	ix2 = xb2[w]; iy2 = yb2[w];

	if ((bad&3) == 3)
	{
		//clearbufbyte(&mostbuf[ix1],(ix2-ix1+1)*sizeof(mostbuf[0]),0L);
		for (i=ix1; i<=ix2; i++) mostbuf[i] = 0;
		return(bad);
	}

	if ((bad&12) == 12)
	{
		//clearbufbyte(&mostbuf[ix1],(ix2-ix1+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
		for (i=ix1; i<=ix2; i++) mostbuf[i] = ydimen;
		return(bad);
	}

	if (bad&3)
	{
		t = divscale30(z-s1,s2-s1);
		inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
		xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);

		if ((bad&3) == 2)
		{
			if (xb1[w] <= xcross) { iy2 = inty; ix2 = xcross; }
			//clearbufbyte(&mostbuf[xcross+1],(xb2[w]-xcross)*sizeof(mostbuf[0]),0L);
			for (i=xcross+1; i<=xb2[w]; i++) mostbuf[i] = 0;
		}
		else
		{
			if (xcross <= xb2[w]) { iy1 = inty; ix1 = xcross; }
			//clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),0L);
			for (i=xb1[w]; i<=xcross; i++) mostbuf[i] = 0;
		}
	}

	if (bad&12)
	{
		t = divscale30(z-s3,s4-s3);
		inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
		xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);

		if ((bad&12) == 8)
		{
			if (xb1[w] <= xcross) { iy2 = inty; ix2 = xcross; }
			//clearbufbyte(&mostbuf[xcross+1],(xb2[w]-xcross)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
			for (i=xcross+1; i<=xb2[w]; i++) mostbuf[i] = ydimen;
		}
		else
		{
			if (xcross <= xb2[w]) { iy1 = inty; ix1 = xcross; }
			//clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
			for (i=xb1[w]; i<=xcross; i++) mostbuf[i] = ydimen;
		}
	}

	y = (scale(z,xdimenscale,iy1)<<4);
	yinc = ((scale(z,xdimenscale,iy2)<<4)-y) / (ix2-ix1+1);
	qinterpolatedown16short(&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);

	if (mostbuf[ix1] < 0) mostbuf[ix1] = 0;
	if (mostbuf[ix1] > ydimen) mostbuf[ix1] = ydimen;
	if (mostbuf[ix2] < 0) mostbuf[ix2] = 0;
	if (mostbuf[ix2] > ydimen) mostbuf[ix2] = ydimen;

	return(bad);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %r14d
shll $0x7, %r14d
movslq 0x24ef05(%rip), %rdx    # 0x273a80
movslq %esi, %r15
leaq 0x24ef0b(%rip), %rax    # 0x273a90
movslq (%rax,%r15,4), %rsi
movq %rsi, %rax
imulq %rdx, %rax
shrq $0x14, %rax
leaq 0x252ef5(%rip), %rcx    # 0x277a90
movl (%rcx,%r15,4), %r8d
movslq %r8d, %rbx
imulq %rbx, %rdx
shrq $0x14, %rdx
movslq 0x256edf(%rip), %r12    # 0x27ba90
movq %r12, %rbp
movq %rsi, 0x8(%rsp)
imulq %rsi, %rbp
shrq $0x14, %rbp
imulq %rbx, %r12
shrq $0x14, %r12
xorl %ecx, %ecx
movl %r14d, %esi
subl %eax, %esi
setl %cl
xorl %r9d, %r9d
cmpl %edx, %r14d
setl %r9b
leal (%rcx,%r9,2), %r10d
xorl %ecx, %ecx
movl %r14d, %r9d
subl %ebp, %r9d
movl %r9d, 0x2c(%rsp)
setg %cl
xorl %r9d, %r9d
cmpl %r12d, %r14d
setg %r9b
shll $0x3, %r9d
leal (%r9,%rcx,4), %r11d
leaq 0x24ae76(%rip), %rcx    # 0x26fa80
movl (%rcx,%r15,4), %r13d
leaq 0x246e5b(%rip), %rcx    # 0x26ba70
movl (%rcx,%r15,4), %r9d
movslq %r9d, %rcx
cmpl $0x3, %r10d
jne 0x24c4f
subl %r9d, %r13d
jl 0x24f89
leaq (%rdi,%rcx,2), %rdi
leaq 0x2(,%r13,2), %rdx
xorl %esi, %esi
movl %r10d, %ebx
movl %r11d, %ebp
callq 0x62f0
movl %ebp, %r11d
movl %ebx, %r10d
jmp 0x24f89
cmpl $0xc, %r11d
jne 0x24c7f
subl %r9d, %r13d
jl 0x24f89
leaq (%rdi,%rcx,2), %rax
incl %r13d
xorl %ecx, %ecx
movzwl 0x256e26(%rip), %edx    # 0x27ba94
movw %dx, (%rax,%rcx,2)
incq %rcx
cmpl %ecx, %r13d
jne 0x24c67
jmp 0x24f89
testl %r10d, %r10d
movq %rdi, 0x30(%rsp)
je 0x24d34
movl %r8d, 0x10(%rsp)
subl %eax, %edx
movslq %esi, %rax
shlq $0x1e, %rax
movslq %edx, %rsi
cqto
idivq %rsi
movl %ebx, %edx
movq 0x8(%rsp), %rsi
subl %esi, %edx
movslq %edx, %r8
cltq
imulq %rax, %r8
shrq $0x1e, %r8
addl %esi, %r8d
movl %r13d, %edx
subl %r9d, %edx
imulq %rbx, %rax
shrq $0x1e, %rax
movslq %eax, %rsi
movslq %edx, %rax
imulq %rsi, %rax
movslq %r8d, %rsi
cqto
idivq %rsi
leal (%r9,%rax), %edx
cmpl $0x2, %r10d
jne 0x24d46
testl %eax, %eax
movl %edx, %ecx
cmovsl %r13d, %ecx
movl %ecx, 0x4(%rsp)
cmovsl 0x10(%rsp), %r8d
cmpl %r13d, %edx
jge 0x24dbe
movl %r11d, 0x24(%rsp)
movl %r10d, 0x28(%rsp)
movslq %edx, %rcx
leaq (%rdi,%rcx,2), %rdi
addq $0x2, %rdi
movq %r9, 0x18(%rsp)
movl %r9d, %edx
notl %edx
addl %r13d, %edx
subl %eax, %edx
movq 0x8(%rsp), %rax
movl %eax, (%rsp)
movq %r8, 0x10(%rsp)
jmp 0x24d8a
movl %r13d, 0x4(%rsp)
movq 0x8(%rsp), %rsi
movl %esi, (%rsp)
jmp 0x24dde
cmpl %r13d, %edx
movl %edx, %esi
cmovgl %r9d, %esi
cmovgl 0x8(%rsp), %r8d
testl %eax, %eax
js 0x24dc8
movl %r11d, 0x24(%rsp)
movl %r10d, 0x28(%rsp)
leaq (%rdi,%rcx,2), %rdi
cmpl %edx, %r9d
cmovgl %r9d, %edx
subl %r9d, %edx
movl %esi, %eax
movq %rax, 0x18(%rsp)
movl %r13d, 0x4(%rsp)
movl %r8d, (%rsp)
movl 0x10(%rsp), %eax
movq %rax, 0x10(%rsp)
movl %edx, %eax
leaq 0x2(,%rax,2), %rdx
xorl %esi, %esi
callq 0x62f0
movq 0x10(%rsp), %rax
movl %eax, %r8d
movq 0x30(%rsp), %rdi
movl 0x28(%rsp), %r10d
movl 0x24(%rsp), %r11d
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rsi
jmp 0x24dde
movq 0x8(%rsp), %rsi
movl %esi, (%rsp)
jmp 0x24dde
movl %esi, %r9d
movl %r13d, 0x4(%rsp)
movl %r8d, (%rsp)
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %r8d
testl %r11d, %r11d
je 0x24e85
movq %r9, 0x18(%rsp)
subl %ebp, %r12d
movslq 0x2c(%rsp), %rax
shlq $0x1e, %rax
movslq %r12d, %rcx
cqto
idivq %rcx
movl %ebx, %ecx
subl %esi, %ecx
movslq %ecx, %rcx
cltq
imulq %rax, %rcx
shrq $0x1e, %rcx
addl %esi, %ecx
leaq 0x246c56(%rip), %rdx    # 0x26ba70
movslq (%rdx,%r15,4), %rsi
movl %r13d, %edx
subl %esi, %edx
imulq %rax, %rbx
shrq $0x1e, %rbx
movslq %ebx, %r9
movslq %edx, %rax
imulq %r9, %rax
movslq %ecx, %r9
cqto
idivq %r9
leal (%rsi,%rax), %edx
cmpl $0x8, %r11d
jne 0x24e96
testl %eax, %eax
movl 0x4(%rsp), %r15d
cmovnsl %edx, %r15d
cmovnsl %ecx, %r8d
cmpl %r13d, %edx
movq 0x18(%rsp), %r9
movl (%rsp), %r12d
jge 0x24ed9
movl %r11d, %ebp
movl %r10d, %ebx
movslq %r13d, %rax
movslq %edx, %rcx
movzwl 0x256c1e(%rip), %edx    # 0x27ba94
movw %dx, 0x2(%rdi,%rcx,2)
incq %rcx
cmpq %rax, %rcx
jl 0x24e6f
jmp 0x24edf
movl %r11d, %ebp
movl %r10d, %ebx
movl 0x4(%rsp), %r15d
movl (%rsp), %r12d
jmp 0x24edf
cmpl %r13d, %edx
movq 0x18(%rsp), %r9
cmovlel %edx, %r9d
movl (%rsp), %r12d
cmovlel %ecx, %r12d
testl %eax, %eax
movl 0x4(%rsp), %r15d
js 0x24ed9
movl %r11d, %ebp
cmpl %edx, %esi
cmovgl %esi, %edx
leaq (%rdi,%rsi,2), %rax
subl %esi, %edx
incl %edx
xorl %ecx, %ecx
movzwl 0x256bc8(%rip), %esi    # 0x27ba94
movw %si, (%rax,%rcx,2)
incq %rcx
cmpl %ecx, %edx
jne 0x24ec5
jmp 0x24edc
movl %r11d, %ebp
movl %r10d, %ebx
movslq 0x256bb2(%rip), %rax    # 0x27ba98
movslq %r14d, %rcx
imulq %rax, %rcx
movslq %r12d, %rsi
movq %rcx, %rax
cqto
idivq %rsi
movq %rax, %rsi
movslq %r8d, %r8
movq %rcx, %rax
cqto
idivq %r8
subl %esi, %eax
movl %esi, %ecx
shll $0x4, %ecx
shll $0x4, %eax
movl %r15d, %esi
subl %r9d, %esi
incl %esi
cltd
idivl %esi
movslq %r9d, %rdx
leaq (%rdi,%rdx,2), %r14
movl 0x256b74(%rip), %edx    # 0x27ba9c
shll $0x10, %edx
addl %ecx, %edx
movq %r14, %rdi
movl %eax, %ecx
callq 0x4d1a2
movzwl (%r14), %eax
testw %ax, %ax
jns 0x24f48
movw $0x0, (%r14)
xorl %eax, %eax
movzwl %ax, %ecx
movl 0x256b43(%rip), %eax    # 0x27ba94
cmpl %ecx, %eax
movl %ebx, %r10d
jge 0x24f5c
movw %ax, (%r14)
movslq %r15d, %rax
movq 0x30(%rsp), %rsi
movzwl (%rsi,%rax,2), %ecx
testw %cx, %cx
movl %ebp, %r11d
jns 0x24f78
movw $0x0, (%rsi,%rax,2)
xorl %ecx, %ecx
movzwl %cx, %edx
movl 0x256b13(%rip), %ecx    # 0x27ba94
cmpl %edx, %ecx
jge 0x24f89
movw %cx, (%rsi,%rax,2)
orl %r10d, %r11d
movl %r11d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq