// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/src/tektag.c
// Function: operatesector
void
operatesector(short dasector)
{     //Door code
     int i, j, datag;
     int dax2, day2, centx, centy;
     short startwall, endwall, wallfind[2];

     datag = sector[dasector].lotag;

     // lights out / on
     if( datag == 33 ) {
          if( sectptr[dasector]->visibility >= 212 ) {
               sectptr[dasector]->visibility=0;
          }
          else {
               sectptr[dasector]->visibility=212;
          }
          return;
     }

     startwall = sector[dasector].wallptr;
     endwall = startwall + sector[dasector].wallnum - 1;
     centx = 0L, centy = 0L;
     for(i=startwall;i<=endwall;i++)
     {
          centx += wall[i].x;
          centy += wall[i].y;
     }
     centx /= (endwall-startwall+1);
     centy /= (endwall-startwall+1);

     // kens swinging door
     if( datag == 13 ) {
          for( i=0; i<swingcnt; i++ ) {
               if( swingsector[i] == dasector ) {
                    if( swinganginc[i] == 0 ) {
                         if( swingang[i] == swingangclosed[i] ) {
                              swinganginc[i] = swingangopendir[i];
                         }
                         else {
                              swinganginc[i] = -swingangopendir[i];
                         }
                    }
                    else {
                         swinganginc[i] = -swinganginc[i];
                    }
               }
          }
     }

     // kens true sideways double-sliding door
     if( datag == 16 ) {
          // get 2 closest line segments to center (dax, day)
          wallfind[0] = -1;
          wallfind[1] = -1;
          for( i=startwall;i<=endwall;i++ )
               if (wall[i].lotag == 6)
               {
                    if (wallfind[0] == -1)
                         wallfind[0] = i;
                    else
                         wallfind[1] = i;
               }

          for(j=0;j<2;j++)
          {
               if ((((wall[wallfind[j]].x+wall[wall[wallfind[j]].point2].x)>>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy))
               {     //door was closed
                         //find what direction door should open
                    i = wallfind[j]-1; if (i < startwall) i = endwall;
                    dax2 = wall[i].x-wall[wallfind[j]].x;
                    day2 = wall[i].y-wall[wallfind[j]].y;
                    if (dax2 != 0)
                    {
                         dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x;
                         dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x;
                         setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
                         setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
                         setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
                         setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L);
                    }
                    else if (day2 != 0)
                    {
                         day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y;
                         day2 -= wall[wall[wall[wallfind[j]].point2].point2].y;
                         setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
                         setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
                         setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
                         setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L);
                    }
               }
               else
               {    //door was not closed
                    i = wallfind[j]-1; if (i < startwall) i = endwall;
                    dax2 = wall[i].x-wall[wallfind[j]].x;
                    day2 = wall[i].y-wall[wallfind[j]].y;
                    if (dax2 != 0)
                    {
                         setanimation(&wall[wallfind[j]].x,centx,4L,0L);
                         setanimation(&wall[i].x,centx+dax2,4L,0L);
                         setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L);
                         setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L);
                    }
                    else if (day2 != 0)
                    {
                         setanimation(&wall[wallfind[j]].y,centy,4L,0L);
                         setanimation(&wall[i].y,centy+day2,4L,0L);
                         setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L);
                         setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L);
                    }
               }
          }
     }

     tekoperatesector(dasector);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, 0x18(%rsp)
