// File: /workspace/github_c_makefile_star2_O1/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 0x4b43d
testq %rax, %rax
je 0x3189a
movq %rax, %r14
leaq 0x2fa5e5(%rip), %rdi    # 0x32bcb0
movl $0x30c00, %edx          # imm = 0x30C00
xorl %esi, %esi
callq 0x62f0
movq %r14, %rdi
callq 0x4ac84
testq %rax, %rax
je 0x3188e
movq %rax, %r13
leaq 0x6035e(%rip), %rbx     # 0x91a50
leaq 0x44737(%rip), %r15     # 0x75e30
movl $0x90, %r12d
leaq (%rbx,%r12), %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
leaq 0x44989(%rip), %rsi     # 0x7609b
callq 0x6880
movq %rbx, %rbp
testl %eax, %eax
je 0x31747
xorl %ecx, %ecx
leaq 0x10(%rcx), %rbp
cmpq %r12, %rbp
je 0x31742
movq 0x10(%rcx,%rbx), %rsi
movq %r13, %rdi
callq 0x6880
movq %rbp, %rcx
testl %eax, %eax
jne 0x31720
addq %rbx, %rbp
jmp 0x31747
movq 0x10(%rsp), %rbp
movl 0x8(%rbp), %eax
cmpq $0x3, %rax
ja 0x3187a
movq 0x10(%r14), %r13
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4ad79
testl %eax, %eax
jne 0x3187a
cmpl $0x4000, 0x8(%rsp)      # imm = 0x4000
jb 0x3187a
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4ad2c
leaq 0x44949(%rip), %rdi     # 0x760e3
movl $0x3fff, %esi           # imm = 0x3FFF
movq %rbp, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x24cb4
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
jmp 0x3187a
movslq 0x8(%rsp), %rax
testq %rax, %rax
js 0x31828
leaq (%rax,%rax,2), %rax
leaq 0x2fa4e3(%rip), %rcx    # 0x32bcb0
orb $0x1, 0x8(%rcx,%rax,4)
jmp 0x3187a
movslq 0x8(%rsp), %rax
testq %rax, %rax
js 0x31840
leaq (%rax,%rax,2), %rax
leaq 0x2fa4c4(%rip), %rcx    # 0x32bcb0
orb $0x2, 0x8(%rcx,%rax,4)
jmp 0x3187a
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x4ad79
testl %eax, %eax
jne 0x3187a
movslq 0x8(%rsp), %rax
testq %rax, %rax
js 0x31858
movzwl 0xc(%rsp), %ecx
leaq (%rax,%rax,2), %rax
leaq 0x2fa48f(%rip), %rdx    # 0x32bcb0
movw %cx, 0x6(%rdx,%rax,4)
jmp 0x3187a
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4ad2c
leaq 0x4492b(%rip), %rdi     # 0x76169
jmp 0x3186e
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4ad2c
leaq 0x44969(%rip), %rdi     # 0x761bf
jmp 0x3186e
movq 0x28(%r14), %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x4ad2c
leaq 0x448a4(%rip), %rdi     # 0x76112
movq %rbp, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x24cb4
movq %r14, %rdi
callq 0x4ac84
movq %rax, %r13
testq %rax, %rax
jne 0x31708
movq %r14, %rdi
callq 0x4b574
xorl %eax, %eax
jmp 0x3189f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq