// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
orl $-0x1, (%rsp)
callq 0x44c62
testq %rax, %rax
je 0x2f285
movq %rax, %rbx
leaq 0x2f6bc5(%rip), %rdi    # 0x325cb0
movl $0x30c00, %edx          # imm = 0x30C00
xorl %esi, %esi
callq 0x62f0
leaq 0x5ca12(%rip), %r15     # 0x8bb10
leaq 0x3cdc7(%rip), %r13     # 0x6becc
leaq 0x5c974(%rip), %r14     # 0x8ba80
movq %rbx, %rdi
callq 0x4454c
testq %rax, %rax
je 0x2f279
movq %rax, %rbp
xorl %ecx, %ecx
leaq 0x10(%rcx), %r12
cmpq $0xa0, %r12
je 0x2f14c
movq (%rcx,%r14), %rsi
movq %rbp, %rdi
callq 0x6880
movq %r12, %rcx
testl %eax, %eax
jne 0x2f122
leaq (%r12,%r14), %rax
addq $-0x10, %rax
jmp 0x2f14f
movq %r15, %rax
movl 0x8(%rax), %eax
cmpq $0x3, %rax
ja 0x2f10c
movq 0x10(%rbx), %rbp
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4465e
testl %eax, %eax
jne 0x2f10c
cmpl $0x4000, (%rsp)         # imm = 0x4000
jb 0x2f10c
movq 0x28(%rbx), %r12
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x44619
leaq 0x3cf8f(%rip), %rdi     # 0x6c123
movl $0x3fff, %esi           # imm = 0x3FFF
movq %r12, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x22427
orl $-0x1, (%rsp)
jmp 0x2f10c
movslq (%rsp), %rax
testq %rax, %rax
js 0x2f222
imulq $0xc, %rax, %rax
leaq 0x2f6aee(%rip), %rcx    # 0x325cb0
orb $0x1, 0x8(%rax,%rcx)
jmp 0x2f10c
movslq (%rsp), %rax
testq %rax, %rax
js 0x2f23a
imulq $0xc, %rax, %rax
leaq 0x2f6ad0(%rip), %rcx    # 0x325cb0
orb $0x2, 0x8(%rax,%rcx)
jmp 0x2f10c
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x4465e
testl %eax, %eax
jne 0x2f10c
movslq (%rsp), %rax
testq %rax, %rax
js 0x2f252
movzwl 0x4(%rsp), %ecx
imulq $0xc, %rax, %rax
leaq 0x2f6a98(%rip), %rdx    # 0x325cb0
movw %cx, 0x6(%rax,%rdx)
jmp 0x2f10c
movq 0x28(%rbx), %r12
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x44619
leaq 0x3cf71(%rip), %rdi     # 0x6c1a9
jmp 0x2f268
movq 0x28(%rbx), %r12
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x44619
leaq 0x3cfaf(%rip), %rdi     # 0x6c1ff
jmp 0x2f268
movq 0x28(%rbx), %r12
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x44619
leaq 0x3ceea(%rip), %rdi     # 0x6c152
movq %r12, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x22427
jmp 0x2f10c
movq %rbx, %rdi
callq 0x44d91
xorl %eax, %eax
jmp 0x2f288
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq