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

     buildputs("Appending extensions...\n");

     fh=open(mapname, O_BINARY | O_WRONLY, 0);
     if ( fh == -1 ) {
          return(-1);
     }

     //checkextras();

     // prepare trailer
     memset(&XTtrailer, 0, sizeof(struct XTtrailertype));
     strncpy(XTtrailer.mapname, mapname, 12);
     XTtrailer.mapname[12]='\0';
     strcpy(XTtrailer.ID, TRAILERID);
     XTtrailer.ID[12]='\0';
     XTtrailer.numXTs=0L;

     // go to end of map = beginning of eXTensions
     XTtrailer.start=(int)lseek(fh, 0, SEEK_END);

     // verify extension then
     // write extensions to end of map file
     XTtrailer.numXTs=0L;
     for (i=0; i<MAXSPRITES; i++) {
          if( spriteXT[i].lock == 0xFF ) {
               memset(&XTsave, 0, sizeof(struct XTsavetype));
               XTtrailer.numXTs++;
               XTsave.XTnum=i;
               XTsave.sprXT=spriteXT[i];
               write(fh, &XTsave, sizeof(struct XTsavetype));
          }
     }

     // write trailer 
     write(fh, &XTtrailer, sizeof(struct XTtrailertype));
     close(fh);

 return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
leaq 0xa58cd(%rip), %rdi     # 0xaf500
callq 0x4a720
movq -0x10(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x6430
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x9c5f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9da2
leaq 0x1602fa(%rip), %rdi    # 0x169f60
xorl %esi, %esi
movl $0x22, %edx
callq 0x62d0
movq -0x10(%rbp), %rsi
leaq 0x1602e3(%rip), %rdi    # 0x169f60
addq $0x8, %rdi
movl $0xc, %edx
callq 0x6180
movb $0x0, 0x1602e2(%rip)    # 0x169f74
leaq 0x1602dc(%rip), %rdi    # 0x169f75
leaq 0xa56fa(%rip), %rsi     # 0xaf39a
callq 0x63e0
movb $0x0, 0x1602d5(%rip)    # 0x169f81
movl $0x0, 0x1602aa(%rip)    # 0x169f60
movl -0x14(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x62a0
movl %eax, 0x160297(%rip)    # 0x169f64
movl $0x0, 0x160289(%rip)    # 0x169f60
movl $0x0, -0x18(%rbp)
cmpl $0x4000, -0x18(%rbp)    # imm = 0x4000
jge 0x9d7f
movslq -0x18(%rbp), %rcx
leaq 0xd826a(%rip), %rax     # 0xe1f60
imulq $0x22, %rcx, %rcx
addq %rcx, %rax
movzbl 0x1e(%rax), %eax
cmpl $0xff, %eax
jne 0x9d6f
leaq 0x160273(%rip), %rdi    # 0x169f82
xorl %esi, %esi
movl $0x24, %edx
callq 0x62d0
movl 0x16023f(%rip), %eax    # 0x169f60
addl $0x1, %eax
movl %eax, 0x160236(%rip)    # 0x169f60
movl -0x18(%rbp), %eax
movw %ax, 0x16024e(%rip)     # 0x169f82
movslq -0x18(%rbp), %rax
leaq 0xd8221(%rip), %rsi     # 0xe1f60
imulq $0x22, %rax, %rax
addq %rax, %rsi
leaq 0x160235(%rip), %rdi    # 0x169f82
addq $0x2, %rdi
movl $0x22, %edx
callq 0x60c0
movl -0x14(%rbp), %edi
leaq 0x16021d(%rip), %rsi    # 0x169f82
movl $0x24, %edx
callq 0x6a20
jmp 0x9d71
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9cde
movl -0x14(%rbp), %edi
leaq 0x1601d7(%rip), %rsi    # 0x169f60
movl $0x22, %edx
callq 0x6a20
movl -0x14(%rbp), %edi
callq 0x6220
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)