// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %edx, %ecx
movq %rdi, %rbx
shll $0x7, %ecx
movslq 0x24acae(%rip), %rdx    # 0x26ca80
movslq %esi, %r9
leaq 0x24acb4(%rip), %rax    # 0x26ca90
movslq (%rax,%r9,4), %rdi
movq %rdi, %rax
imulq %rdx, %rax
shrq $0x14, %rax
leaq 0x24ec9e(%rip), %rsi    # 0x270a90
movl (%rsi,%r9,4), %esi
movl %esi, 0x8(%rsp)
movslq %esi, %r10
imulq %r10, %rdx
shrq $0x14, %rdx
movslq 0x252c84(%rip), %r13    # 0x274a90
movq %r13, %r12
movq %rdi, 0x18(%rsp)
imulq %rdi, %r12
shrq $0x14, %r12
imulq %r10, %r13
shrq $0x14, %r13
xorl %esi, %esi
movl %ecx, %r8d
subl %eax, %r8d
setl %sil
xorl %edi, %edi
cmpl %edx, %ecx
setl %dil
leal (%rsi,%rdi,2), %r11d
xorl %esi, %esi
movl %ecx, %edi
subl %r12d, %edi
setg %sil
xorl %r14d, %r14d
cmpl %r13d, %ecx
setg %r14b
shll $0x3, %r14d
leal (%r14,%rsi,4), %ebp
leaq 0x246c20(%rip), %rsi    # 0x268a80
movl (%rsi,%r9,4), %r14d
leaq 0x242c05(%rip), %rsi    # 0x264a70
movl (%rsi,%r9,4), %esi
movq %rsi, 0x10(%rsp)
movslq %esi, %r15
movslq %r14d, %rsi
movl %r11d, 0xc(%rsp)
cmpl $0x3, %r11d
jne 0x21e9d
movl 0xc(%rsp), %edx
cmpq %rsi, %r15
jg 0x22128
andw $0x0, (%rbx,%r15,2)
incq %r15
jmp 0x21e89
cmpl $0xc, %ebp
jne 0x21ec0
movl 0xc(%rsp), %edx
cmpq %rsi, %r15
jg 0x22128
movzwl 0x252bde(%rip), %eax    # 0x274a94
movw %ax, (%rbx,%r15,2)
incq %r15
jmp 0x21ea6
movl 0xc(%rsp), %r11d
testl %r11d, %r11d
je 0x21f53
movl %ebp, 0x24(%rsp)
subl %eax, %edx
movslq %r8d, %rax
shlq $0x1e, %rax
movslq %edx, %r8
cqto
idivq %r8
movl %r10d, %edx
movq 0x18(%rsp), %r11
subl %r11d, %edx
movslq %edx, %r8
cltq
imulq %rax, %r8
shrq $0x1e, %r8
addl %r11d, %r8d
movl %r14d, %edx
movq 0x10(%rsp), %r11
subl %r11d, %edx
imulq %r10, %rax
shrq $0x1e, %rax
movslq %eax, %rbp
movslq %edx, %rax
imulq %rbp, %rax
movslq %r8d, %rbp
cqto
idivq %rbp
leal (%r11,%rax), %ebp
cmpl $0x2, 0xc(%rsp)
jne 0x21f64
testl %eax, %eax
movslq %ebp, %rdx
cmovsl %r14d, %ebp
movl %ebp, %r15d
movl 0x24(%rsp), %ebp
movl 0x8(%rsp), %r11d
cmpq %rsi, %rdx
jge 0x21f8e
andw $0x0, 0x2(%rbx,%rdx,2)
incq %rdx
jmp 0x21f43
movl %r14d, %r15d
movq 0x18(%rsp), %rax
movl %eax, %edx
movl 0x8(%rsp), %r11d
jmp 0x21faf
cmpl %r14d, %ebp
cmovlel %ebp, %r11d
movq %r11, 0x10(%rsp)
movl %ebp, %edx
movslq %ebp, %rax
movl 0x24(%rsp), %ebp
movl 0x8(%rsp), %r11d
cmpq %rax, %r15
jg 0x21fa0
andw $0x0, (%rbx,%r15,2)
incq %r15
jmp 0x21f7e
testl %eax, %eax
cmovsl %r11d, %r8d
movq 0x18(%rsp), %rax
movl %eax, %edx
movl %r8d, %r11d
jmp 0x21faf
cmpl %r14d, %edx
cmovgl 0x18(%rsp), %r8d
movl %r14d, %r15d
movl %r8d, %edx
testl %ebp, %ebp
je 0x22042
movl %edx, 0x8(%rsp)
subl %r12d, %r13d
movslq %edi, %rax
shlq $0x1e, %rax
movslq %r13d, %rdi
cqto
idivq %rdi
movl %r10d, %edx
movq 0x18(%rsp), %r8
subl %r8d, %edx
movslq %edx, %rdi
cltq
imulq %rax, %rdi
shrq $0x1e, %rdi
addl %r8d, %edi
leaq 0x242a81(%rip), %rdx    # 0x264a70
movslq (%rdx,%r9,4), %r8
movl %r14d, %edx
subl %r8d, %edx
imulq %rax, %r10
shrq $0x1e, %r10
movslq %r10d, %r9
movslq %edx, %rax
imulq %r9, %rax
movslq %edi, %r9
cqto
idivq %r9
leal (%r8,%rax), %edx
cmpl $0x8, %ebp
jne 0x22049
testl %eax, %eax
cmovnsl %edx, %r15d
movslq %edx, %rdx
movq 0x10(%rsp), %r9
cmpq %rsi, %rdx
jge 0x2206e
movzwl 0x252a5d(%rip), %r8d    # 0x274a94
movw %r8w, 0x2(%rbx,%rdx,2)
incq %rdx
jmp 0x2202a
movq 0x10(%rsp), %r9
jmp 0x22087
cmpl %r14d, %edx
movq 0x10(%rsp), %r9
cmovlel %edx, %r9d
movslq %edx, %rax
cmpq %rax, %r8
jg 0x2207d
movzwl 0x252a30(%rip), %esi    # 0x274a94
movw %si, (%rbx,%r8,2)
incq %r8
jmp 0x22058
testl %eax, %eax
cmovsl %r11d, %edi
movl %edi, %r11d
movl 0x8(%rsp), %edx
jmp 0x22087
cmpl %r14d, %edx
cmovgl 0x8(%rsp), %edi
movl %edi, %edx
movslq 0x252a0a(%rip), %rax    # 0x274a98
movslq %ecx, %rcx
imulq %rax, %rcx
movslq %edx, %rsi
movq %rcx, %rax
cqto
idivq %rsi
movq %rax, %rsi
movslq %r11d, %rdi
movq %rcx, %rax
cqto
idivq %rdi
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 (%rbx,%rdx,2), %r14
movl 0x2529cc(%rip), %edx    # 0x274a9c
shll $0x10, %edx
addl %ecx, %edx
movq %r14, %rdi
movl %eax, %ecx
callq 0x4448f
movzwl (%r14), %eax
testw %ax, %ax
jns 0x220ef
andw $0x0, (%r14)
xorl %eax, %eax
movzwl %ax, %ecx
movl 0x25299c(%rip), %eax    # 0x274a94
cmpl %ecx, %eax
jge 0x22100
movw %ax, (%r14)
movslq %r15d, %rax
movzwl (%rbx,%rax,2), %ecx
testw %cx, %cx
jns 0x22113
andw $0x0, (%rbx,%rax,2)
xorl %ecx, %ecx
movzwl %cx, %edx
movl 0x252978(%rip), %ecx    # 0x274a94
cmpl %edx, %ecx
movl 0xc(%rsp), %edx
jge 0x22128
movw %cx, (%rbx,%rax,2)
orl %edx, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq