// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: setfirstwall
void setfirstwall(short sectnum, short newfirstwall)
{
	int i, j, k, numwallsofloop;
	int startwall, endwall, danumwalls, dagoalloop;

	startwall = sector[sectnum].wallptr;
	danumwalls = sector[sectnum].wallnum;
	endwall = startwall+danumwalls;
	if ((newfirstwall < startwall) || (newfirstwall >= startwall+danumwalls)) return;
	for(i=0;i<danumwalls;i++)
		Bmemcpy(&wall[i+numwalls],&wall[i+startwall],sizeof(walltype));

	numwallsofloop = 0;
	i = newfirstwall;
	do
	{
		numwallsofloop++;
		i = wall[i].point2;
	} while (i != newfirstwall);

		//Put correct loop at beginning
	dagoalloop = loopnumofsector(sectnum,newfirstwall);
	if (dagoalloop > 0)
	{
		j = 0;
		while (loopnumofsector(sectnum,j+startwall) != dagoalloop) j++;
		for(i=0;i<danumwalls;i++)
		{
			k = i+j; if (k >= danumwalls) k -= danumwalls;
			Bmemcpy(&wall[startwall+i],&wall[numwalls+k],sizeof(walltype));

			wall[startwall+i].point2 += danumwalls-startwall-j;
			if (wall[startwall+i].point2 >= danumwalls)
				wall[startwall+i].point2 -= danumwalls;
			wall[startwall+i].point2 += startwall;
		}
		newfirstwall += danumwalls-j;
		if (newfirstwall >= startwall+danumwalls) newfirstwall -= danumwalls;
	}

	for(i=0;i<numwallsofloop;i++)
		Bmemcpy(&wall[i+numwalls],&wall[i+startwall],sizeof(walltype));
	for(i=0;i<numwallsofloop;i++)
	{
		k = i+newfirstwall-startwall;
		if (k >= numwallsofloop) k -= numwallsofloop;
		Bmemcpy(&wall[startwall+i],&wall[numwalls+k],sizeof(walltype));

		wall[startwall+i].point2 += numwallsofloop-newfirstwall;
		if (wall[startwall+i].point2 >= numwallsofloop)
			wall[startwall+i].point2 -= numwallsofloop;
		wall[startwall+i].point2 += startwall;
	}

	for(i=startwall;i<endwall;i++)
		if (wall[i].nextwall >= 0) wall[wall[i].nextwall].nextwall = i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movw %si, %ax
movw %di, %cx
movw %cx, -0x2(%rbp)
movw %ax, -0x4(%rbp)
movswq -0x2(%rbp), %rcx
leaq 0x2274ee(%rip), %rax    # 0x2805c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
movl %eax, -0x18(%rbp)
movswq -0x2(%rbp), %rcx
leaq 0x2274d5(%rip), %rax    # 0x2805c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movswl 0x2(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movswl -0x4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jl 0x59119
movswl -0x4(%rbp), %eax
movl -0x18(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jl 0x5911e
jmp 0x59550
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x5918a
movl -0x8(%rbp), %eax
movswl 0x3f8891(%rip), %ecx    # 0x4519c8
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x19c46d(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl -0x8(%rbp), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rdx
leaq 0x19c456(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x59125
movl $0x0, -0x14(%rbp)
movswl -0x4(%rbp), %eax
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x19c404(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
movswl -0x4(%rbp), %ecx
cmpl %ecx, %eax
jne 0x59198
movw -0x2(%rbp), %ax
movswl %ax, %edi
movswl -0x4(%rbp), %esi
callq 0x59000
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x5935a
movl $0x0, -0xc(%rbp)
movw -0x2(%rbp), %cx
movl -0xc(%rbp), %eax
addl -0x18(%rbp), %eax
movswl %cx, %edi
movswl %ax, %esi
callq 0x59000
cmpl -0x24(%rbp), %eax
je 0x5920e
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x591e9
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x5932d
movl -0x8(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x20(%rbp), %eax
jl 0x5923d
movl -0x20(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c363(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x3f876d(%rip), %ecx    # 0x4519c8
addl -0x10(%rbp), %ecx
movslq %ecx, %rdx
leaq 0x19c348(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movl -0x20(%rbp), %edx
subl -0x18(%rbp), %edx
subl -0xc(%rbp), %edx
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c30a(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c2e9(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
jl 0x592fb
movl -0x20(%rbp), %edx
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c2c6(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x8(%rax)
movl -0x18(%rbp), %edx
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c2a2(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x59215
movl -0x20(%rbp), %ecx
subl -0xc(%rbp), %ecx
movswl -0x4(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x4(%rbp)
movswl -0x4(%rbp), %eax
movl -0x18(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jl 0x59358
movl -0x20(%rbp), %ecx
movswl -0x4(%rbp), %eax
subl %ecx, %eax
movw %ax, -0x4(%rbp)
jmp 0x5935a
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x593c6
movl -0x8(%rbp), %eax
movswl 0x3f8655(%rip), %ecx    # 0x4519c8
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x19c231(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movl -0x8(%rbp), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rdx
leaq 0x19c21a(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x59361
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x594eb
movl -0x8(%rbp), %eax
movswl -0x4(%rbp), %ecx
addl %ecx, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x593fb
movl -0x14(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c1a5(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x3f85af(%rip), %ecx    # 0x4519c8
addl -0x10(%rbp), %ecx
movslq %ecx, %rdx
leaq 0x19c18a(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movl -0x14(%rbp), %edx
movswl -0x4(%rbp), %eax
subl %eax, %edx
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c14c(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c12b(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jl 0x594b9
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c108(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x8(%rax)
movl -0x18(%rbp), %edx
movl -0x18(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x19c0e4(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x593cd
movl -0x18(%rbp), %eax
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x59550
movslq -0x8(%rbp), %rcx
leaq 0x19c0ac(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xa(%rax), %eax
cmpl $0x0, %eax
jl 0x59543
movl -0x8(%rbp), %eax
movw %ax, %cx
movslq -0x8(%rbp), %rdx
leaq 0x19c08b(%rip), %rax    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rax
movswq 0xa(%rax), %rdx
leaq 0x19c078(%rip), %rax    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rax
movw %cx, 0xa(%rax)
jmp 0x59545
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x594f1
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)