movslq %edi, %rcx
imulq $0x28, %rcx, %rdx
leaq 0x3c54d8(%rip), %rax    # 0x3ea8e0
movzwl 0x22(%rax,%rdx), %edi
cmpl $0x21, %edi
jne 0x2543d
leaq 0x1c9e17(%rip), %rax    # 0x1ef230
movq (%rax,%rcx,8), %rax
xorl %ecx, %ecx
cmpb $-0x2c, 0x20(%rax)
movl $0xd4, %edx
cmovael %ecx, %edx
movb %dl, 0x20(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rdx, %rax
movswq (%rax), %r10
movzwl 0x2(%rax), %eax
addw %r10w, %ax
decl %eax
movswl %ax, %r11d
movswq %ax, %rsi
movq %r10, %r8
shlq $0x5, %r8
leaq 0x33a46c(%rip), %r14    # 0x35f8d0
leaq (%r8,%r14), %rdx
addq $0x4, %rdx
xorl %eax, %eax
movq %r10, %r9
xorl %ecx, %ecx
cmpq %rsi, %r9
jg 0x25486
addl -0x4(%rdx), %eax
addl (%rdx), %ecx
incq %r9
addq $0x20, %rdx
jmp 0x25473
movl %r11d, %r9d
subl %r10d, %r9d
incl %r9d
cltd
idivl %r9d
movl %eax, %ebx
movl %ecx, %eax
cltd
idivl %r9d
cmpl $0x10, %edi
je 0x2551f
cmpl $0xd, %edi
jne 0x25848
leaq 0xfeb00(%rip), %rax     # 0x123fb0
movzwl (%rax), %ecx
xorl %eax, %eax
testw %cx, %cx
cmovlel %eax, %ecx
movzwl %cx, %ecx
leaq 0xfec3b(%rip), %rdx     # 0x124100
leaq 0xfed74(%rip), %rsi     # 0x124240
leaq 0xfed2d(%rip), %rdi     # 0x124200
leaq 0xfeca6(%rip), %r8      # 0x124180
leaq 0xfecdf(%rip), %r9      # 0x1241c0
cmpq %rax, %rcx
je 0x25848
movl 0x18(%rsp), %r10d
cmpw %r10w, (%rdx,%rax,2)
jne 0x2551a
movzwl (%rsi,%rax,2), %r10d
testw %r10w, %r10w
jne 0x25512
movzwl (%rdi,%rax,2), %r11d
movzwl (%r9,%rax,2), %r10d
cmpw (%r8,%rax,2), %r11w
je 0x25515
negl %r10d
movw %r10w, (%rsi,%rax,2)
incq %rax
jmp 0x254e1
movl %ebx, 0xc(%rsp)
leaq (%r8,%r14), %rbx
addq $0x1a, %rbx
movw $0xffff, %dx            # imm = 0xFFFF
movq %r10, %rcx
movw $0xffff, %di            # imm = 0xFFFF
cmpq %rsi, %rcx
jg 0x25568
cmpw $-0x1, %di
movl %ecx, %r8d
cmovel %edx, %r8d
movl %edi, %r9d
cmovel %ecx, %r9d
cmpw $0x6, (%rbx)
cmovnel %edx, %r8d
cmovnel %edi, %r9d
incq %rcx
addq $0x20, %rbx
movl %r8d, %edx
movl %r9d, %edi
jmp 0x25536
movl %eax, 0x14(%rsp)
movw %di, 0x1c(%rsp)
movw %dx, 0x1e(%rsp)
xorl %r15d, %r15d
movq %r10, 0x20(%rsp)
movl %r11d, 0x10(%rsp)
movl 0xc(%rsp), %r9d
cmpq $0x2, %r15
je 0x25848
movswq 0x1c(%rsp,%r15,2), %rdx
movq %rdx, %rbp
shlq $0x5, %rbp
leaq (%r14,%rbp), %rdi
movl (%r14,%rbp), %eax
movl 0x4(%r14,%rbp), %esi
movswq 0x8(%r14,%rbp), %rcx
shlq $0x5, %rcx
movl (%r14,%rcx), %r8d
addl %eax, %r8d
sarl %r8d
cmpl %r9d, %r8d
jne 0x2569f
leaq (%r14,%rcx), %r8
movl 0x4(%r8), %r8d
addl %esi, %r8d
sarl %r8d
cmpl 0x14(%rsp), %r8d
jne 0x2569f
leal -0x1(%rdx), %r8d
cmpw %r10w, %dx
cmovlel %r11d, %r8d
movslq %r8d, %r13
shlq $0x5, %r13
cmpl %eax, (%r14,%r13)
jne 0x257a8
leaq (%r14,%r13), %rbx
addq $0x4, %rbx
cmpl %esi, (%rbx)
je 0x25840
leaq (%r14,%rbp), %r13
addq $0x4, %r13
movswq 0x8(%r14,%rcx), %rax
shlq $0x5, %rax
movswq 0x8(%r14,%rax), %rcx
shlq $0x5, %rcx
movl 0x4(%r14,%rcx), %r12d
subl 0x4(%r14,%rax), %r12d
addl %r12d, %esi
movq %r13, %rdi
pushq $0x4
popq %rbp
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xd803
movl (%rbx), %esi
addl %r12d, %esi
movq %rbx, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x4(%r13), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdi
addq $0x4, %rdi
movl (%rdi), %esi
addl %r12d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x4(%r13), %rax
shlq $0x5, %rax
movswq 0x8(%r14,%rax), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdi
addq $0x4, %rdi
addl (%rdi), %r12d
movl %r12d, %esi
movl %ebp, %edx
jmp 0x2582a
movl %edx, %ecx
decl %ecx
cmpw %r10w, %dx
cmovlel %r11d, %ecx
movslq %ecx, %rbx
shlq $0x5, %rbx
movl (%r14,%rbx), %r12d
subl %eax, %r12d
jne 0x25742
movl 0x4(%r14,%rbx), %r12d
cmpl %esi, %r12d
je 0x25840
addq %r14, %rbx
addq $0x4, %rbx
addq $0x4, %rdi
subl %esi, %r12d
movl 0x14(%rsp), %r13d
movl %r13d, %esi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0xd803
addl %r13d, %r12d
movq %rbx, %rdi
movl %r12d, %esi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0xd803
movswq 0x8(%r14,%rbp), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdi
addq $0x4, %rdi
movl %r13d, %esi
pushq $0x4
popq %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x8(%r14,%rbp), %rax
shlq $0x5, %rax
movswq 0x8(%r14,%rax), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdi
addq $0x4, %rdi
jmp 0x25825
addq %r14, %rbx
movl %r9d, %esi
pushq $0x4
popq %r13
movl %r13d, %edx
xorl %ecx, %ecx
callq 0xd803
addl 0xc(%rsp), %r12d
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x8(%r14,%rbp), %rdi
shlq $0x5, %rdi
addq %r14, %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x8(%r14,%rbp), %rax
shlq $0x5, %rax
movswq 0x8(%r14,%rax), %rdi
shlq $0x5, %rdi
addq %r14, %rdi
movl %r12d, %esi
movl %r13d, %edx
jmp 0x2582a
addq %r14, %r13
movswq 0x8(%r14,%rcx), %rcx
shlq $0x5, %rcx
movswq 0x8(%r14,%rcx), %rdx
shlq $0x5, %rdx
movl (%r14,%rdx), %r12d
subl (%r14,%rcx), %r12d
addl %r12d, %eax
movl %eax, %esi
pushq $0x4
popq %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xd803
movl (%r13), %esi
addl %r12d, %esi
movq %r13, %rdi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x8(%r14,%rbp), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdi
movl (%r14,%rax), %esi
addl %r12d, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xd803
movswq 0x8(%r14,%rbp), %rax
shlq $0x5, %rax
movswq 0x8(%r14,%rax), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdi
addl (%r14,%rax), %r12d
movl %r12d, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xd803
movl 0xc(%rsp), %r9d
movl 0x10(%rsp), %r11d
movq 0x20(%rsp), %r10
incq %r15
jmp 0x25588
movswl 0x18(%rsp), %edi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x25860