// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/src/tekstat.c
// Function: attachvirus
int
attachvirus(short i, int pic)
{
     int       j,ext,nextj;

     if( option[4] != 0 ) {
          return(0);
     }
     if( (sprptr[i]->statnum == VIRUS) || (sprptr[i]->statnum == PINBALL) ) {
          return(0);
     }
     if( isanandroid(i) || isahologram(i) ) {
          return(0);
     }

	j=headspritestat[VIRUS];
	while( j >= 0 ) {
		nextj = nextspritestat[j];
          // already hosting ?
          if( sprptr[j]->owner == i ) {
               return(0);
          }
		j = nextj;
	}

     j=jsinsertsprite(sprptr[i]->sectnum, VIRUS);
     if( j == -1 ) {
          return(0);
     }

     sprptr[j]->extra=-1;
     sprptr[j]->x=sprptr[i]->x;
     sprptr[j]->y=sprptr[i]->y;
     sprptr[j]->z=sprptr[i]->z;
     sprptr[j]->xrepeat=20;
     sprptr[j]->yrepeat=20;
     sprptr[j]->cstat=0x0000;
     sprptr[j]->shade=-28;
     sprptr[j]->picnum=pic;
     sprptr[j]->lotag=(krand_intercept("STAT1216")&512)+128;
     sprptr[j]->hitag=0;
     sprptr[j]->owner=i;  // host

     if( pic == FIREPIC ) {
          sprptr[j]->xrepeat=sprptr[i]->xrepeat;
          sprptr[j]->yrepeat=sprptr[i]->yrepeat+8;
          ext=sprptr[i]->extra;
          playsound(S_FIRELOOP,sprptr[j]->x,sprptr[j]->y,0,ST_UPDATE);
          if( validext(ext) ) {
               newstatus(i, PINBALL);
               if( sprptr[i]->statnum == PINBALL ) {
                    sprptr[i]->xvel+=4;
                    sprptr[i]->yvel+=4;
               }
          }
     }
     else {
          playsound(S_FORCEFIELDHUMLOOP, sprptr[i]->x,sprptr[i]->y,0,ST_UNIQUE);
     }

     return(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xa873d(%rip), %rax     # 0xc7978
xorl %r15d, %r15d
cmpb $0x0, 0x4(%rax)
je 0x1f256
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edi, %r14d
movswq %r14w, %r12
leaq 0x107fcc(%rip), %r13    # 0x127230
movq (%r13,%r12,8), %rax
movzwl 0x1a(%rax), %eax
cmpl $0xfa, %eax
je 0x1f244
cmpl $0x193, %eax            # imm = 0x193
je 0x1f244
movl %esi, %ebp
movswl %r14w, %ebx
movl %ebx, %edi
callq 0x1f051
testl %eax, %eax
jne 0x1f244
movl %ebx, %edi
callq 0x1f09c
testl %eax, %eax
jne 0x1f244
movl $0x1f4, %eax            # imm = 0x1F4
addq 0xa7ca5(%rip), %rax     # 0xc6f48
leaq 0x54e906(%rip), %rcx    # 0x56dbb0
movswq (%rax), %rax
testq %rax, %rax
js 0x1f2c7
movq (%r13,%rax,8), %rdx
cmpw %r14w, 0x1e(%rdx)
je 0x1f244
addq %rax, %rax
addq %rcx, %rax
jmp 0x1f2aa
movq (%r13,%r12,8), %rax
movswl 0x18(%rax), %edi
movl $0xfa, %esi
callq 0x1cf0c
cmpw $-0x1, %ax
je 0x1f244
movswq %ax, %r15
movq (%r13,%r15,8), %rax
orw $-0x1, 0x2a(%rax)
movq (%r13,%r12,8), %rax
movl (%rax), %eax
movq (%r13,%r15,8), %rcx
movl %eax, (%rcx)
movq (%r13,%r12,8), %rax
movl 0x4(%rax), %eax
movq (%r13,%r15,8), %rcx
movl %eax, 0x4(%rcx)
movq (%r13,%r12,8), %rax
movl 0x8(%rax), %eax
movq (%r13,%r15,8), %rcx
movl %eax, 0x8(%rcx)
movq (%r13,%r15,8), %rax
movb $0x14, %cl
movb %cl, 0x14(%rax)
movq (%r13,%r15,8), %rax
movb %cl, 0x15(%rax)
movq (%r13,%r15,8), %rax
andw $0x0, 0xc(%rax)
movq (%r13,%r15,8), %rax
movb $-0x1c, 0x10(%rax)
movq (%r13,%r15,8), %rax
movw %bp, 0xe(%rax)
leaq 0x63245(%rip), %rdi     # 0x8259a
callq 0x2945b
andl $0x200, %eax            # imm = 0x200
orl $0x80, %eax
movq (%r13,%r15,8), %rcx
movw %ax, 0x26(%rcx)
movq (%r13,%r15,8), %rax
andw $0x0, 0x28(%rax)
movq (%r13,%r15,8), %rax
movw %r14w, 0x1e(%rax)
movq (%r13,%r12,8), %rax
cmpl $0x1c2, %ebp            # imm = 0x1C2
jne 0x1f40c
movb 0x14(%rax), %al
movq (%r13,%r15,8), %rcx
movb %al, 0x14(%rcx)
movq (%r13,%r12,8), %rax
movb 0x15(%rax), %al
addb $0x8, %al
movq (%r13,%r15,8), %rcx
movb %al, 0x15(%rcx)
movq (%r13,%r12,8), %rax
movzwl 0x2a(%rax), %ebp
movq (%r13,%r15,8), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
pushq $0x24
popq %rdi
pushq $0x2
popq %r8
xorl %ecx, %ecx
callq 0x1ab2a
pushq $0x1
popq %r15
cmpw $0x3fff, %bp            # imm = 0x3FFF
ja 0x1f244
movl %ebx, %edi
movl $0x193, %esi            # imm = 0x193
callq 0x1e16a
movq (%r13,%r12,8), %rax
cmpw $0x193, 0x1a(%rax)      # imm = 0x193
jne 0x1f244
addw $0x4, 0x20(%rax)
movq (%r13,%r12,8), %rax
addw $0x4, 0x22(%rax)
jmp 0x1f244
movl (%rax), %esi
movl 0x4(%rax), %edx
pushq $0x6c
popq %rdi
pushq $0x8
popq %r8
xorl %ecx, %ecx
callq 0x1ab2a
pushq $0x1
popq %r15
jmp 0x1f244