// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/tekprep.c
// Function: findrandomspot
void
findrandomspot(int *x, int *y, short *sectnum)
{
     short startwall, endwall, s;
     int dax, day, minx, maxx, miny, maxy, cnt, k;

     cnt = 256;
     while (cnt > 0)
     {
          do
          {
            k = mulscale(krand_intercept("PREP 521"),numsectors,16);
          } while ((sector[k].ceilingz >= sector[k].floorz) || (sector[k].lotag != 0) || ((sector[k].floorstat&2) != 0));

          startwall = sector[k].wallptr;
          endwall = startwall+sector[k].wallnum-1;
          if (endwall > startwall)
          {
               dax = 0L;
               day = 0L;
               minx = 0x7fffffff; maxx = 0x80000000;
               miny = 0x7fffffff; maxy = 0x80000000;

               for(s=startwall;s<=endwall;s++)
               {
                    dax += wall[s].x;
                    day += wall[s].y;
                    if (wall[s].x < minx) minx = wall[s].x;
                    if (wall[s].x > maxx) maxx = wall[s].x;
                    if (wall[s].y < miny) miny = wall[s].y;
                    if (wall[s].y > maxy) maxy = wall[s].y;
               }
               if ((maxx-minx > 256) && (maxy-miny > 256))
               {
                    dax /= (endwall-startwall+1);
                    day /= (endwall-startwall+1);
                    if (inside(dax,day,k) == 1)
                    {
                         *x = dax;
                         *y = day;
                         *sectnum = k;
                         return;
                    }
               }
          }
          cnt--;
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movl $0x100, %ebx            # imm = 0x100
leaq 0x71fd1(%rip), %r12     # 0x8cde2
leaq 0x562fa8(%rip), %r14    # 0x57ddc0
leaq 0x3d6aa1(%rip), %r15    # 0x3f18c0
leaq 0x34ba8a(%rip), %rbp    # 0x3668b0
movq %r12, %rdi
callq 0x2be4a
movswq (%r14), %rcx
movslq %eax, %r13
imulq %rcx, %r13
movq %r13, %rax
sarq $0x10, %rax
leaq (%rax,%rax,4), %rax
movl 0x4(%r15,%rax,8), %ecx
cmpl 0x8(%r15,%rax,8), %ecx
jge 0x1ae26
leaq (%r15,%rax,8), %rax
cmpw $0x0, 0x22(%rax)
jne 0x1ae26
testb $0x2, 0xe(%rax)
jne 0x1ae26
movzwl (%rax), %edi
movzwl 0x2(%rax), %r8d
addw %di, %r8w
decl %r8d
cmpw %di, %r8w
jle 0x1af29
movq %rbx, 0x20(%rsp)
shrq $0x10, %r13
movswl %di, %eax
movl %eax, (%rsp)
movswl %r8w, %eax
movl %eax, 0x4(%rsp)
xorl %ecx, %ecx
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0x80000000, %r9d       # imm = 0x80000000
movl $0x80000000, %r11d      # imm = 0x80000000
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %eax, %eax
movswq %di, %rsi
shlq $0x5, %rsi
movl (%rbp,%rsi), %ebx
movl 0x4(%rbp,%rsi), %esi
addl %ebx, %eax
addl %esi, %ecx
cmpl %edx, %ebx
cmovll %ebx, %edx
cmpl %r11d, %ebx
cmovgl %ebx, %r11d
cmpl %r10d, %esi
cmovll %esi, %r10d
cmpl %r9d, %esi
cmovgl %esi, %r9d
incl %edi
cmpw %r8w, %di
jle 0x1aeac
subl %edx, %r11d
cmpl $0x101, %r11d           # imm = 0x101
movq 0x20(%rsp), %rbx
jl 0x1af29
subl %r10d, %r9d
cmpl $0x101, %r9d            # imm = 0x101
jl 0x1af29
movl 0x4(%rsp), %esi
subl (%rsp), %esi
incl %esi
cltd
idivl %esi
movl %eax, %edi
movl %ecx, %eax
cltd
idivl %esi
movswl %r13w, %edx
movl %edi, 0x4(%rsp)
movl %eax, (%rsp)
movl %eax, %esi
callq 0x46943
cmpl $0x1, %eax
je 0x1af39
leal -0x1(%rbx), %eax
cmpl $0x1, %ebx
movl %eax, %ebx
ja 0x1ae26
jmp 0x1af57
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq 0x10(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movw %r13w, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq