// File: /workspace/github_c_makefile_star2_O3/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, 0x1c(%rsp)
movslq %edi, %rax
leaq (%rax,%rax,4), %rcx
leaq 0x3ccc34(%rip), %rdx    # 0x3f48e0
movzwl 0x22(%rdx,%rcx,8), %edi
cmpl $0x21, %edi
jne 0x27ce1
leaq 0x1d1573(%rip), %rcx    # 0x1f9230
movq (%rcx,%rax,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
leaq (%rdx,%rcx,8), %rax
movzwl (%rax), %ecx
movw %cx, 0xe(%rsp)
movswq %cx, %rsi
movswl %si, %edx
movzwl 0x2(%rax), %r8d
addw %si, %r8w
decl %r8d
movswl %r8w, %r11d
xorl %eax, %eax
movl $0x0, %ecx
cmpw %r11w, %si
jg 0x27d44
movq %rsi, %rax
shlq $0x5, %rax
leaq 0x341bb1(%rip), %rcx    # 0x3698d0
leaq (%rax,%rcx), %r9
addq $0x4, %r9
movslq %r11d, %r10
subq %rsi, %r10
incq %r10
xorl %ecx, %ecx
xorl %eax, %eax
addl -0x4(%r9), %eax
addl (%r9), %ecx
addq $0x20, %r9
decq %r10
jne 0x27d34
movl %r11d, %r9d
subl %edx, %r9d
incl %r9d
cltd
idivl %r9d
movl %eax, %r10d
movl %ecx, %eax
cltd
idivl %r9d
cmpl $0x10, %edi
je 0x27dde
cmpl $0xd, %edi
jne 0x2812d
leaq 0x106241(%rip), %rax    # 0x12dfb0
movswq (%rax), %rax
testq %rax, %rax
jle 0x2812d
xorl %ecx, %ecx
leaq 0x10637b(%rip), %rdx    # 0x12e100
leaq 0x1064b4(%rip), %rsi    # 0x12e240
leaq 0x10646d(%rip), %rdi    # 0x12e200
leaq 0x1063e6(%rip), %r8     # 0x12e180
leaq 0x10641f(%rip), %r9     # 0x12e1c0
movl 0x1c(%rsp), %r10d
cmpw %r10w, (%rdx,%rcx,2)
jne 0x27dd1
movzwl (%rsi,%rcx,2), %r10d
testw %r10w, %r10w
jne 0x27dc9
movzwl (%rdi,%rcx,2), %r11d
movzwl (%r9,%rcx,2), %r10d
cmpw (%r8,%rcx,2), %r11w
je 0x27dcc
negl %r10d
movw %r10w, (%rsi,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x27da1
jmp 0x2812d
movl %eax, 0x18(%rsp)
movw $0xffff, %r14w          # imm = 0xFFFF
movw $0xffff, %dx            # imm = 0xFFFF
cmpw %r8w, 0xe(%rsp)
jg 0x27e4c
movq %rsi, %rax
shlq $0x5, %rax
leaq 0x341acf(%rip), %rcx    # 0x3698d0
addq %rcx, %rax
addq $0x1a, %rax
movslq %r11d, %rcx
subq %rsi, %rcx
incq %rcx
movw $0xffff, %di            # imm = 0xFFFF
movzwl 0xe(%rsp), %edx
movl %edx, %esi
movw $0xffff, %r8w           # imm = 0xFFFF
cmpw $-0x1, %di
movl %esi, %r14d
cmovel %r8d, %r14d
movl %edi, %edx
cmovel %esi, %edx
cmpw $0x6, (%rax)
cmovnel %r8d, %r14d
cmovnel %edi, %edx
incl %esi
addq $0x20, %rax
movl %edx, %edi
movl %r14d, %r8d
decq %rcx
jne 0x27e21
movb $0x1, %bpl
leaq 0x341a7a(%rip), %rbx    # 0x3698d0
movl %r11d, 0x14(%rsp)
movl %r10d, 0x10(%rsp)
movswq %dx, %rdx
movq %rdx, %r13
shlq $0x5, %r13
leaq (%rbx,%r13), %rdi
movl (%rbx,%r13), %eax
movl 0x4(%rbx,%r13), %esi
movswq 0x8(%rbx,%r13), %rcx
shlq $0x5, %rcx
movl (%rbx,%rcx), %r8d
addl %eax, %r8d
sarl %r8d
cmpl %r10d, %r8d
jne 0x27f6f
leaq (%rbx,%rcx), %r8
movl 0x4(%r8), %r8d
addl %esi, %r8d
sarl %r8d
cmpl 0x18(%rsp), %r8d
jne 0x27f6f
leal -0x1(%rdx), %r8d
cmpw 0xe(%rsp), %dx
cmovlel %r11d, %r8d
movslq %r8d, %r12
shlq $0x5, %r12
cmpl %eax, (%rbx,%r12)
jne 0x28080
addq %rbx, %r12
addq $0x4, %r12
cmpl %esi, (%r12)
je 0x2811b
addq %rbx, %r13
addq $0x4, %r13
movswq 0x8(%rbx,%rcx), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rcx
shlq $0x5, %rcx
movl 0x4(%rbx,%rcx), %r15d
subl 0x4(%rbx,%rax), %r15d
addl %r15d, %esi
movq %r13, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movl (%r12), %esi
addl %r15d, %esi
movq %r12, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x4(%r13), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
movl (%rdi), %esi
addl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x4(%r13), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
addl (%rdi), %r15d
jmp 0x28102
leal -0x1(%rdx), %ecx
cmpw 0xe(%rsp), %dx
cmovlel %r11d, %ecx
movslq %ecx, %r12
shlq $0x5, %r12
movl (%rbx,%r12), %r15d
subl %eax, %r15d
jne 0x2801e
movl 0x4(%rbx,%r12), %r15d
cmpl %esi, %r15d
je 0x2811b
leaq (%rbx,%r12), %rax
addq $0x4, %rax
movq %rax, 0x20(%rsp)
addq $0x4, %rdi
subl %esi, %r15d
movl 0x18(%rsp), %r12d
movl %r12d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
addl %r12d, %r15d
movq 0x20(%rsp), %rdi
movl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x8(%rbx,%r13), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
movl %r12d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x8(%rbx,%r13), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
jmp 0x28102
addq %rbx, %r12
movl %r10d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
addl 0x10(%rsp), %r15d
movq %r12, %rdi
movl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x8(%rbx,%r13), %rdi
shlq $0x5, %rdi
addq %rbx, %rdi
movl 0x10(%rsp), %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x8(%rbx,%r13), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rdi
shlq $0x5, %rdi
addq %rbx, %rdi
jmp 0x28102
addq %rbx, %r12
movswq 0x8(%rbx,%rcx), %rcx
shlq $0x5, %rcx
movswq 0x8(%rbx,%rcx), %rdx
shlq $0x5, %rdx
movl (%rbx,%rdx), %r15d
subl (%rbx,%rcx), %r15d
addl %r15d, %eax
movl %eax, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movl (%r12), %esi
addl %r15d, %esi
movq %r12, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x8(%rbx,%r13), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
movl (%rbx,%rax), %esi
addl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movswq 0x8(%rbx,%r13), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addl (%rbx,%rax), %r15d
movl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe713
movl 0x10(%rsp), %r10d
movl 0x14(%rsp), %r11d
movl %r14d, %edx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x27e60
movswl 0x1c(%rsp), %edi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28145