// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x100, -0x3c(%rbp)     # imm = 0x100
cmpl $0x0, -0x3c(%rbp)
jle 0x24c6d
jmp 0x24997
leaq 0xb5421(%rip), %rdi     # 0xd9dbf
callq 0x41510
movl %eax, %edi
leaq 0x5a53e4(%rip), %rax    # 0x5c9d90
movswl (%rax), %esi
movl $0x10, %edx
callq 0x24c80
movl %eax, -0x40(%rbp)
movslq -0x40(%rbp), %rcx
leaq 0x418ec9(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movslq -0x40(%rbp), %rax
leaq 0x418eb4(%rip), %rdx    # 0x43d890
imulq $0x28, %rax, %rax
addq %rax, %rdx
movb $0x1, %al
cmpl 0x8(%rdx), %ecx
movb %al, -0x41(%rbp)
jge 0x24a2f
movslq -0x40(%rbp), %rcx
leaq 0x418e98(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movswl 0x22(%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
jne 0x24a2f
movslq -0x40(%rbp), %rcx
leaq 0x418e78(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movswl 0xe(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x24997
movslq -0x40(%rbp), %rcx
leaq 0x418e4b(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movw (%rax), %ax
movw %ax, -0x1a(%rbp)
movswl -0x1a(%rbp), %eax
movslq -0x40(%rbp), %rdx
leaq 0x418e2e(%rip), %rcx    # 0x43d890
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movswl 0x2(%rcx), %ecx
addl %ecx, %eax
subl $0x1, %eax
movw %ax, -0x1c(%rbp)
movswl -0x1c(%rbp), %eax
movswl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jle 0x24c5f
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
movl $0x80000000, -0x30(%rbp) # imm = 0x80000000
movl $0x7fffffff, -0x34(%rbp) # imm = 0x7FFFFFFF
movl $0x80000000, -0x38(%rbp) # imm = 0x80000000
movw -0x1a(%rbp), %ax
movw %ax, -0x1e(%rbp)
movswl -0x1e(%rbp), %eax
movswl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jg 0x24bde
movswq -0x1e(%rbp), %rcx
leaq 0x38ddac(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movswq -0x1e(%rbp), %rcx
leaq 0x38dd91(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movswq -0x1e(%rbp), %rcx
leaq 0x38dd75(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jge 0x24b31
movswq -0x1e(%rbp), %rcx
leaq 0x38dd5b(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movswq -0x1e(%rbp), %rcx
leaq 0x38dd43(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x30(%rbp), %eax
jle 0x24b63
movswq -0x1e(%rbp), %rcx
leaq 0x38dd29(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movswq -0x1e(%rbp), %rcx
leaq 0x38dd11(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0x34(%rbp), %eax
jge 0x24b97
movswq -0x1e(%rbp), %rcx
leaq 0x38dcf6(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movswq -0x1e(%rbp), %rcx
leaq 0x38dcdd(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0x38(%rbp), %eax
jle 0x24bcb
movswq -0x1e(%rbp), %rcx
leaq 0x38dcc2(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x24bcd
movw -0x1e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1e(%rbp)
jmp 0x24ab8
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
cmpl $0x100, %eax            # imm = 0x100
jle 0x24c5d
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl $0x100, %eax            # imm = 0x100
jle 0x24c5d
movswl -0x1c(%rbp), %ecx
movswl -0x1a(%rbp), %eax
subl %eax, %ecx
addl $0x1, %ecx
movl -0x24(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
movswl -0x1c(%rbp), %ecx
movswl -0x1a(%rbp), %eax
subl %eax, %ecx
addl $0x1, %ecx
movl -0x28(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %edi
movl -0x28(%rbp), %esi
movl -0x40(%rbp), %eax
movswl %ax, %edx
callq 0x69810
cmpl $0x1, %eax
jne 0x24c5b
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
jmp 0x24c6d
jmp 0x24c5d
jmp 0x24c5f
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2498b
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)