// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: loadoldboard
int loadoldboard(char *filename, char fromwhere, int *daposx, int *daposy, int *daposz,
			 short *daang, short *dacursectnum)
{
	short fil, i, numsprites;
	struct sectortypev4 v4sect;
	struct walltypev4   v4wall;
	struct spritetypev4 v4spr;
	struct sectortypev5 v5sect;
	struct walltypev5   v5wall;
	struct spritetypev5 v5spr;
	struct sectortypev6 v6sect;
	struct walltypev6   v6wall;
	struct spritetypev6 v6spr;

	i = strlen(filename)-1;
	if ((unsigned char)filename[i] == 255) { filename[i] = 0; fromwhere = 1; }	// JBF 20040119: "compatibility"
	if ((fil = kopen4load(filename,fromwhere)) == -1)
		{ mapversion = 5L; return(-1); }

	if (kread(fil,&mapversion,4) != 4) goto readerror;
	mapversion = B_LITTLE32(mapversion);
	if (mapversion != 4L && mapversion != 5L && mapversion != 6L) {
		kclose(fil);
		return(-2);
	}

	initspritelists();

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

	if (kread(fil,daposx,4) != 4) goto readerror;
	if (kread(fil,daposy,4) != 4) goto readerror;
	if (kread(fil,daposz,4) != 4) goto readerror;
	if (kread(fil,daang,2) != 2) goto readerror;
	if (kread(fil,dacursectnum,2) != 2) goto readerror;
	*daposx = B_LITTLE32(*daposx);
	*daposy = B_LITTLE32(*daposy);
	*daposz = B_LITTLE32(*daposz);
	*daang  = B_LITTLE16(*daang);
	*dacursectnum = B_LITTLE16(*dacursectnum);

	if (mapversion == 4) {
		if (kread(fil,&numsectors,2) != 2) goto readerror;
		if (kread(fil,&numwalls,2) != 2) goto readerror;
		if (kread(fil,&numsprites,2) != 2) goto readerror;
	}

	if (mapversion > 4 && kread(fil,&numsectors,2) != 2) goto readerror;
	numsectors = B_LITTLE16(numsectors);
	if (numsectors > MAXSECTORS) {
		kclose(fil);
		return(-1);
	}

	for (i=0; i<numsectors; i++) {
		switch (mapversion) {
			case 4:
				if (readv4sect(fil,&v4sect)) goto readerror;
				convertv4sectv5(&v4sect,&v5sect);
				convertv5sectv6(&v5sect,&v6sect);
				convertv6sectv7(&v6sect,&sector[i]);
				break;
			case 5:
				if (readv5sect(fil,&v5sect)) goto readerror;
				convertv5sectv6(&v5sect,&v6sect);
				convertv6sectv7(&v6sect,&sector[i]);
				break;
			case 6:
				if (readv6sect(fil,&v6sect)) goto readerror;
				convertv6sectv7(&v6sect,&sector[i]);
				break;
		}
	}

	if (mapversion > 4 && kread(fil,&numwalls,2) != 2) goto readerror;
	numwalls = B_LITTLE16(numwalls);
	if (numwalls > MAXWALLS) {
		kclose(fil);
		return(-1);
	}

	for (i=0; i<numwalls; i++) {
		switch (mapversion) {
			case 4:
				if (readv4wall(fil,&v4wall)) goto readerror;
				convertv4wallv5(&v4wall,&v5wall);
				convertv5wallv6(&v5wall,&v6wall,i);
				convertv6wallv7(&v6wall,&wall[i]);
				break;
			case 5:
				if (readv5wall(fil,&v5wall)) goto readerror;
				convertv5wallv6(&v5wall,&v6wall,i);
				convertv6wallv7(&v6wall,&wall[i]);
				break;
			case 6:
				if (readv6wall(fil,&v6wall)) goto readerror;
				convertv6wallv7(&v6wall,&wall[i]);
				break;
		}
	}

	if (mapversion > 4 && kread(fil,&numsprites,2) != 2) goto readerror;
	numsprites = B_LITTLE16(numsprites);
	if (numsprites > MAXSPRITES) {
		kclose(fil);
		return(-1);
	}

	for (i=0; i<numsprites; i++) {
		switch (mapversion) {
			case 4:
				if (readv4sprite(fil,&v4spr)) goto readerror;
				convertv4sprv5(&v4spr,&v5spr);
				convertv5sprv6(&v5spr,&v6spr);
				convertv6sprv7(&v6spr,&sprite[i]);
				break;
			case 5:
				if (readv5sprite(fil,&v5spr)) goto readerror;
				convertv5sprv6(&v5spr,&v6spr);
				convertv6sprv7(&v6spr,&sprite[i]);
				break;
			case 6:
				if (readv6sprite(fil,&v6spr)) goto readerror;
				convertv6sprv7(&v6spr,&sprite[i]);
				break;
		}
	}

	for(i=0;i<numsprites;i++) {
		if ((sprite[i].cstat & 48) == 48) sprite[i].cstat &= ~48;
		insertsprite(sprite[i].sectnum,sprite[i].statnum);
	}

		//Must be after loading sectors, etc!
	updatesector(*daposx,*daposy,dacursectnum);

	kclose(fil);

#if USE_POLYMOST && USE_OPENGL
	memset(spriteext, 0, sizeof(spriteext));
#endif
	guniqhudid = 0;

	return(0);

readerror:
	kclose(fil);
	return -3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movb %sil, %al
movq 0x10(%rbp), %rsi
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x63d0
subq $0x1, %rax
movw %ax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movswq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xff, %eax
jne 0x4630f
movq -0x10(%rbp), %rax
movswq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movb $0x1, -0x11(%rbp)
movq -0x10(%rbp), %rdi
movsbl -0x11(%rbp), %esi
callq 0x2fee0
movw %ax, -0x3a(%rbp)
cwtl
cmpl $-0x1, %eax
jne 0x4633c
movl $0x5, 0x9a958(%rip)     # 0xe0c88
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x46ad9
movswl -0x3a(%rbp), %edi
leaq 0x9a941(%rip), %rsi     # 0xe0c88
movl $0x4, %edx
callq 0x302b0
cmpl $0x4, %eax
je 0x4635b
jmp 0x46ac9
movl 0x9a927(%rip), %eax     # 0xe0c88
movl %eax, 0x9a921(%rip)     # 0xe0c88
movslq 0x9a91a(%rip), %rax     # 0xe0c88
cmpq $0x4, %rax
je 0x463a3
movslq 0x9a90d(%rip), %rax     # 0xe0c88
cmpq $0x5, %rax
je 0x463a3
movslq 0x9a900(%rip), %rax     # 0xe0c88
cmpq $0x6, %rax
je 0x463a3
movswl -0x3a(%rbp), %edi
callq 0x30960
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x46ad9
callq 0x385d0
leaq 0x3a1a91(%rip), %rdi    # 0x3e7e40
movl $0x80, %esi
xorl %edx, %edx
callq 0x6ed50
leaq 0x3a1c7e(%rip), %rdi    # 0x3e8040
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x6ed50
leaq 0x3a246b(%rip), %rdi    # 0x3e8840
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x6ed50
movswl -0x3a(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cmpl $0x4, %eax
je 0x463fd
jmp 0x46ac9
movswl -0x3a(%rbp), %edi
movq -0x28(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cmpl $0x4, %eax
je 0x46419
jmp 0x46ac9
movswl -0x3a(%rbp), %edi
movq -0x30(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cmpl $0x4, %eax
je 0x46435
jmp 0x46ac9
movswl -0x3a(%rbp), %edi
movq -0x38(%rbp), %rsi
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x46451
jmp 0x46ac9
movswl -0x3a(%rbp), %edi
movq 0x10(%rbp), %rsi
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x4646d
jmp 0x46ac9
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movw (%rax), %cx
movq -0x38(%rbp), %rax
movw %cx, (%rax)
movq 0x10(%rbp), %rax
movw (%rax), %cx
movq 0x10(%rbp), %rax
movw %cx, (%rax)
cmpl $0x4, 0x9a7d4(%rip)     # 0xe0c88
jne 0x46512
movswl -0x3a(%rbp), %edi
leaq 0x3c65ff(%rip), %rsi    # 0x40cac0
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x464d5
jmp 0x46ac9
movswl -0x3a(%rbp), %edi
leaq 0x40b4e8(%rip), %rsi    # 0x4519c8
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x464f4
jmp 0x46ac9
movswl -0x3a(%rbp), %edi
leaq -0x3e(%rbp), %rsi
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x46510
jmp 0x46ac9
jmp 0x46512
cmpl $0x4, 0x9a76f(%rip)     # 0xe0c88
jle 0x4653a
movswl -0x3a(%rbp), %edi
leaq 0x3c659a(%rip), %rsi    # 0x40cac0
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x4653a
jmp 0x46ac9
movw 0x3c657f(%rip), %ax     # 0x40cac0
movw %ax, 0x3c6578(%rip)     # 0x40cac0
movswl 0x3c6571(%rip), %eax    # 0x40cac0
cmpl $0x1000, %eax           # imm = 0x1000
jle 0x4656b
movswl -0x3a(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x46ad9
movw $0x0, -0x3c(%rbp)
movswl -0x3c(%rbp), %eax
movswl 0x3c6544(%rip), %ecx    # 0x40cac0
cmpl %ecx, %eax
jge 0x466b0
movl 0x9a6fe(%rip), %eax     # 0xe0c88
movl %eax, -0x194(%rbp)
subl $0x4, %eax
je 0x465b8
jmp 0x46597
movl -0x194(%rbp), %eax
subl $0x5, %eax
je 0x46616
jmp 0x465a4
movl -0x194(%rbp), %eax
subl $0x6, %eax
je 0x46664
jmp 0x4669d
movswl -0x3a(%rbp), %edi
leaq -0x60(%rbp), %rsi
callq 0x46af0
cmpl $0x0, %eax
je 0x465cf
jmp 0x46ac9
leaq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x46e20
leaq -0xd0(%rbp), %rdi
leaq -0x144(%rbp), %rsi
callq 0x46f70
movswq -0x3c(%rbp), %rax
leaq 0x239fc2(%rip), %rsi    # 0x2805c0
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq -0x144(%rbp), %rdi
callq 0x470d0
jmp 0x4669d
movswl -0x3a(%rbp), %edi
leaq -0xd0(%rbp), %rsi
callq 0x47350
cmpl $0x0, %eax
je 0x46630
jmp 0x46ac9
leaq -0xd0(%rbp), %rdi
leaq -0x144(%rbp), %rsi
callq 0x46f70
movswq -0x3c(%rbp), %rax
leaq 0x239f71(%rip), %rsi    # 0x2805c0
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq -0x144(%rbp), %rdi
callq 0x470d0
jmp 0x4669d
movswl -0x3a(%rbp), %edi
leaq -0x144(%rbp), %rsi
callq 0x47760
cmpl $0x0, %eax
je 0x4667e
jmp 0x46ac9
movswq -0x3c(%rbp), %rax
leaq 0x239f36(%rip), %rsi    # 0x2805c0
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq -0x144(%rbp), %rdi
callq 0x470d0
jmp 0x4669f
movw -0x3c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x3c(%rbp)
jmp 0x46571
cmpl $0x4, 0x9a5d1(%rip)     # 0xe0c88
jle 0x466d8
movswl -0x3a(%rbp), %edi
leaq 0x40b304(%rip), %rsi    # 0x4519c8
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x466d8
jmp 0x46ac9
movw 0x40b2e9(%rip), %ax     # 0x4519c8
movw %ax, 0x40b2e2(%rip)     # 0x4519c8
movswl 0x40b2db(%rip), %eax    # 0x4519c8
cmpl $0x4000, %eax           # imm = 0x4000
jle 0x46709
movswl -0x3a(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x46ad9
movw $0x0, -0x3c(%rbp)
movswl -0x3c(%rbp), %eax
movswl 0x40b2ae(%rip), %ecx    # 0x4519c8
cmpl %ecx, %eax
jge 0x46856
movl 0x9a560(%rip), %eax     # 0xe0c88
movl %eax, -0x198(%rbp)
subl $0x4, %eax
je 0x46756
jmp 0x46735
movl -0x198(%rbp), %eax
subl $0x5, %eax
je 0x467b8
jmp 0x46742
movl -0x198(%rbp), %eax
subl $0x6, %eax
je 0x4680a
jmp 0x46843
movswl -0x3a(%rbp), %edi
leaq -0x80(%rbp), %rsi
callq 0x47b70
cmpl $0x0, %eax
je 0x4676d
jmp 0x46ac9
leaq -0x80(%rbp), %rdi
leaq -0xf4(%rbp), %rsi
callq 0x47e90
movswl -0x3c(%rbp), %edx
leaq -0xf4(%rbp), %rdi
leaq -0x164(%rbp), %rsi
callq 0x47fc0
movswq -0x3c(%rbp), %rax
leaq 0x1aee10(%rip), %rsi    # 0x1f55b0
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x164(%rbp), %rdi
callq 0x480f0
jmp 0x46843
movswl -0x3a(%rbp), %edi
leaq -0xf4(%rbp), %rsi
callq 0x48200
cmpl $0x0, %eax
je 0x467d2
jmp 0x46ac9
movswl -0x3c(%rbp), %edx
leaq -0xf4(%rbp), %rdi
leaq -0x164(%rbp), %rsi
callq 0x47fc0
movswq -0x3c(%rbp), %rax
leaq 0x1aedbb(%rip), %rsi    # 0x1f55b0
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x164(%rbp), %rdi
callq 0x480f0
jmp 0x46843
movswl -0x3a(%rbp), %edi
leaq -0x164(%rbp), %rsi
callq 0x485a0
cmpl $0x0, %eax
je 0x46824
jmp 0x46ac9
movswq -0x3c(%rbp), %rax
leaq 0x1aed80(%rip), %rsi    # 0x1f55b0
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x164(%rbp), %rdi
callq 0x480f0
jmp 0x46845
movw -0x3c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x3c(%rbp)
jmp 0x4670f
cmpl $0x4, 0x9a42b(%rip)     # 0xe0c88
jle 0x4687b
movswl -0x3a(%rbp), %edi
leaq -0x3e(%rbp), %rsi
movl $0x2, %edx
callq 0x302b0
cmpl $0x2, %eax
je 0x4687b
jmp 0x46ac9
movw -0x3e(%rbp), %ax
movw %ax, -0x3e(%rbp)
movswl -0x3e(%rbp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jle 0x468a3
movswl -0x3a(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x46ad9
movw $0x0, -0x3c(%rbp)
movswl -0x3c(%rbp), %eax
movswl -0x3e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x469eb
movl 0x9a3c9(%rip), %eax     # 0xe0c88
movl %eax, -0x19c(%rbp)
subl $0x4, %eax
je 0x468ed
jmp 0x468cc
movl -0x19c(%rbp), %eax
subl $0x5, %eax
je 0x46951
jmp 0x468d9
movl -0x19c(%rbp), %eax
subl $0x6, %eax
je 0x4699f
jmp 0x469d8
movswl -0x3a(%rbp), %edi
leaq -0xa8(%rbp), %rsi
callq 0x488f0
cmpl $0x0, %eax
je 0x46907
jmp 0x46ac9
leaq -0xa8(%rbp), %rdi
leaq -0x11c(%rbp), %rsi
callq 0x48c60
leaq -0x11c(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x48d90
movswq -0x3c(%rbp), %rax
leaq 0x272ed7(%rip), %rsi    # 0x2b9810
imulq $0x2c, %rax, %rax
addq %rax, %rsi
leaq -0x190(%rbp), %rdi
callq 0x48f40
jmp 0x469d8
movswl -0x3a(%rbp), %edi
leaq -0x11c(%rbp), %rsi
callq 0x490a0
cmpl $0x0, %eax
je 0x4696b
jmp 0x46ac9
leaq -0x11c(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x48d90
movswq -0x3c(%rbp), %rax
leaq 0x272e86(%rip), %rsi    # 0x2b9810
imulq $0x2c, %rax, %rax
addq %rax, %rsi
leaq -0x190(%rbp), %rdi
callq 0x48f40
jmp 0x469d8
movswl -0x3a(%rbp), %edi
leaq -0x190(%rbp), %rsi
callq 0x49440
cmpl $0x0, %eax
je 0x469b9
jmp 0x46ac9
movswq -0x3c(%rbp), %rax
leaq 0x272e4b(%rip), %rsi    # 0x2b9810
imulq $0x2c, %rax, %rax
addq %rax, %rsi
leaq -0x190(%rbp), %rdi
callq 0x48f40
jmp 0x469da
movw -0x3c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x3c(%rbp)
jmp 0x468a9
movw $0x0, -0x3c(%rbp)
movswl -0x3c(%rbp), %eax
movswl -0x3e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x46a85
movswq -0x3c(%rbp), %rcx
leaq 0x272e03(%rip), %rax    # 0x2b9810
imulq $0x2c, %rcx, %rcx
addq %rcx, %rax
movswl 0xc(%rax), %eax
andl $0x30, %eax
cmpl $0x30, %eax
jne 0x46a3e
movswq -0x3c(%rbp), %rcx
leaq 0x272de4(%rip), %rax    # 0x2b9810
imulq $0x2c, %rcx, %rcx
addq %rcx, %rax
movswl 0xc(%rax), %ecx
andl $-0x31, %ecx
movw %cx, 0xc(%rax)
movswq -0x3c(%rbp), %rcx
leaq 0x272dc6(%rip), %rax    # 0x2b9810
imulq $0x2c, %rcx, %rcx
addq %rcx, %rax
movw 0x18(%rax), %cx
movswq -0x3c(%rbp), %rdx
leaq 0x272daf(%rip), %rax    # 0x2b9810
imulq $0x2c, %rdx, %rdx
addq %rdx, %rax
movswl %cx, %edi
movswl 0x1a(%rax), %esi
callq 0x46280
movw -0x3c(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x3c(%rbp)
jmp 0x469f1
movq -0x20(%rbp), %rax
movl (%rax), %edi
movq -0x28(%rbp), %rax
movl (%rax), %esi
movq 0x10(%rbp), %rdx
callq 0x392a0
movswl -0x3a(%rbp), %edi
callq 0x30960
leaq 0x322d66(%rip), %rdi    # 0x369810
xorl %esi, %esi
movl $0x30c00, %edx          # imm = 0x30C00
callq 0x62d0
movl $0x0, 0x40af0c(%rip)    # 0x4519cc
movl $0x0, -0x4(%rbp)
jmp 0x46ad9
movswl -0x3a(%rbp), %edi
callq 0x30960
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw %cs:(%rax,%rax)