// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
xorl %eax, %eax
leaq 0x9bafa(%rip), %r12     # 0xa4810
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax,%r12)
movups %xmm0, (%rax,%r12)
movw $0x0, 0x20(%rax,%r12)
addq $0x22, %rax
cmpq $0x88000, %rax          # imm = 0x88000
jne 0x8d19
xorl %esi, %esi
callq 0x1ff50
cmpl $-0x1, %eax
je 0x8dbc
movl %eax, %ebx
movl %eax, %edi
movl $0xffffffde, %esi       # imm = 0xFFFFFFDE
movl $0x2, %edx
callq 0x203a8
xorps %xmm0, %xmm0
movups %xmm0, 0x123aaf(%rip)   # 0x12c810
movups %xmm0, 0x123ab8(%rip)   # 0x12c820
movw $0x0, 0x123abf(%rip)    # 0x12c830
leaq 0x123a98(%rip), %rsi    # 0x12c810
movl %ebx, %edi
movl $0x22, %edx
callq 0x201c2
movabsq $0x58455f50414d2a2a, %rax # imm = 0x58455F50414D2A2A
xorq 0x123a90(%rip), %rax    # 0x12c825
movabsq $0x2a2a535458455f, %rcx # imm = 0x2A2A535458455F
xorq 0x123a84(%rip), %rcx    # 0x12c82a
orq %rax, %rcx
je 0x8dc6
leaq 0x696b5(%rip), %rdi     # 0x72467
callq 0x32200
jmp 0x8ea4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x8ead
leaq 0x696c2(%rip), %rdi     # 0x7248f
callq 0x32200
movl 0x123a3c(%rip), %esi    # 0x12c814
xorl %ebp, %ebp
movl %ebx, %edi
xorl %edx, %edx
callq 0x203a8
cmpl $0x0, 0x123a26(%rip)    # 0x12c810
movl $0x0, %r14d
jle 0x8e55
xorl %r14d, %r14d
leaq 0x123a36(%rip), %r15    # 0x12c832
movl %ebx, %edi
movq %r15, %rsi
movl $0x24, %edx
callq 0x201c2
cmpl $0x24, %eax
jne 0x8e55
movswq 0x123a1a(%rip), %rax    # 0x12c832
movq %rax, %rcx
shlq $0x5, %rcx
leaq (%rcx,%rax,2), %rax
movzwl 0x123a2a(%rip), %ecx    # 0x12c854
movw %cx, 0x20(%r12,%rax)
movups 0x123a0d(%rip), %xmm0   # 0x12c844
movups %xmm0, 0x10(%r12,%rax)
movups 0x1239f0(%rip), %xmm0   # 0x12c834
movups %xmm0, (%r12,%rax)
incl %r14d
cmpl 0x1239bd(%rip), %r14d   # 0x12c810
jl 0x8dfc
movl $0x2a, %eax
leaq 0x272e4f(%rip), %rcx    # 0x27bcb0
xorl %edx, %edx
cmpw $-0x1, (%rcx,%rax)
setne %dl
addl %edx, %ebp
addq $0x2c, %rax
cmpq $0xb002a, %rax          # imm = 0xB002A
jne 0x8e61
cmpl %r14d, %ebp
jne 0x8e91
leaq 0x6964f(%rip), %rdi     # 0x724d4
movl %r14d, %esi
xorl %eax, %eax
callq 0x24cb4
jmp 0x8ea4
leaq 0x69611(%rip), %rdi     # 0x724a9
movl %ebp, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x24cb4
movl %ebx, %edi
callq 0x20671
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq