// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/build.c
// Function: AutoAlignWalls
void AutoAlignWalls(int nWall0, int ply)
{
	int z0, z1, nTile, nWall1, branch, visible, nNextSector, nSector;

	nTile = wall[nWall0].picnum;
	branch = 0;
	if (ply == 0)
	{
			//clear visited bits
		memset(visited,0,sizeof(visited));
		visited[nWall0] = 1;
	}

	z0 = GetWallZPeg(nWall0);

	nWall1 = wall[nWall0].point2;

		//loop through walls at this vertex in CCW order
	while (1)
	{
			//break if this wall would connect us in a loop
		if (visited[nWall1]) break;

		visited[nWall1] = 1;

			//break if reached back of left wall
		if (wall[nWall1].nextwall == nWall0) break;

		if (wall[nWall1].picnum == nTile)
		{
			z1 = GetWallZPeg(nWall1);
			visible = 0;

			nNextSector = wall[nWall1].nextsector;
			if (nNextSector < 0)
				visible = 1;
			else
			{
					//ignore two sided walls that have no visible face
				nSector = wall[wall[nWall1].nextwall].nextsector;
				if (getceilzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) <
					getceilzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y))
					visible = 1;

				if (getflorzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) >
					getflorzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y))
					visible = 1;
			}

			if (visible)
			{
				branch++;
				AlignWalls(nWall0,z0,nWall1,z1,nTile);

					//if wall was 1-sided, no need to recurse
				if (wall[nWall1].nextwall < 0)
				{
					nWall0 = nWall1;
					z0 = GetWallZPeg(nWall0);
					nWall1 = wall[nWall0].point2;
					branch = 0;
					continue;
				}
				else
					AutoAlignWalls(nWall1,ply+1);
			}
		}

		if (wall[nWall1].nextwall < 0) break;
		nWall1 = wall[wall[nWall1].nextwall].point2;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x1d1227(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x10(%rax), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x0, -0x8(%rbp)
jne 0x243c6
leaq 0x1937c5(%rip), %rdi    # 0x1b7b70
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x62d0
movslq -0x4(%rbp), %rcx
leaq 0x1937ae(%rip), %rax    # 0x1b7b70
movb $0x1, (%rax,%rcx)
movl -0x4(%rbp), %edi
callq 0x2c0b0
movl %eax, -0xc(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x1d11d4(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rcx
leaq 0x19377b(%rip), %rax    # 0x1b7b70
cmpb $0x0, (%rax,%rcx)
je 0x24400
jmp 0x24684
movslq -0x18(%rbp), %rcx
leaq 0x193765(%rip), %rax    # 0x1b7b70
movb $0x1, (%rax,%rcx)
movslq -0x18(%rbp), %rcx
leaq 0x1d1196(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xa(%rax), %eax
cmpl -0x4(%rbp), %eax
jne 0x2442f
jmp 0x24684
movslq -0x18(%rbp), %rcx
leaq 0x1d1176(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x10(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x24636
movl -0x18(%rbp), %edi
callq 0x2c0b0
movl %eax, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movslq -0x18(%rbp), %rcx
leaq 0x1d1145(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xc(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x2448b
movl $0x1, -0x20(%rbp)
jmp 0x245af
movslq -0x18(%rbp), %rcx
leaq 0x1d111a(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0xa(%rax), %rcx
leaq 0x1d1107(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xc(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movslq -0x18(%rbp), %rdx
leaq 0x1d10eb(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl (%rcx), %esi
movslq -0x18(%rbp), %rdx
leaq 0x1d10d7(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %edx
movswl %ax, %edi
callq 0x551d0
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
movslq -0x18(%rbp), %rdx
leaq 0x1d10b4(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl (%rcx), %esi
movslq -0x18(%rbp), %rdx
leaq 0x1d10a0(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %edx
movswl %ax, %edi
callq 0x551d0
movl %eax, %ecx
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
jge 0x24532
movl $0x1, -0x20(%rbp)
movl -0x28(%rbp), %eax
movslq -0x18(%rbp), %rdx
leaq 0x1d1070(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl (%rcx), %esi
movslq -0x18(%rbp), %rdx
leaq 0x1d105c(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %edx
movswl %ax, %edi
callq 0x55060
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movslq -0x18(%rbp), %rdx
leaq 0x1d1039(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl (%rcx), %esi
movslq -0x18(%rbp), %rdx
leaq 0x1d1025(%rip), %rcx    # 0x1f55b0
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %edx
movswl %ax, %edi
callq 0x55060
movl %eax, %ecx
movl -0x30(%rbp), %eax
cmpl %ecx, %eax
jle 0x245ad
movl $0x1, -0x20(%rbp)
jmp 0x245af
cmpl $0x0, -0x20(%rbp)
je 0x24634
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x4(%rbp), %edi
movl -0xc(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x10(%rbp), %ecx
movl -0x14(%rbp), %r8d
callq 0x2c220
movslq -0x18(%rbp), %rcx
leaq 0x1d0fd2(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xa(%rax), %eax
cmpl $0x0, %eax
jge 0x24624
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %edi
callq 0x2c0b0
movl %eax, -0xc(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x1d0fa6(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
jmp 0x243ea
movl -0x18(%rbp), %edi
movl -0x8(%rbp), %esi
addl $0x1, %esi
callq 0x24370
jmp 0x24634
jmp 0x24636
movslq -0x18(%rbp), %rcx
leaq 0x1d0f6f(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xa(%rax), %eax
cmpl $0x0, %eax
jge 0x24653
jmp 0x24684
movslq -0x18(%rbp), %rcx
leaq 0x1d0f52(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0xa(%rax), %rcx
leaq 0x1d0f3f(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
jmp 0x243ea
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)