// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movl $0x100, -0x28(%rbp)     # imm = 0x100
cmpl $0x0, -0x28(%rbp)
jle 0x2495d
jmp 0x2452e
leaq 0xb589c(%rip), %rdi     # 0xd9dd1
callq 0x41510
movl %eax, %edi
leaq 0x5a584d(%rip), %rax    # 0x5c9d90
movswl (%rax), %esi
movl $0x10, %edx
callq 0x24c80
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rcx
leaq 0x419332(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movslq -0x2c(%rbp), %rax
leaq 0x41931d(%rip), %rdx    # 0x43d890
imulq $0x28, %rax, %rax
addq %rax, %rdx
movb $0x1, %al
cmpl 0x8(%rdx), %ecx
movb %al, -0x39(%rbp)
jge 0x245c6
movslq -0x2c(%rbp), %rcx
leaq 0x419301(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movswl 0x22(%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x39(%rbp)
jne 0x245c6
movslq -0x2c(%rbp), %rcx
leaq 0x4192e1(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movswl 0xe(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x2452e
movslq -0x2c(%rbp), %rcx
leaq 0x4192b4(%rip), %rax    # 0x43d890
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movw (%rax), %ax
movw %ax, -0x6(%rbp)
movswl -0x6(%rbp), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x419297(%rip), %rcx    # 0x43d890
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movswl 0x2(%rcx), %ecx
addl %ecx, %eax
subl $0x1, %eax
movw %ax, -0x8(%rbp)
movswl -0x8(%rbp), %eax
movswl -0x6(%rbp), %ecx
cmpl %ecx, %eax
jle 0x2494f
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x7fffffff, -0x18(%rbp) # imm = 0x7FFFFFFF
movl $0x80000000, -0x1c(%rbp) # imm = 0x80000000
movl $0x7fffffff, -0x20(%rbp) # imm = 0x7FFFFFFF
movl $0x80000000, -0x24(%rbp) # imm = 0x80000000
movw -0x6(%rbp), %ax
movw %ax, -0xa(%rbp)
movswl -0xa(%rbp), %eax
movswl -0x8(%rbp), %ecx
cmpl %ecx, %eax
jg 0x24775
movswq -0xa(%rbp), %rcx
leaq 0x38e215(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movswq -0xa(%rbp), %rcx
leaq 0x38e1fa(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movswq -0xa(%rbp), %rcx
leaq 0x38e1de(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x18(%rbp), %eax
jge 0x246c8
movswq -0xa(%rbp), %rcx
leaq 0x38e1c4(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movswq -0xa(%rbp), %rcx
leaq 0x38e1ac(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x246fa
movswq -0xa(%rbp), %rcx
leaq 0x38e192(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movswq -0xa(%rbp), %rcx
leaq 0x38e17a(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0x20(%rbp), %eax
jge 0x2472e
movswq -0xa(%rbp), %rcx
leaq 0x38e15f(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x20(%rbp)
movswq -0xa(%rbp), %rcx
leaq 0x38e146(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0x24(%rbp), %eax
jle 0x24762
movswq -0xa(%rbp), %rcx
leaq 0x38e12b(%rip), %rax    # 0x3b2880
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x24764
movw -0xa(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xa(%rbp)
jmp 0x2464f
movl -0x1c(%rbp), %eax
subl -0x18(%rbp), %eax
cmpl $0x100, %eax            # imm = 0x100
jle 0x2494d
movl -0x24(%rbp), %eax
subl -0x20(%rbp), %eax
cmpl $0x100, %eax            # imm = 0x100
jle 0x2494d
movswl -0x8(%rbp), %ecx
movswl -0x6(%rbp), %eax
subl %eax, %ecx
addl $0x1, %ecx
movl -0x10(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x10(%rbp)
movswl -0x8(%rbp), %ecx
movswl -0x6(%rbp), %eax
subl %eax, %ecx
addl $0x1, %ecx
movl -0x14(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
movl -0x2c(%rbp), %eax
movswl %ax, %edx
callq 0x69810
cmpl $0x1, %eax
jne 0x2494b
movl -0x2c(%rbp), %eax
xorl %esi, %esi
movswl %ax, %edi
callq 0x2abd0
cwtl
movl %eax, -0x30(%rbp)
cmpl $-0x1, -0x30(%rbp)
je 0x24949
movslq -0x30(%rbp), %rax
imulq $0x2c, %rax, %rcx
leaq 0x4522d9(%rip), %rax    # 0x476ae0
movq %rax, -0x48(%rbp)
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x10(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl -0x14(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movslq -0x2c(%rbp), %rax
leaq (%rax,%rax,4), %rcx
leaq 0x41905c(%rip), %rax    # 0x43d890
movl 0x8(%rax,%rcx,8), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0xc(%rax)
movq -0x38(%rbp), %rax
movb $-0x8, 0x10(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x11(%rax)
movq -0x38(%rbp), %rax
movb $0xc, 0x12(%rax)
movq -0x38(%rbp), %rax
movb $0x10, 0x14(%rax)
movq -0x38(%rbp), %rax
movb $0x10, 0x15(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x16(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x17(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0xe(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x1c(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x22(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x24(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x1e(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x26(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movw $0xffff, 0x2a(%rax)     # imm = 0xFFFF
movq -0x38(%rbp), %rdi
movslq -0x30(%rbp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x111332(%rip), %rax    # 0x135c20
leaq (%rax,%rcx,4), %rsi
movl $0x3, %edx
callq 0x8c070
movq -0x48(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x2c, %rcx, %rcx
movswq 0xe(%rax,%rcx), %rsi
leaq 0x5d4efb(%rip), %rdx    # 0x5f9810
movswl (%rdx,%rsi,2), %esi
movzbl 0x15(%rax,%rcx), %edx
imull %edx, %esi
addl %esi, %esi
movl 0x8(%rax,%rcx), %edx
subl %esi, %edx
movl %edx, 0x8(%rax,%rcx)
movl -0x4(%rbp), %eax
movw %ax, %cx
movslq -0x30(%rbp), %rdx
leaq 0x4521a2(%rip), %rax    # 0x476ae0
imulq $0x2c, %rdx, %rdx
addq %rdx, %rax
movw %cx, 0xe(%rax)
jmp 0x2495d
jmp 0x2494d
jmp 0x2494f
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x24522
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)