// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: loadmaphack
int loadmaphack(char *filename)
{
#if USE_POLYMOST && USE_OPENGL
	static struct { char *text; int tokenid; } legaltokens[] = {
		{ "sprite", 0 },
		{ "angleoff", 1 },
		{ "angoff", 1 },
		{ "notmd2", 2 },
		{ "notmd3", 2 },
		{ "notmd", 2 },
		{ "nomd2anim", 3 },
		{ "nomd3anim", 3 },
		{ "nomdanim", 3 },
		{ NULL, -1 }
	};

	scriptfile *script;
	char *tok, *cmdtokptr;
	int i;
	int whichsprite = -1;

	script = scriptfile_fromfile(filename);
	if (!script) return -1;

	memset(spriteext, 0, sizeof(spriteext));

	while (1) {
		tok = scriptfile_gettoken(script);
		if (!tok) break;
		for (i=0;legaltokens[i].text;i++) if (!Bstrcasecmp(tok,legaltokens[i].text)) break;
		cmdtokptr = script->ltextptr;
		switch (legaltokens[i].tokenid) {
			case 0:		// sprite <xx>
				if (scriptfile_getnumber(script, &whichsprite)) break;

				if ((unsigned)whichsprite >= (unsigned)MAXSPRITES) {
					// sprite number out of range
					buildprintf("Sprite number out of range 0-%d on line %s:%d\n",
							MAXSPRITES-1,script->filename, scriptfile_getlinum(script,cmdtokptr));
					whichsprite = -1;
					break;
				}

				break;
			case 1:		// angoff <xx>
				{
					int ang;
					if (scriptfile_getnumber(script, &ang)) break;

					if (whichsprite < 0) {
						// no sprite directive preceeding
						buildprintf("Ignoring angle offset directive because of absent/invalid sprite number on line %s:%d\n",
							script->filename, scriptfile_getlinum(script,cmdtokptr));
						break;
					}
					spriteext[whichsprite].angoff = (short)ang;
				}
				break;
			case 2:      // notmd
				if (whichsprite < 0) {
					// no sprite directive preceeding
					buildprintf("Ignoring not-MD2/MD3 directive because of absent/invalid sprite number on line %s:%d\n",
							script->filename, scriptfile_getlinum(script,cmdtokptr));
					break;
				}
				spriteext[whichsprite].flags |= SPREXT_NOTMD;
				break;
			case 3:      // nomdanim
				if (whichsprite < 0) {
					// no sprite directive preceeding
					buildprintf("Ignoring no-MD2/MD3-anim directive because of absent/invalid sprite number on line %s:%d\n",
							script->filename, scriptfile_getlinum(script,cmdtokptr));
					break;
				}
				spriteext[whichsprite].flags |= SPREXT_NOMDANIM;
				break;
			default:
				// unrecognised token
				break;
		}
	}

	scriptfile_close(script);
#else
	(void)filename;
#endif //USE_POLYMOST && USE_OPENGL

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
callq 0x4dbed
testq %rax, %rax
je 0x323b8
movq %rax, %r14
leaq 0x2faac7(%rip), %rdi    # 0x32ccb0
movl $0x30c00, %edx          # imm = 0x30C00
xorl %esi, %esi
callq 0x62f0
movq %r14, %rdi
callq 0x4d468
testq %rax, %rax
je 0x323ac
movq %rax, %r13
leaq 0x60890(%rip), %rbx     # 0x92aa0
leaq 0x44d29(%rip), %r15     # 0x76f40
movl $0x90, %r12d
leaq (%rbx,%r12), %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
leaq 0x44feb(%rip), %rsi     # 0x7721b
callq 0x6880
movq %rbx, %rbp
testl %eax, %eax
je 0x32265
xorl %ecx, %ecx
leaq 0x10(%rcx), %rbp
cmpq %r12, %rbp
je 0x32260
movq 0x10(%rcx,%rbx), %rsi
movq %r13, %rdi
callq 0x6880
movq %rbp, %rcx
testl %eax, %eax
jne 0x3223e
addq %rbx, %rbp
jmp 0x32265
movq 0x10(%rsp), %rbp
movl 0x8(%rbp), %eax
cmpq $0x3, %rax
ja 0x32398
movq 0x10(%r14), %r13
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4d559
testl %eax, %eax
jne 0x32398
cmpl $0x4000, 0x8(%rsp)      # imm = 0x4000
jb 0x32398
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4d50c
leaq 0x44fab(%rip), %rdi     # 0x77263
movl $0x3fff, %esi           # imm = 0x3FFF
movq %rbp, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x25221
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
jmp 0x32398
movslq 0x8(%rsp), %rax
testq %rax, %rax
js 0x32346
leaq (%rax,%rax,2), %rax
leaq 0x2fa9c5(%rip), %rcx    # 0x32ccb0
orb $0x1, 0x8(%rcx,%rax,4)
jmp 0x32398
movslq 0x8(%rsp), %rax
testq %rax, %rax
js 0x3235e
leaq (%rax,%rax,2), %rax
leaq 0x2fa9a6(%rip), %rcx    # 0x32ccb0
orb $0x2, 0x8(%rcx,%rax,4)
jmp 0x32398
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x4d559
testl %eax, %eax
jne 0x32398
movslq 0x8(%rsp), %rax
testq %rax, %rax
js 0x32376
movzwl 0xc(%rsp), %ecx
leaq (%rax,%rax,2), %rax
leaq 0x2fa971(%rip), %rdx    # 0x32ccb0
movw %cx, 0x6(%rdx,%rax,4)
jmp 0x32398
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4d50c
leaq 0x44f8d(%rip), %rdi     # 0x772e9
jmp 0x3238c
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4d50c
leaq 0x44fcb(%rip), %rdi     # 0x7733f
jmp 0x3238c
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4d50c
leaq 0x44f06(%rip), %rdi     # 0x77292
movq %rbp, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x25221
movq %r14, %rdi
callq 0x4d468
movq %rax, %r13
testq %rax, %rax
jne 0x32226
movq %r14, %rdi
callq 0x4dd24
xorl %eax, %eax
jmp 0x323bd
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq