// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: initengine
int initengine(void)
{
	int i, j;

#if !defined _WIN32 && defined DEBUGGINGAIDS
	struct sigaction sigact, oldact;
	memset(&sigact, 0, sizeof(sigact));
	sigact.sa_sigaction = sighandler;
	sigact.sa_flags = SA_SIGINFO;
	sigaction(SIGFPE, &sigact, &oldact);
#endif
	if (!preinitcalled) {
		i = preinitengine();
		if (i) return i;
	}

	xyaspect = -1;

	pskyoff[0] = 0; pskybits = 0;

	parallaxtype = 2; parallaxyoffs = 0L; parallaxyscale = 65536;
	showinvisibility = 0;

	for(i=1;i<1024;i++) lowrecip[i] = ((1<<24)-1)/i;
	for(i=0;i<MAXVOXELS;i++)
		for(j=0;j<MAXVOXMIPS;j++)
		{
			voxoff[i][j] = 0L;
			voxlock[i][j] = 200;
		}
	for(i=0;i<MAXTILES;i++)
		tiletovox[i] = -1;
	clearbuf(&voxscale[0],sizeof(voxscale)>>2,65536L);

	searchit = 0; searchstat = -1;

	for(i=0;i<MAXPALOOKUPS;i++) palookup[i] = NULL;

	clearbuf(&waloff[0],(int)MAXTILES,0L);

	clearbuf(&show2dsector[0],(int)((MAXSECTORS+3)>>5),0L);
	clearbuf(&show2dsprite[0],(int)((MAXSPRITES+3)>>5),0L);
	clearbuf(&show2dwall[0],(int)((MAXWALLS+3)>>5),0L);
	automapping = 0;

	pointhighlight = -1;
	linehighlight = -1;
	highlightcnt = 0;

	totalclock = 0;
	visibility = 512;
	parallaxvisibility = 512;

	captureformat = 2;  // PNG

	if (loadtables()) return 1;
	if (loadpalette()) return 1;

#if USE_POLYMOST
	polymost_initosdfuncs();
#endif
#if USE_POLYMOST && USE_OPENGL
	if (!hicfirstinit) hicinit();
	if (!mdinited) mdinit();
	PTCacheLoadIndex();
#endif

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpb $0x0, 0x334355(%rip)    # 0x3568b4
jne 0x22566
callq 0x2238f
orl $-0x1, 0x33434b(%rip)   # 0x3568b8
andw $0x0, 0x33434b(%rip)    # 0x3568c0
andw $0x0, 0x334543(%rip)    # 0x356ac0
movb $0x2, 0x33453e(%rip)    # 0x356ac2
andl $0x0, 0x334539(%rip)    # 0x356ac4
movl $0x10000, 0x334533(%rip) # imm = 0x10000
movb $0x0, 0x334530(%rip)    # 0x356acc
pushq $0x1
popq %rcx
leaq 0x33452a(%rip), %rsi    # 0x356ad0
cmpq $0x400, %rcx            # imm = 0x400
je 0x225c0
movl $0xffffff, %eax         # imm = 0xFFFFFF
xorl %edx, %edx
divl %ecx
movl %eax, (%rsi,%rcx,4)
incq %rcx
jmp 0x225a6
leaq 0x335509(%rip), %rax    # 0x357ad0
leaq 0x35d502(%rip), %rcx    # 0x37fad0
xorl %edx, %edx
cmpq $0x1000, %rdx           # imm = 0x1000
je 0x225fc
xorl %esi, %esi
cmpq $0x5, %rsi
je 0x225ef
andq $0x0, (%rax,%rsi,8)
movb $-0x38, (%rcx,%rsi)
incq %rsi
jmp 0x225db
incq %rdx
addq $0x28, %rax
addq $0x5, %rcx
jmp 0x225d0
xorl %eax, %eax
leaq 0x3624cb(%rip), %rcx    # 0x384ad0
cmpq $0x9000, %rax           # imm = 0x9000
je 0x22617
orl $-0x1, (%rax,%rcx)
addq $0x4, %rax
jmp 0x22605
leaq 0x36b4b2(%rip), %rdi    # 0x38dad0
movl $0x1000, %esi           # imm = 0x1000
movl $0x10000, %edx          # imm = 0x10000
callq 0x444af
andw $0x0, 0x36f49b(%rip)    # 0x391ad0
orw $-0x1, 0x36f495(%rip)   # 0x391ad2
xorl %eax, %eax
leaq 0x36f49a(%rip), %r15    # 0x391ae0
cmpq $0x800, %rax            # imm = 0x800
je 0x22659
andq $0x0, (%rax,%r15)
addq $0x8, %rax
jmp 0x22646
leaq 0x36fc80(%rip), %rdi    # 0x3922e0
xorl %ebx, %ebx
movl $0x2400, %esi           # imm = 0x2400
xorl %edx, %edx
callq 0x444af
leaq 0x381c6b(%rip), %rdi    # 0x3a42e0
movl $0x80, %esi
xorl %edx, %edx
callq 0x444af
leaq 0x381e58(%rip), %rdi    # 0x3a44e0
movl $0x200, %ebp            # imm = 0x200
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x444af
leaq 0x382640(%rip), %rdi    # 0x3a4ce0
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x444af
orw $-0x1, 0x382e2e(%rip)   # 0x3a54e2
orw $-0x1, 0x382e28(%rip)   # 0x3a54e4
andw $0x0, 0x382e22(%rip)    # 0x3a54e6
movb $0x0, 0x382e15(%rip)    # 0x3a54e0
andl $0x0, 0x382e16(%rip)    # 0x3a54e8
movl %ebp, 0x382e14(%rip)    # 0x3a54ec
movl %ebp, 0x382e12(%rip)    # 0x3a54f0
movl $0x2, 0x382e0c(%rip)    # 0x3a54f4
pushq $0x1
popq %rdi
leaq 0x42ea0e(%rip), %rax    # 0x451100
leaq 0x42c807(%rip), %rcx    # 0x44ef00
xorl %edx, %edx
xorl %esi, %esi
cmpq $0x1000, %rdx           # imm = 0x1000
je 0x227b6
movslq %edi, %r10
movl %edx, %r9d
shll $0x12, %r9d
orl $0x20000, %r9d          # imm = 0x20000
movl $0x20000000, %edi       # imm = 0x20000000
movl $0x40000000, %r8d       # imm = 0x40000000
leal (,%rdi,4), %r11d
cmpl %r8d, %r9d
movl %r8d, %ebp
cmovbl %ebx, %ebp
cmovbl %ebx, %r11d
subl %ebp, %r9d
subl %edi, %r8d
addl %r11d, %r8d
shrl %r8d
movl %edi, %r11d
shrl $0x2, %r11d
cmpl $0x3, %edi
movl %r11d, %edi
ja 0x22726
leal (,%r10,4), %edi
xorl %r11d, %r11d
cmpq %r10, %rdx
setge %r11b
cmovll %r10d, %edi
addl %r11d, %esi
cmpl %r8d, %r9d
sbbl $-0x1, %r8d
andl $0xfffe, %r8d           # imm = 0xFFFE
movw %r8w, (%rax,%rdx,2)
imull $0xffffff02, %esi, %r8d # imm = 0xFFFFFF02
leal 0xa00(%r8), %r9d
movw %r9w, (%rcx,%rdx,2)
cmpq $0xff, %rdx
ja 0x227ae
addl $0x40c, %r8d            # imm = 0x40C
movw %r8w, 0x2000(%rcx,%rdx,2)
incq %rdx
jmp 0x226fd
leaq 0x4226a3(%rip), %r14    # 0x444e60
leaq 0x3a558c(%rip), %r12    # 0x3c7d50
xorl %r13d, %r13d
movabsq $0x20000000000, %rbx    # imm = 0x20000000000
cmpq $0x800, %r13            # imm = 0x800
je 0x22824
cvtsi2sd %r13d, %xmm0
mulsd 0x49771(%rip), %xmm0    # 0x6bf58
mulsd 0x49771(%rip), %xmm0    # 0x6bf60
callq 0x6390
mulsd 0x4976c(%rip), %xmm0    # 0x6bf68
cvttsd2si %xmm0, %eax
movw %ax, (%r12)
leaq 0x800(%r13), %rcx
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
movl %eax, (%r14)
incq %r13
addq $0x4, %r14
addq $0x2, %r12
jmp 0x227d1
leaq 0x407d13(%rip), %rbx    # 0x42a53e
leaq 0x40730e(%rip), %r14    # 0x429b40
xorl %r12d, %r12d
cmpq $0x280, %r12            # imm = 0x280
je 0x2288a
cvtsi2sd %r12d, %xmm0
addsd 0x49725(%rip), %xmm0    # 0x6bf70
divsd 0x49725(%rip), %xmm0    # 0x6bf78
callq 0x6c80
mulsd 0x49720(%rip), %xmm0    # 0x6bf80
mulsd 0x49720(%rip), %xmm0    # 0x6bf88
divsd 0x496e8(%rip), %xmm0    # 0x6bf58
cvttsd2si %xmm0, %eax
movw %ax, (%r14)
negl %eax
movw %ax, (%rbx)
incq %r12
addq $-0x2, %rbx
addq $0x2, %r14
jmp 0x22835
leaq 0x40d91f(%rip), %rbx    # 0x4301b0
xorl %r14d, %r14d
cmpq $0x10, %r14
je 0x2290e
leal 0x8(%r14), %eax
cvtsi2sd %eax, %xmm0
movsd 0x496e6(%rip), %xmm1    # 0x6bf90
divsd %xmm0, %xmm1
movsd 0x496e2(%rip), %xmm0    # 0x6bf98
movsd %xmm1, 0x10(%rsp)
callq 0x6380
movsd 0x496cf(%rip), %xmm1    # 0x6bf98
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
xorl %r12d, %r12d
cmpq $0x100, %r12            # imm = 0x100
je 0x22902
cvtsi2sd %r12d, %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x6380
mulsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movb %al, (%rbx,%r12)
incq %r12
jmp 0x228d6
incq %r14
addq $0x100, %rbx            # imm = 0x100
jmp 0x22894
leaq 0x3a543b(%rip), %rdi    # 0x3c7d50
movl $0x1000, %esi           # imm = 0x1000
callq 0x64918
cmpl $0xee1e7aba, %eax       # imm = 0xEE1E7ABA
jne 0x22999
leaq 0x407213(%rip), %rdi    # 0x429b40
movl $0x500, %esi            # imm = 0x500
callq 0x64918
cmpl $0xee893d92, %eax       # imm = 0xEE893D92
jne 0x229a2
leaq 0x49b11(%rip), %rdi     # 0x6c456
xorl %esi, %esi
callq 0x1dc36
testl %eax, %eax
js 0x229ab
movl %eax, %ebx
movl %eax, %edi
callq 0x1e14c
movl %eax, %ebp
leaq 0x252c4e(%rip), %rsi    # 0x2755b0
movl %ebx, %edi
movl $0x300, %edx            # imm = 0x300
callq 0x1de3f
cmpl $0x300, %eax            # imm = 0x300
jne 0x229cb
movl %ebp, %eax
cmpb $0x2, %al
je 0x229ee
addq $-0x8280, %rax          # imm = 0xFFFF7D80
testb %al, %al
je 0x22afb
leaq 0x49b38(%rip), %rdi     # 0x6c4c8
xorl %eax, %eax
callq 0x22427
jmp 0x229d7
leaq 0x49a4e(%rip), %rax     # 0x6c3ee
jmp 0x229b2
leaq 0x49a79(%rip), %rax     # 0x6c422
jmp 0x229b2
leaq 0x49b7d(%rip), %rax     # 0x6c52f
movq %rax, 0x18f067(%rip)    # 0x1b1a20
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49a90(%rip), %rdi     # 0x6c462
callq 0x30c8d
leaq 0x49b51(%rip), %rax     # 0x6c52f
movq %rax, 0x18f03b(%rip)    # 0x1b1a20
movl %ebx, %edi
callq 0x1e2db
jmp 0x229b9
leaq 0x3eae33(%rip), %rsi    # 0x40d828
pushq $0x2
popq %rdx
movl %ebx, %edi
callq 0x1de3f
cmpl $0x2, %eax
jne 0x22b1c
movswq 0x3eae18(%rip), %rdi    # 0x40d828
shlq $0x8, %rdi
callq 0x69a0
movq %rax, 0x36f0c0(%rip)    # 0x391ae0
testq %rax, %rax
je 0x22cc7
movq %rax, %r14
movl $0x10000, %edi          # imm = 0x10000
callq 0x69a0
movq %rax, 0x18eff3(%rip)    # 0x1b1a30
testq %rax, %rax
je 0x22cd3
movq %r14, 0x3e65bb(%rip)    # 0x409008
andl $0x0, 0x3e65b0(%rip)    # 0x409004
movq %r14, %rdi
callq 0x641cb
movq 0x18efcd(%rip), %rdi    # 0x1b1a30
callq 0x6419f
movslq 0x3e6595(%rip), %rax    # 0x409004
movq (%r15,%rax,8), %rsi
movswl 0x3eadae(%rip), %edx    # 0x40d828
shll $0x8, %edx
movl %ebx, %edi
callq 0x1de3f
movq 0x18efa5(%rip), %rsi    # 0x1b1a30
movl %ebx, %edi
movl $0x10000, %edx          # imm = 0x10000
callq 0x1de3f
movl %ebx, %edi
callq 0x1e2db
xorl %eax, %eax
movl $0x80, %ecx
pushq $0x40
popq %rdx
leaq 0x251ff1(%rip), %rsi    # 0x274aa0
leaq 0x2521fa(%rip), %rdi    # 0x274cb0
leaq 0x252403(%rip), %r8     # 0x274ec0
movq %rdx, %r9
testq %r9, %r9
js 0x22b28
imull $0x1e, %eax, %r10d
movl %r10d, (%rsi,%rdx,4)
movl %r10d, (%rsi,%r9,4)
imull $0x3b, %eax, %r10d
movl %r10d, (%rdi,%rdx,4)
movl %r10d, (%rdi,%r9,4)
imull $0xb, %eax, %r10d
movl %r10d, (%r8,%rdx,4)
movl %r10d, (%r8,%r9,4)
subl %ecx, %eax
addl $0x81, %eax
decq %r9
addl $-0x2, %ecx
incq %rdx
jmp 0x22ac0
shrq $0x8, %rax
movw %ax, 0x3ead22(%rip)     # 0x40d828
movswl %ax, %esi
leaq 0x4998b(%rip), %rdi     # 0x6c49b
xorl %eax, %eax
callq 0x22427
jmp 0x229d7
leaq 0x4995f(%rip), %rdi     # 0x6c482
jmp 0x229d2
xorpd %xmm0, %xmm0
movupd %xmm0, 0x252679(%rip)   # 0x2751ad
movapd %xmm0, 0x252664(%rip)   # 0x2751a0
movapd %xmm0, 0x25264c(%rip)   # 0x275190
movapd %xmm0, 0x252634(%rip)   # 0x275180
movapd %xmm0, 0x25261c(%rip)   # 0x275170
movapd %xmm0, 0x252604(%rip)   # 0x275160
movapd %xmm0, 0x2525ec(%rip)   # 0x275150
movapd %xmm0, 0x2525d4(%rip)   # 0x275140
leaq 0x25264d(%rip), %rbx    # 0x2751c0
movl $0x3e8, %edx            # imm = 0x3E8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x62f0
leaq 0x252d24(%rip), %rax    # 0x2758ad
movl $0xff, %ecx
leaq 0x2525ab(%rip), %rdx    # 0x275140
leaq 0x7ac04(%rip), %rsi     # 0x9d7a0
leaq 0x252d0d(%rip), %rdi    # 0x2758b0
testl %ecx, %ecx
js 0x22c11
movzbl (%rax), %r8d
andl $-0x8, %r8d
movzbl 0x1(%rax), %r9d
andl $-0x8, %r9d
movzbl 0x2(%rax), %r10d
shrl $0x3, %r10d
leal (%r9,%r8,8), %r8d
leaq (%r8,%r10), %r9
addq $0x49, %r9
movl %r9d, %r8d
shrl $0x3, %r8d
movb (%r8,%rdx), %r10b
movl %r9d, %r11d
andl $0x7, %r11d
movb (%r11,%rsi), %r11b
movl %ecx, %r14d
testb %r10b, %r11b
je 0x22bf6
movzbl (%r9,%rbx), %ebp
movl %ebp, (%rdi,%r14,4)
jmp 0x22bfe
orl $-0x1, (%rdi,%r14,4)
movl %r9d, %r9d
movb %cl, (%r9,%rbx)
orb %r10b, %r11b
movb %r11b, (%r8,%rdx)
decl %ecx
addq $-0x3, %rax
jmp 0x22ba3
pushq $-0x40
popq %rax
xorl %ecx, %ecx
pushq $-0x49
popq %rdx
pushq $-0x8
popq %rsi
leaq 0x2524ad(%rip), %rdi    # 0x2750d0
cmpl $0x40, %eax
jg 0x22c7c
leal 0x3(%rcx), %r8d
movq %rdx, %r9
movl %esi, %r10d
cmpl $0x8, %r10d
jg 0x22c73
movslq %ecx, %rcx
leaq (,%rcx,4), %r11
movslq %r8d, %rbx
subq %rcx, %rbx
addl $0x3, %ecx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x22c65
leal (%r9,%r14), %ebp
leaq (%r11,%r14,4), %r15
movl %ebp, (%rdi,%r15)
incq %r14
jmp 0x22c4f
addl $0x8, %r10d
addl $0x3, %r8d
addq $0x8, %r9
jmp 0x22c32
addl $0x40, %eax
addq $0x40, %rdx
jmp 0x22c23
movl 0x252482(%rip), %eax    # 0x275104
movl 0x2524b0(%rip), %ecx    # 0x275138
movl %ecx, 0x252476(%rip)    # 0x275104
movl %eax, 0x2524a4(%rip)    # 0x275138
callq 0x54086
leaq 0x60cf70(%rip), %rax    # 0x62fc10
cmpl $0x0, (%rax)
jne 0x22caa
callq 0x55478
leaq 0x61f36f(%rip), %rax    # 0x642020
cmpb $0x0, (%rax)
jne 0x22cbb
callq 0x55b36
callq 0x5d72c
xorl %eax, %eax
jmp 0x229bc
leaq 0x49818(%rip), %rax     # 0x6c4e6
jmp 0x229de
leaq 0x4982e(%rip), %rax     # 0x6c508
jmp 0x229de