// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4000, -0x18(%rbp)    # imm = 0x4000
jge 0x9a5b
movslq -0x18(%rbp), %rax
leaq 0xd8539(%rip), %rdi     # 0xe1f60
imulq $0x22, %rax, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x22, %edx
callq 0x62d0
movslq -0x18(%rbp), %rcx
leaq 0xd851b(%rip), %rax     # 0xe1f60
imulq $0x22, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x1e(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9a13
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2fee0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x9a7b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bac
movl -0x14(%rbp), %edi
movl $0xffffffde, %esi       # imm = 0xFFFFFFDE
movl $0x2, %edx
callq 0x30590
leaq 0x1604cc(%rip), %rdi    # 0x169f60
xorl %esi, %esi
movl $0x22, %edx
callq 0x62d0
movl -0x14(%rbp), %edi
leaq 0x1604b6(%rip), %rsi    # 0x169f60
movl $0x22, %edx
callq 0x302b0
leaq 0x1604ba(%rip), %rdi    # 0x169f75
leaq 0xa58d8(%rip), %rsi     # 0xaf39a
callq 0x6820
cmpl $0x0, %eax
je 0x9add
leaq 0xa58d4(%rip), %rdi     # 0xaf3a7
callq 0x4a720
jmp 0x9b9d
leaq 0xa58eb(%rip), %rdi     # 0xaf3cf
callq 0x4a720
movl -0x14(%rbp), %edi
movl 0x160472(%rip), %esi    # 0x169f64
xorl %edx, %edx
callq 0x30590
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl 0x160457(%rip), %eax    # 0x169f60
jge 0x9b64
movl -0x14(%rbp), %edi
leaq 0x16046d(%rip), %rsi    # 0x169f82
movl $0x24, %edx
callq 0x302b0
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
cmpq $0x24, %rax
je 0x9b2e
jmp 0x9b64
movswq 0x16044c(%rip), %rax    # 0x169f82
leaq 0xd8423(%rip), %rdi     # 0xe1f60
imulq $0x22, %rax, %rax
addq %rax, %rdi
leaq 0x160437(%rip), %rsi    # 0x169f82
addq $0x2, %rsi
movl $0x22, %edx
callq 0x60c0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9b00
callq 0x9bc0
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x9b8a
movl -0x20(%rbp), %esi
movl -0x18(%rbp), %edx
leaq 0xa5868(%rip), %rdi     # 0xaf3e9
movb $0x0, %al
callq 0x37c90
jmp 0x9b9b
movl -0x18(%rbp), %esi
leaq 0xa5880(%rip), %rdi     # 0xaf414
movb $0x0, %al
callq 0x37c90
jmp 0x9b9d
movl -0x14(%rbp), %edi
callq 0x30960
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)