// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/build.c
// Function: copysector
void copysector(short soursector, short destsector, short deststartwall, unsigned char copystat)
{
	short j, k, m, newnumwalls, startwall, endwall;

	newnumwalls = deststartwall;  //erase existing sector fragments

		//duplicate walls
	startwall = sector[soursector].wallptr;
	endwall = startwall + sector[soursector].wallnum;
	for(j=startwall;j<endwall;j++)
	{
		Bmemcpy(&wall[newnumwalls],&wall[j],sizeof(walltype));
		wall[newnumwalls].point2 += deststartwall-startwall;
		if (wall[newnumwalls].nextwall >= 0)
		{
			wall[newnumwalls].nextwall += deststartwall-startwall;
			wall[newnumwalls].nextsector += destsector-soursector;
		}
		newnumwalls++;
	}

	//for(j=deststartwall;j<newnumwalls;j++)
	//{
	//   if (wall[j].nextwall >= 0)
	//      checksectorpointer(wall[j].nextwall,wall[j].nextsector);
	//   checksectorpointer((short)j,destsector);
	//}

	if (newnumwalls > deststartwall)
	{
			//duplicate sectors
		Bmemcpy(&sector[destsector],&sector[soursector],sizeof(sectortype));
		sector[destsector].wallptr = deststartwall;
		sector[destsector].wallnum = newnumwalls-deststartwall;

		if (copystat == 1)
		{
				//duplicate sprites
			j = headspritesect[soursector];
			while (j >= 0)
			{
				k = nextspritesect[j];

				m = insertsprite(destsector,sprite[j].statnum);
				Bmemcpy(&sprite[m],&sprite[j],sizeof(spritetype));
				sprite[m].sectnum = destsector;   //Don't let memcpy overwrite sector!

				j = k;
			}
		}

	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movw %dx, %cx
movw %si, %dx
movw %di, %si
movw %si, -0x2(%rbp)
movw %dx, -0x4(%rbp)
movw %cx, -0x6(%rbp)
movb %al, -0x7(%rbp)
movw -0x6(%rbp), %ax
movw %ax, -0x10(%rbp)
movswq -0x2(%rbp), %rcx
leaq 0x25599a(%rip), %rax    # 0x2805c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movw (%rax), %ax
movw %ax, -0x12(%rbp)
movswl -0x12(%rbp), %eax
movswq -0x2(%rbp), %rdx
leaq 0x25597c(%rip), %rcx    # 0x2805c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movswl 0x2(%rcx), %ecx
addl %ecx, %eax
movw %ax, -0x14(%rbp)
movw -0x12(%rbp), %ax
movw %ax, -0xa(%rbp)
movswl -0xa(%rbp), %eax
movswl -0x14(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2ad5f
movswq -0x10(%rbp), %rcx
leaq 0x1ca937(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswq -0xa(%rbp), %rdx
leaq 0x1ca924(%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)
movswl -0x6(%rbp), %edx
movswl -0x12(%rbp), %eax
subl %eax, %edx
movswq -0x10(%rbp), %rcx
leaq 0x1ca8e9(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movswq -0x10(%rbp), %rcx
leaq 0x1ca8cc(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xa(%rax), %eax
cmpl $0x0, %eax
jl 0x2ad42
movswl -0x6(%rbp), %edx
movswl -0x12(%rbp), %eax
subl %eax, %edx
movswq -0x10(%rbp), %rcx
leaq 0x1ca8a6(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xa(%rax), %ecx
addl %edx, %ecx
movw %cx, 0xa(%rax)
movswl -0x4(%rbp), %edx
movswl -0x2(%rbp), %eax
subl %eax, %edx
movswq -0x10(%rbp), %rcx
leaq 0x1ca87f(%rip), %rax    # 0x1f55b0
shlq $0x5, %rcx
addq %rcx, %rax
movswl 0xc(%rax), %ecx
addl %edx, %ecx
movw %cx, 0xc(%rax)
movw -0x10(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x10(%rbp)
movw -0xa(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xa(%rbp)
jmp 0x2ac5d
movswl -0x10(%rbp), %eax
movswl -0x6(%rbp), %ecx
cmpl %ecx, %eax
jle 0x2aea2
movswq -0x4(%rbp), %rax
leaq 0x255845(%rip), %rdi    # 0x2805c0
imulq $0x28, %rax, %rax
addq %rax, %rdi
movswq -0x2(%rbp), %rax
leaq 0x255832(%rip), %rsi    # 0x2805c0
imulq $0x28, %rax, %rax
addq %rax, %rsi
movl $0x28, %edx
callq 0x60c0
movw -0x6(%rbp), %cx
movswq -0x4(%rbp), %rdx
leaq 0x255811(%rip), %rax    # 0x2805c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movw %cx, (%rax)
movswl -0x10(%rbp), %eax
movswl -0x6(%rbp), %ecx
subl %ecx, %eax
movw %ax, %cx
movswq -0x4(%rbp), %rdx
leaq 0x2557ee(%rip), %rax    # 0x2805c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movw %cx, 0x2(%rax)
movzbl -0x7(%rbp), %eax
cmpl $0x1, %eax
jne 0x2aea0
movswq -0x2(%rbp), %rcx
leaq 0x3be27a(%rip), %rax    # 0x3e9070
movw (%rax,%rcx,2), %ax
movw %ax, -0xa(%rbp)
movswl -0xa(%rbp), %eax
cmpl $0x0, %eax
jl 0x2ae9e
movswq -0xa(%rbp), %rcx
leaq 0x3c8269(%rip), %rax    # 0x3f3080
movw (%rax,%rcx,2), %ax
movw %ax, -0xc(%rbp)
movw -0x4(%rbp), %cx
movswq -0xa(%rbp), %rdx
leaq 0x28e9e1(%rip), %rax    # 0x2b9810
imulq $0x2c, %rdx, %rdx
addq %rdx, %rax
movswl %cx, %edi
movswl 0x1a(%rax), %esi
callq 0x46280
movw %ax, -0xe(%rbp)
movswq -0xe(%rbp), %rax
leaq 0x28e9be(%rip), %rdi    # 0x2b9810
imulq $0x2c, %rax, %rax
addq %rax, %rdi
movswq -0xa(%rbp), %rax
leaq 0x28e9ab(%rip), %rsi    # 0x2b9810
imulq $0x2c, %rax, %rax
addq %rax, %rsi
movl $0x2c, %edx
callq 0x60c0
movw -0x4(%rbp), %cx
movswq -0xe(%rbp), %rdx
leaq 0x28e98a(%rip), %rax    # 0x2b9810
imulq $0x2c, %rdx, %rdx
addq %rdx, %rax
movw %cx, 0x18(%rax)
movw -0xc(%rbp), %ax
movw %ax, -0xa(%rbp)
jmp 0x2adfe
jmp 0x2aea0
jmp 0x2aea2
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)