// File: /workspace/github_c_makefile_star2_O1/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 0xadb64(%rip), %rax     # 0xce978
xorl %r15d, %r15d
cmpb $0x0, 0x4(%rax)
je 0x20e2f
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 0x10d3d3(%rip), %r13    # 0x12e210
movq (%r13,%r12,8), %rax
movzwl 0x1a(%rax), %eax
cmpl $0xfa, %eax
je 0x20e1d
cmpl $0x193, %eax            # imm = 0x193
je 0x20e1d
movl %esi, %ebp
movswl %r14w, %ebx
movl %ebx, %edi
callq 0x20c18
testl %eax, %eax
jne 0x20e1d
movl %ebx, %edi
callq 0x20c64
testl %eax, %eax
jne 0x20e1d
leaq 0x54b509(%rip), %rax    # 0x56c380
movzwl 0x1f4(%rax), %ecx
testw %cx, %cx
js 0x20ea2
leaq 0x553d06(%rip), %rax    # 0x574b90
movzwl %cx, %ecx
movq (%r13,%rcx,8), %rdx
cmpw %r14w, 0x1e(%rdx)
je 0x20e1d
movzwl (%rax,%rcx,2), %ecx
testw %cx, %cx
jns 0x20e8a
movq (%r13,%r12,8), %rax
movswl 0x18(%rax), %edi
movl $0xfa, %esi
callq 0x1e94c
cmpw $-0x1, %ax
je 0x20e1d
movswq %ax, %r15
movq (%r13,%r15,8), %rax
movw $0xffff, 0x2a(%rax)     # imm = 0xFFFF
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
xorl %ecx, %ecx
movw %cx, 0xc(%rax)
movq (%r13,%r15,8), %rax
movb $-0x1c, 0x10(%rax)
movq (%r13,%r15,8), %rax
movw %bp, 0xe(%rax)
leaq 0x6c5e0(%rip), %rdi     # 0x8d512
callq 0x2be4a
andl $0x200, %eax            # imm = 0x200
orl $0x80, %eax
movq (%r13,%r15,8), %rcx
movw %ax, 0x26(%rcx)
movq (%r13,%r15,8), %rax
xorl %ecx, %ecx
movw %cx, 0x28(%rax)
movq (%r13,%r15,8), %rax
movw %r14w, 0x1e(%rax)
movq (%r13,%r12,8), %rax
cmpl $0x1c2, %ebp            # imm = 0x1C2
jne 0x20ff4
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
movl $0x24, %edi
xorl %ecx, %ecx
movl $0x2, %r8d
callq 0x1c1f1
movl $0x1, %r15d
cmpw $0x3fff, %bp            # imm = 0x3FFF
ja 0x20e1d
movl %ebx, %edi
movl $0x193, %esi            # imm = 0x193
callq 0x1fc27
movq (%r13,%r12,8), %rax
cmpw $0x193, 0x1a(%rax)      # imm = 0x193
jne 0x20e1d
addw $0x4, 0x20(%rax)
movq (%r13,%r12,8), %rax
addw $0x4, 0x22(%rax)
jmp 0x20e1d
movl (%rax), %esi
movl 0x4(%rax), %edx
movl $0x6c, %edi
xorl %ecx, %ecx
movl $0x8, %r8d
callq 0x1c1f1
movl $0x1, %r15d
jmp 0x20e1d