// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/src/bstub.c
// Function: JS_LoadSpriteExts
int
JS_LoadSpriteExts(const char *mapname)
{
     int       fh,i,nr,nex;

     for (i=0; i<MAXSPRITES; i++) {
          memset(&spriteXT[i], 0, sizeof(struct spriteextension));
          spriteXT[i].lock=0x00;
     }

     fh = kopen4load(mapname, 0);
     if ( fh == -1 ) {
          return(-1);
     }

     // read in XTtrailer 
     klseek(fh, -((int)sizeof(struct XTtrailertype)), SEEK_END);
     memset(&XTtrailer, 0, sizeof(struct XTtrailertype));
     kread(fh, &XTtrailer, sizeof(struct XTtrailertype));

     // if no previous extension info then continue
     if( strcmp(XTtrailer.ID, TRAILERID) != 0 ) {
          buildputs("New File - No extension information...\n");
          goto noext;
     }

     buildputs("Reading in extensions...\n");

     // load and intialize spriteXT array members
     klseek(fh, XTtrailer.start, SEEK_SET);
     for( i=0; i<XTtrailer.numXTs; i++ ) {
          nr=kread(fh, &XTsave, sizeof(struct XTsavetype));
          if( nr != sizeof(struct XTsavetype) )
               break;
          spriteXT[XTsave.XTnum]=XTsave.sprXT;  // struct assign
     }

     nex=JS_CheckExtras();
     if( nex != i ) {
          buildprintf("ERROR: %d Sprite Extras != %d Extensions.\n", nex,i);
     }
     else {
          buildprintf("Loaded %d extensions.\n", i);
     }

noext:

     kclose(fh);

 return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %eax, %eax
leaq 0x9c9e6(%rip), %r15     # 0xa5810
pxor %xmm0, %xmm0
movdqu %xmm0, 0x10(%rax,%r15)
movdqu %xmm0, (%rax,%r15)
movw $0x0, 0x20(%rax,%r15)
addq $0x22, %rax
cmpq $0x88000, %rax          # imm = 0x88000
jne 0x8e2e
xorl %esi, %esi
callq 0x2043c
cmpl $-0x1, %eax
je 0x8ed6
movl %eax, %ebx
movl %eax, %edi
movl $0xffffffde, %esi       # imm = 0xFFFFFFDE
movl $0x2, %edx
callq 0x20872
pxor %xmm0, %xmm0
movdqu %xmm0, 0x124996(%rip)   # 0x12d810
movdqu %xmm0, 0x12499e(%rip)   # 0x12d820
movw $0x0, 0x1249a5(%rip)    # 0x12d830
leaq 0x12497e(%rip), %rsi    # 0x12d810
movl %ebx, %edi
movl $0x22, %edx
callq 0x20684
movabsq $0x58455f50414d2a2a, %rax # imm = 0x58455F50414D2A2A
xorq 0x124976(%rip), %rax    # 0x12d825
movabsq $0x2a2a535458455f, %rcx # imm = 0x2A2A535458455F
xorq 0x12496a(%rip), %rcx    # 0x12d82a
orq %rax, %rcx
je 0x8ee0
leaq 0x6a5e7(%rip), %rdi     # 0x734b3
callq 0x32d18
jmp 0x9002
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x900b
leaq 0x6a5f4(%rip), %rdi     # 0x734db
callq 0x32d18
movl 0x124922(%rip), %esi    # 0x12d814
xorl %ebp, %ebp
movl %ebx, %edi
xorl %edx, %edx
callq 0x20872
cmpl $0x0, 0x12490c(%rip)    # 0x12d810
jle 0x8f68
xorl %ebp, %ebp
leaq 0x124923(%rip), %r14    # 0x12d832
movl %ebx, %edi
movq %r14, %rsi
movl $0x24, %edx
callq 0x20684
cmpl $0x24, %eax
jne 0x8f68
movswq 0x124907(%rip), %rax    # 0x12d832
movq %rax, %rcx
shlq $0x5, %rcx
leaq (%rcx,%rax,2), %rax
movzwl 0x124917(%rip), %ecx    # 0x12d854
movw %cx, 0x20(%r15,%rax)
movups 0x1248fa(%rip), %xmm0   # 0x12d844
movups %xmm0, 0x10(%r15,%rax)
movdqu 0x1248dc(%rip), %xmm0   # 0x12d834
movdqu %xmm0, (%r15,%rax)
incl %ebp
cmpl 0x1248aa(%rip), %ebp    # 0x12d810
jl 0x8f0f
pxor %xmm0, %xmm0
movl $0xae, %eax
leaq 0x273d38(%rip), %rcx    # 0x27ccb0
pcmpeqd %xmm1, %xmm1
movdqa 0x6a26c(%rip), %xmm2    # 0x731f0
movzwl -0x84(%rcx,%rax), %edx
movd %edx, %xmm3
pinsrw $0x1, -0x58(%rcx,%rax), %xmm3
pinsrw $0x2, -0x2c(%rcx,%rax), %xmm3
pinsrw $0x3, (%rcx,%rax), %xmm3
pcmpeqw %xmm1, %xmm3
pxor %xmm1, %xmm3
punpcklwd %xmm3, %xmm3    # xmm3 = xmm3[0,0,1,1,2,2,3,3]
pand %xmm2, %xmm3
paddd %xmm3, %xmm0
addq $0xb0, %rax
cmpq $0xb00ae, %rax          # imm = 0xB00AE
jne 0x8f84
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, %esi
cmpl %ebp, %esi
jne 0x8ff2
leaq 0x6a539(%rip), %rdi     # 0x73520
movl %ebp, %esi
xorl %eax, %eax
callq 0x25221
jmp 0x9002
leaq 0x6a4fc(%rip), %rdi     # 0x734f5
movl %ebp, %edx
xorl %eax, %eax
callq 0x25221
movl %ebx, %edi
callq 0x20b40
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq