// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movslq %edi, %rax
leaq (%rax,%rax,4), %rcx
leaq 0x3ca1b8(%rip), %rdx    # 0x3f18c0
movzwl 0x22(%rdx,%rcx,8), %r12d
cmpl $0x21, %r12d
jne 0x2773f
leaq 0x1ceaf5(%rip), %rcx    # 0x1f6210
movq (%rcx,%rax,8), %rax
xorl %ecx, %ecx
cmpb $-0x2c, 0x20(%rax)
movl $0xd4, %edx
cmovael %ecx, %edx
movb %dl, 0x20(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edi, 0xc(%rsp)
leaq (%rdx,%rcx,8), %rax
movzwl (%rax), %ecx
movw %cx, 0x2(%rsp)
movswq %cx, %rsi
movswl %si, %edx
movzwl 0x2(%rax), %r8d
addw %si, %r8w
decl %r8d
movswl %r8w, %edi
xorl %eax, %eax
movl $0x0, %ecx
movl %edi, 0x4(%rsp)
cmpw %di, %si
jg 0x277ab
movq %rsi, %rax
shlq $0x5, %rax
leaq 0x33f12c(%rip), %rcx    # 0x3668b0
leaq (%rax,%rcx), %r9
addq $0x4, %r9
movslq 0x4(%rsp), %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 0x2779b
movl 0x4(%rsp), %r9d
subl %edx, %r9d
incl %r9d
cltd
idivl %r9d
movl %eax, %ebp
movl %ecx, %eax
cltd
idivl %r9d
movl %eax, 0x10(%rsp)
cmpl $0x10, %r12d
je 0x2784b
cmpl $0xd, %r12d
jne 0x27b8a
leaq 0x1037d3(%rip), %rax    # 0x12afb0
movswq (%rax), %rax
testq %rax, %rax
movl 0xc(%rsp), %edi
jle 0x27841
xorl %ecx, %ecx
leaq 0x10390d(%rip), %rdx    # 0x12b100
leaq 0x103a46(%rip), %r9     # 0x12b240
leaq 0x1039ff(%rip), %r10    # 0x12b200
leaq 0x103978(%rip), %r11    # 0x12b180
leaq 0x1039b1(%rip), %rbx    # 0x12b1c0
cmpw %di, (%rdx,%rcx,2)
jne 0x27839
movzwl (%r9,%rcx,2), %r14d
testw %r14w, %r14w
jne 0x27831
movzwl (%r10,%rcx,2), %r15d
movzwl (%rbx,%rcx,2), %r14d
cmpw (%r11,%rcx,2), %r15w
je 0x27834
negl %r14d
movw %r14w, (%r9,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x2780f
cmpl $0x10, %r12d
jne 0x27b8a
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movw $0xffff, %di            # imm = 0xFFFF
movw $0xffff, %r9w           # imm = 0xFFFF
cmpw %r8w, 0x2(%rsp)
jg 0x278c0
movq %rsi, %rax
shlq $0x5, %rax
leaq 0x33f03e(%rip), %rcx    # 0x3668b0
addq %rcx, %rax
addq $0x1a, %rax
movslq 0x4(%rsp), %rcx
subq %rsi, %rcx
incq %rcx
movw $0xffff, %si            # imm = 0xFFFF
movzwl 0x2(%rsp), %edx
movw $0xffff, %r8w           # imm = 0xFFFF
cmpw $-0x1, %si
movl %edx, %edi
cmovel %r8d, %edi
movl %esi, %r9d
cmovel %edx, %r9d
cmpw $0x6, (%rax)
cmovnel %r8d, %edi
cmovnel %esi, %r9d
incl %edx
addq $0x20, %rax
movl %r9d, %esi
movl %edi, %r8d
decq %rcx
jne 0x27892
movw %r9w, 0x8(%rsp)
movw %di, 0xa(%rsp)
xorl %r13d, %r13d
leaq 0x33efdb(%rip), %rbx    # 0x3668b0
movl %ebp, 0x14(%rsp)
movswq 0x8(%rsp,%r13,2), %rdx
movq %rdx, %r14
shlq $0x5, %r14
leaq (%rbx,%r14), %rdi
movl (%rbx,%r14), %esi
movswq 0x8(%rbx,%r14), %rcx
shlq $0x5, %rcx
movl (%rbx,%rcx), %eax
addl %esi, %eax
sarl %eax
cmpl %ebp, %eax
jne 0x279e4
leaq (%rbx,%rcx), %r8
movl 0x4(%rdi), %eax
movl 0x4(%r8), %r8d
addl %eax, %r8d
sarl %r8d
cmpl 0x10(%rsp), %r8d
jne 0x279e4
leal -0x1(%rdx), %r8d
cmpw 0x2(%rsp), %dx
cmovlel 0x4(%rsp), %r8d
movslq %r8d, %r12
shlq $0x5, %r12
cmpl %esi, (%rbx,%r12)
jne 0x27aee
addq %rbx, %r12
addq $0x4, %r12
cmpl %eax, (%r12)
je 0x27b7d
addq $0x4, %rdi
movswq 0x8(%rbx,%rcx), %rcx
shlq $0x5, %rcx
movswq 0x8(%rbx,%rcx), %rdx
shlq $0x5, %rdx
movl 0x4(%rbx,%rdx), %r15d
subl 0x4(%rbx,%rcx), %r15d
addl %r15d, %eax
movl %eax, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movl (%r12), %esi
addl %r15d, %esi
movq %r12, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
movl (%rdi), %esi
addl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
addl (%rdi), %r15d
jmp 0x27b6e
movl %edx, %eax
decl %eax
cmpw 0x2(%rsp), %dx
cmovlel 0x4(%rsp), %eax
movslq %eax, %r12
shlq $0x5, %r12
movl (%rbx,%r12), %r15d
subl %esi, %r15d
jne 0x27a91
movl 0x4(%rbx,%r12), %r15d
movl 0x4(%rdi), %eax
cmpl %eax, %r15d
je 0x27b7d
addq %rbx, %r12
addq $0x4, %r12
addq $0x4, %rdi
subl %eax, %r15d
movl 0x10(%rsp), %ebp
movl %ebp, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
addl %ebp, %r15d
movq %r12, %rdi
movl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
movl %ebp, %esi
movl 0x14(%rsp), %ebp
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
jmp 0x27b6e
addq %rbx, %r12
movl %ebp, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
addl %ebp, %r15d
movq %r12, %rdi
movl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rdi
shlq $0x5, %rdi
addq %rbx, %rdi
movl %ebp, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rdi
shlq $0x5, %rdi
addq %rbx, %rdi
jmp 0x27b6e
addq %rbx, %r12
movswq 0x8(%rbx,%rcx), %rax
shlq $0x5, %rax
movswq 0x8(%rbx,%rax), %rcx
shlq $0x5, %rcx
movl (%rbx,%rcx), %r15d
subl (%rbx,%rax), %r15d
addl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movl (%r12), %esi
addl %r15d, %esi
movq %r12, %rdi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %rax
shlq $0x5, %rax
leaq (%rbx,%rax), %rdi
movl (%rbx,%rax), %esi
addl %r15d, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0xe71e
movswq 0x8(%rbx,%r14), %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 0xe71e
incq %r13
cmpq $0x1, %r13
je 0x278d9
movswl 0xc(%rsp), %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27ba2