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

     cnt = 256;
     while (cnt > 0)
     {
          do
          {
            k = mulscale(krand_intercept("PREP 585"),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)
                    {
                         j=jsinsertsprite(k,0);
                         if( j != -1 ) {
                              fillsprite(j,dax,day,sector[k].floorz,0,-8,0,
                                         12,16,16,0,0,0,0,
                                         0,0,0,0,k,0,0,0,-1);
                              sprite[j].z-=((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1);
                              switch( picnum ) {
                              }
                              sprite[j].picnum=picnum;
                         }
                         return;
                    }
               }
          }
          cnt--;
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, 0x8(%rsp)
movl $0x100, %ebp            # imm = 0x100
leaq 0x72201(%rip), %r14     # 0x8cdf4
leaq 0x5631c6(%rip), %r13    # 0x57ddc0
leaq 0x3d6cbf(%rip), %rbx    # 0x3f18c0
movq %r14, %rdi
callq 0x2be4a
movswq (%r13), %rcx
movslq %eax, %r12
imulq %rcx, %r12
movq %r12, %rax
sarq $0x10, %rax
leaq (%rax,%rax,4), %rax
movl 0x4(%rbx,%rax,8), %ecx
cmpl 0x8(%rbx,%rax,8), %ecx
jge 0x1ac01
leaq (%rbx,%rax,8), %r15
cmpw $0x0, 0x22(%r15)
jne 0x1ac01
testb $0x2, 0xe(%r15)
jne 0x1ac01
movzwl (%r15), %edi
movzwl 0x2(%r15), %eax
addw %di, %ax
decl %eax
movl %eax, (%rsp)
cmpw %di, %ax
jle 0x1ad10
movq %rbp, 0x10(%rsp)
shrq $0x10, %r12
movswl %di, %eax
movl %eax, 0xc(%rsp)
movswl (%rsp), %eax
movl %eax, 0x4(%rsp)
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0x80000000, %r9d       # imm = 0x80000000
xorl %eax, %eax
xorl %ecx, %ecx
movl $0x80000000, %r11d      # imm = 0x80000000
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movswq %di, %rsi
shlq $0x5, %rsi
leaq 0x34bc17(%rip), %r8     # 0x3668b0
movl (%r8,%rsi), %ebp
movl 0x4(%r8,%rsi), %esi
addl %ebp, %eax
addl %esi, %ecx
cmpl %edx, %ebp
cmovll %ebp, %edx
cmpl %r11d, %ebp
cmovgl %ebp, %r11d
cmpl %r10d, %esi
cmovll %esi, %r10d
cmpl %r9d, %esi
cmovgl %esi, %r9d
incl %edi
cmpw (%rsp), %di
jle 0x1ac8a
subl %edx, %r11d
cmpl $0x101, %r11d           # imm = 0x101
movq 0x10(%rsp), %rbp
jl 0x1ad10
subl %r10d, %r9d
cmpl $0x101, %r9d            # imm = 0x101
jl 0x1ad10
movl 0x4(%rsp), %esi
subl 0xc(%rsp), %esi
incl %esi
cltd
idivl %esi
movl %eax, %edi
movl %ecx, %eax
cltd
idivl %esi
movswl %r12w, %edx
movl %edi, (%rsp)
movl %eax, 0x4(%rsp)
movl %eax, %esi
callq 0x46943
cmpl $0x1, %eax
je 0x1ad2d
leal -0x1(%rbp), %eax
cmpl $0x1, %ebp
movl %eax, %ebp
ja 0x1ac01
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rsp), %r13d
movl (%rsp), %ebp
movswl %r12w, %edi
xorl %esi, %esi
callq 0x1e94c
cmpw $-0x1, %ax
je 0x1ad1e
movswq %ax, %rax
imulq $0x2c, %rax, %rbx
leaq 0x40fdbb(%rip), %r14    # 0x42ab10
leaq (%r14,%rbx), %rdi
movl %ebp, (%r14,%rbx)
movl %r13d, 0x4(%r14,%rbx)
movl 0x8(%r15), %ecx
movl %ecx, 0x8(%r14,%rbx)
movl $0x0, 0xc(%r14,%rbx)
movw $0xf8, 0x10(%r14,%rbx)
movb $0xc, 0x12(%r14,%rbx)
movl $0x1010, 0x14(%r14,%rbx) # imm = 0x1010
xorl %ecx, %ecx
movq %rcx, 0x1c(%r14,%rbx)
movq %rcx, 0x22(%r14,%rbx)
movw $0xffff, 0x2a(%r14,%rbx) # imm = 0xFFFF
leaq (%rax,%rax,2), %rsi
shlq $0x2, %rsi
addq 0xb320a(%rip), %rsi     # 0xcdfb8
movl $0x3, %edx
callq 0x5da55
movswq 0xe(%r14,%rbx), %rax
leaq 0x59487b(%rip), %rcx    # 0x5af640
movswl (%rcx,%rax,2), %eax
movzbl 0x15(%r14,%rbx), %ecx
imull %eax, %ecx
addl %ecx, %ecx
subl %ecx, 0x8(%r14,%rbx)
movl 0x8(%rsp), %eax
movw %ax, 0xe(%r14,%rbx)
jmp 0x1ad1e