// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
callq 0x6fed0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x498c3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x49b11
leaq 0x31ff46(%rip), %rdi    # 0x369810
xorl %esi, %esi
movl $0x30c00, %edx          # imm = 0x30C00
callq 0x62d0
movq -0x18(%rbp), %rdi
callq 0x6efc0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x498ef
jmp 0x49b01
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rcx
leaq 0x9784f(%rip), %rax     # 0xe1150
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x49940
movq -0x20(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq 0x97833(%rip), %rax     # 0xe1150
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x67c0
cmpl $0x0, %eax
jne 0x49933
jmp 0x49940
jmp 0x49935
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x498f6
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movslq -0x2c(%rbp), %rax
shlq $0x4, %rax
leaq 0x977f5(%rip), %rcx     # 0xe1150
movl 0x8(%rax,%rcx), %eax
movq %rax, -0x40(%rbp)
subq $0x3, %rax
ja 0x49afa
movq -0x40(%rbp), %rax
leaq 0x693c8(%rip), %rcx     # 0xb2d40
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x6f220
cmpl $0x0, %eax
je 0x49998
jmp 0x49afc
cmpl $0x4000, -0x30(%rbp)    # imm = 0x4000
jb 0x499df
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6f180
movq -0x48(%rbp), %rdx
movl %eax, %ecx
leaq 0x696af(%rip), %rdi     # 0xb3076
movl $0x3fff, %esi           # imm = 0x3FFF
movb $0x0, %al
callq 0x37c90
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x49afc
jmp 0x49afc
movq -0x18(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x6f220
cmpl $0x0, %eax
je 0x499fb
jmp 0x49afc
cmpl $0x0, -0x30(%rbp)
jge 0x49a33
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6f180
movq -0x50(%rbp), %rsi
movl %eax, %edx
leaq 0x6967e(%rip), %rdi     # 0xb30a5
movb $0x0, %al
callq 0x37c90
jmp 0x49afc
movl -0x34(%rbp), %eax
movw %ax, %cx
movslq -0x30(%rbp), %rdx
leaq 0x31fdcc(%rip), %rax    # 0x369810
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movw %cx, 0x6(%rax)
jmp 0x49afc
cmpl $0x0, -0x30(%rbp)
jge 0x49a89
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6f180
movq -0x58(%rbp), %rsi
movl %eax, %edx
leaq 0x6967c(%rip), %rdi     # 0xb30fc
movb $0x0, %al
callq 0x37c90
jmp 0x49afc
movslq -0x30(%rbp), %rcx
leaq 0x31fd7c(%rip), %rax    # 0x369810
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzbl 0x8(%rax), %ecx
orl $0x1, %ecx
movb %cl, 0x8(%rax)
jmp 0x49afc
cmpl $0x0, -0x30(%rbp)
jge 0x49adc
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6f180
movq -0x60(%rbp), %rsi
movl %eax, %edx
leaq 0x6967f(%rip), %rdi     # 0xb3152
movb $0x0, %al
callq 0x37c90
jmp 0x49afc
movslq -0x30(%rbp), %rcx
leaq 0x31fd29(%rip), %rax    # 0x369810
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzbl 0x8(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x8(%rax)
jmp 0x49afc
jmp 0x49afc
jmp 0x498d6
movq -0x18(%rbp), %rdi
callq 0x700b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)