// hello_m68k_CRTSTDIO.c
// Generated by decompiling hello_m68k.exe
// using Reko decompiler version 0.11.6.0.

#include "hello_m68k.h"

// 000015E8: void fn000015E8(Register word32 d3, Register word32 a2, Register ptr32 a5, Register word32 a6, Stack word32 dwArg04)
void fn000015E8(word32 d3, word32 a2, ptr32 a5, word32 a6, word32 dwArg04)
{
	(*((word32) a5 + 0x0082))();
	word32 d0_n;
	if (d0_n == 0x00)
		return;
	struct Eq_n * a2_n;
	struct Eq_n * a5_n;
	ui32 d3_n;
	if (a2_n == a5_n->aFFFFF578 + 0x0A)
		d3_n = 0x00;
	else
	{
		if (a2_n != a5_n->aFFFFF578 + 18)
			return;
		d3_n = 0x01;
	}
	++a5_n->dwFFFFFAA8;
	if ((a2_n->w000C & 0x010C) != 0x00)
		return;
	if (a5_n->aFFFFF578[d3_n] == 0x00)
	{
		ptr32 * a7_n;
		*a7_n = (<unknown>*) 0x0200;
		(*((char *) &a5_n->dwFFFFFAA8 + 0x05CA))();
		word32 d0_n;
		a5_n->aFFFFF578[d3_n] = d0_n;
		if (d0_n == 0x00)
			return;
	}
	word32 d0_n = a5_n->aFFFFF578[d3_n];
	a2_n->dw0008 = d0_n;
	a2_n->dw0000 = d0_n;
	a2_n->dw0018 = 0x0200;
	a2_n->dw0004 = 0x0200;
	a2_n->w000E |= 0x1102;
}

// 00001680: void fn00001680(Register (ptr32 Eq_n) a5, Stack word32 dwArg04, Stack (ptr32 Eq_n) dwArg08)
void fn00001680(struct Eq_n * a5, word32 dwArg04, struct Eq_n * dwArg08)
{
	if (dwArg04 == 0x00)
	{
		if (!__btst<byte>(dwArg08->b000E, 0x04))
		{
			word32 d3_n;
			word32 d4_n;
			word32 a2_n;
			word32 a5_n;
			word32 a6_n;
			fn00001D80(a5, dwArg08, out d3_n, out d4_n, out a2_n, out a5_n, out a6_n);
		}
	}
	else
	{
		if (__btst<byte>(dwArg08->b000E, 0x04))
			return;
		word32 d3_n;
		word32 d4_n;
		struct Eq_n * a2_n;
		word32 a5_n;
		word32 a6_n;
		fn00001D80(a5, dwArg08, out d3_n, out d4_n, out a2_n, out a5_n, out a6_n);
		a2_n->w000E &= ~0x1100;
		a2_n->dw0018 = 0x00;
		a2_n->dw0000 = 0x00;
		a2_n->dw0008 = 0x00;
	}
}

// 000016D0: void fn000016D0(Register (ptr32 Eq_n) a5, Stack (ptr32 byte) dwArg08)
void fn000016D0(struct Eq_n * a5, byte * dwArg08)
{
	word32 dwLoc18;
	int32 dwLoc14;
	Eq_n dwLoc10;
	word32 d6;
	ptr32 fp;
	byte v18_n = *dwArg08;
	struct Eq_n * a6_n = fp - 0x04;
	ptr32 a7_n = fp - 0x0244;
	ptr32 a3_n = (char *) a5 - 2040;
	Eq_n (* a2_n)[] = (Eq_n (*)[]) ((char *) a5 - 0x0818);
	int32 d6_n = SEQ(SLICE(d6, word24, 8), v18_n);
	if (v18_n != 0x00)
	{
		Eq_n d3_n = dwLoc10;
		int32 d4_n = dwLoc14;
		word32 d5_n = dwLoc18;
		while (a6_n->dwFFFFFDE0 >= 0x00)
		{
			int32 d0_n;
			if ((byte) d6_n >= 0x20 && (byte) d6_n <= 0x78)
				d0_n = (int32) ((&a2_n[0].u0)[(int32) (byte) d6_n] & 0x0F);
			else
				d0_n = 0x00;
			Eq_n d0_n;
			d0_n.u0 = (int32) ((a3_n + (a6_n->tFFFFFFF8).u0)[d0_n].b0000 >> 0x04);
			a6_n->tFFFFFFF8.u0 = (int32) d0_n;
			if (d0_n <= 0x07)
			{
				switch (d0_n)
				{
				case 0x00:
					struct Eq_n * a7_n = a7_n - 4;
					a7_n->ptr0000 = &a6_n->dwFFFFFDE0;
					a7_n->ptrFFFFFFFC = a6_n->ptr0008;
					d6_n = (int32) (int8) d6_n;
					a7_n->dwFFFFFFF8 = d6_n;
					struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
					d3_n = fn00001C40(a5, a7_n->b0008, a7_n->ptrFFFFFFFC, out d4_n, out d5_n, out a2_n, out a3_n, out a5, out a6_n);
					a7_n = &a7_n->t000C.u0;
					break;
				case 0x01:
					a6_n->dwFFFFFFF4 = 0x00;
					a6_n->dwFFFFFFF0 = 0x00;
					a6_n->dwFFFFFFEC = 0x00;
					d6_n = 0x00;
					d5_n = 0x00;
					d3_n.u0 = 0x00;
					d4_n = ~0x00;
					break;
				case 0x02:
					Eq_n d6_n;
					d6_n.u0 = (int32) (int8) d6_n;
					d6_n = d6_n - 0x20;
					if (d6_n <= 0x30 && d6_n >= 0x20)
					{
						word24 v50_n = SLICE(d6_n - 0x20, word24, 8);
						int16 v51_n = g_a17B4[(int32) (int16) SEQ(v50_n, g_a17C0[(int32) ((int16) d6_n - 32)])];
						(*((char *) g_a17B4 + (int32) v51_n))();
						return;
					}
					break;
				case 0x03:
					if ((byte) d6_n == 0x2A)
					{
						word32 *** a7_n = a7_n - 4;
						*a7_n = (word32 ***) ((char *) &a6_n->ptr000C + 4);
						int32 d0_n = fn00001D0C(*a7_n);
						a6_n->dwFFFFFFEC = d0_n;
						a7_n = (char *) a7_n + 4;
						if (d0_n < 0x00)
						{
							__bset<word16>(d3_n, 0x02, out d3_n);
							a6_n->dwFFFFFFEC = -a6_n->dwFFFFFFEC;
						}
					}
					else
					{
						int32 d6_n = (int32) (int8) d6_n + a6_n->dwFFFFFFEC * 0x0A;
						a6_n->dwFFFFFFEC = d6_n - 0x30;
						d6_n = d6_n - 0x30;
					}
					break;
				case 0x04:
					d4_n = 0x00;
					break;
				case 0x05:
					if ((byte) d6_n == 0x2A)
					{
						word32 *** a7_n = a7_n - 4;
						*a7_n = (word32 ***) ((char *) &a6_n->ptr000C + 4);
						int32 d0_n = fn00001D0C(*a7_n);
						a7_n = (char *) a7_n + 4;
						d4_n = d0_n;
						if (d0_n < 0x00)
							d4_n = ~0x00;
					}
					else
					{
						int32 d6_n = (int32) (int8) d6_n + d4_n * 0x0A;
						d6_n = d6_n - 0x30;
						d4_n = d6_n - 0x30;
					}
					break;
				case 0x06:
					d6_n = (int32) (int8) d6_n;
					if (d6_n != 0x4C)
					{
						if (d6_n == 0x68)
							__bset<word16>(d3_n, 0x05, out d3_n);
					}
					else
						__bset<word16>(d3_n, 0x0A, out d3_n);
					break;
				}
			}
			byte v44_n = *a6_n->ptr000C;
			++a6_n->ptr000C;
			d6_n = SEQ(SLICE(d6_n, word24, 8), v44_n);
			if (v44_n == 0x00)
				return;
		}
	}
}

int16 g_a17B4[] = // 000017B4
	{
	};
byte g_a17C0[] = // 000017C0
	{
	};
// 00001C40: Register (ptr32 Eq_n) fn00001C40(Register (ptr32 Eq_n) a5, Stack byte bArg04, Stack (ptr32 Eq_n) dwArg08, Register out (ptr32 Eq_n) d4Out, Register out (ptr32 Eq_n) d5Out, Register out (ptr32 Eq_n) a2Out, Register out (ptr32 Eq_n) a3Out, Register out (ptr32 Eq_n) a5Out, Register out (ptr32 Eq_n) a6Out)
// Called from:
//      fn000016D0
//      fn00001C84
//      fn00001CC4
struct Eq_n * fn00001C40(struct Eq_n * a5, byte bArg04, struct Eq_n * dwArg08, struct Eq_n & d4Out, struct Eq_n & d5Out, struct Eq_n & a2Out, struct Eq_n & a3Out, struct Eq_n & a5Out, struct Eq_n & a6Out)
{
	ptr32 fp;
	word32 dwArg04;
	uint8 bArg07_n = (byte) dwArg04;
	int32 v6_n = dwArg08->dw0004 - 0x01;
	dwArg08->dw0004 = v6_n;
	struct Eq_n * a6_n = fp - 0x04;
	int32 d0_n;
	if (v6_n >= 0x00)
	{
		*dwArg08->ptr0000 = bArg07_n;
		uint8 * a0_n = dwArg08->ptr0000;
		d0_n = (int32) *a0_n;
		dwArg08->ptr0000 = a0_n + 1;
	}
	else
	{
		word32 d3_n;
		word32 d4_n;
		word32 d5_n;
		word32 a2_n;
		word32 a3_n;
		word32 a5_n;
		d0_n = fn00001E94(a5, dwArg08, out d3_n, out d4_n, out d5_n, out a2_n, out a3_n, out a5_n, out a6_n);
	}
	int32 * a0_n = a6_n->ptr0010;
	if (d0_n != ~0x00)
	{
		++*a0_n;
		struct Eq_n * a6_n = a6_n->ptr0000;
		d4Out = (struct Eq_n *) <invalid>;
		d5Out = (struct Eq_n *) <invalid>;
		a2Out = (struct Eq_n *) <invalid>;
		a3Out = (struct Eq_n *) <invalid>;
		a5Out = (struct Eq_n *) <invalid>;
		a6Out = a6_n;
		return (struct Eq_n *) <invalid>;
	}
	else
	{
		*a0_n = d0_n;
		struct Eq_n * a6_n = a6_n->ptr0000;
		d4Out = (struct Eq_n *) <invalid>;
		d5Out = (struct Eq_n *) <invalid>;
		a2Out = (struct Eq_n *) <invalid>;
		a3Out = (struct Eq_n *) <invalid>;
		a5Out = (struct Eq_n *) <invalid>;
		a6Out = a6_n;
		return (struct Eq_n *) <invalid>;
	}
}

// 00001C84: void fn00001C84(Register (ptr32 Eq_n) a5, Stack Eq_n dwArg04, Stack int32 dwArg08, Stack (ptr32 Eq_n) dwArg0C, Stack word32 dwArg10)
void fn00001C84(struct Eq_n * a5, Eq_n dwArg04, int32 dwArg08, struct Eq_n * dwArg0C, word32 dwArg10)
{
	ptr32 fp;
	ptr32 a7_n = fp - 0x14;
	if (dwArg08 > 0x00)
	{
		Eq_n d3_n = dwArg04;
		struct Eq_n * d4_n = dwArg0C;
		int32 d5_n;
		do
		{
			struct Eq_n * a7_n = a7_n - 4;
			a7_n->dw0000 = dwArg10;
			a7_n->ptrFFFFFFFC = d4_n;
			a7_n->tFFFFFFF8.u2 = (struct Eq_n *) d3_n;
			struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
			word32 a2_n;
			word32 a3_n;
			word32 a6_n;
			d3_n = fn00001C40(a5, a7_n->b0008, a7_n->ptrFFFFFFFC, out d4_n, out d5_n, out a2_n, out a3_n, out a5, out a6_n);
			a7_n = &a7_n->t000C.u0;
		} while (d5_n > 0x00);
	}
}

// 00001CC4: void fn00001CC4(Register (ptr32 Eq_n) a5, Stack Eq_n dwArg04, Stack int32 dwArg08, Stack (ptr32 Eq_n) dwArg0C, Stack word32 dwArg10)
void fn00001CC4(struct Eq_n * a5, Eq_n dwArg04, int32 dwArg08, struct Eq_n * dwArg0C, word32 dwArg10)
{
	ptr32 fp;
	ptr32 a7_n = fp - 0x14;
	if (dwArg08 > 0x00)
	{
		Eq_n d3_n = dwArg04;
		struct Eq_n * d4_n = dwArg0C;
		int32 d5_n;
		do
		{
			struct Eq_n * a7_n = a7_n - 4;
			a7_n->dw0000 = dwArg10;
			a7_n->ptrFFFFFFFC = d4_n;
			a7_n->dwFFFFFFF8 = (int32) d3_n.u2->t0000.u0;
			struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
			word32 a2_n;
			word32 a3_n;
			word32 a6_n;
			d3_n = fn00001C40(a5, a7_n->b0008, a7_n->ptrFFFFFFFC, out d4_n, out d5_n, out a2_n, out a3_n, out a5, out a6_n);
			a7_n = &a7_n->t000C.u0;
		} while (d5_n > 0x00);
	}
}

// 00001D0C: Register word32 fn00001D0C(Stack (ptr32 (ptr32 word32)) dwArg04)
// Called from:
//      fn000016D0
word32 fn00001D0C(word32 ** dwArg04)
{
	word32 * a1_n = *dwArg04;
	*dwArg04 = a1_n + 1;
	return *a1_n;
}

// 00001D24: Register int32 fn00001D24(Register (ptr32 Eq_n) a5, Stack (ptr32 Eq_n) dwArg04, Register out word32 d3Out, Register out word32 d4Out, Register out (ptr32 Eq_n) d5Out, Register out (ptr32 Eq_n) d6Out, Register out (ptr32 Eq_n) d7Out, Register out Eq_n a2Out, Register out (ptr32 Eq_n) a5Out, Register out (ptr32 word32) a6Out)
// Called from:
//      fn00001E04
int32 fn00001D24(struct Eq_n * a5, struct Eq_n * dwArg04, word32 & d3Out, word32 & d4Out, struct Eq_n & d5Out, struct Eq_n & d6Out, struct Eq_n & d7Out, union Eq_n & a2Out, struct Eq_n & a5Out, word32 & a6Out)
{
	word32 ** a6_n;
	struct Eq_n * a5_n;
	word32 d4_n;
	word32 d3_n;
	word32 ** a6_n;
	if (dwArg04 != null)
	{
		struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
		word32 d3_n;
		word32 d4_n;
		struct Eq_n * a2_n;
		struct Eq_n * a5_n;
		word32 ** a6_n;
		if (fn00001D80(a5, dwArg04, out d3_n, out d4_n, out a2_n, out a5_n, out a6_n) == 0x00)
		{
			if (__btst<byte>(a2_n->b000E, 0x06))
			{
				Eq_n v19_n;
				v19_n.u1 = a7_n->t0004.u1;
				word32 * a6_n = *a6_n;
				d3Out = d3_n;
				d4Out = d4_n;
				d5Out = (struct Eq_n *) <invalid>;
				d6Out = (struct Eq_n *) <invalid>;
				d7Out = (struct Eq_n *) <invalid>;
				a2Out = v19_n;
				a5Out = a5_n;
				a6Out = a6_n;
				return 0x00;
			}
			else
			{
				a7_n->a0000[0].u1 = a2_n->t0010.u1;
				(*((char *) &a5_n->ptrFFFFF800 + 0x088A))();
				Eq_n v18_n;
				struct Eq_n * a7_n;
				v18_n.u1 = a7_n->t0004.u1;
				word32 * a6_n = *a6_n;
				word32 d3_n;
				d3Out = d3_n;
				word32 d4_n;
				d4Out = d4_n;
				d5Out = (struct Eq_n *) <invalid>;
				d6Out = (struct Eq_n *) <invalid>;
				d7Out = (struct Eq_n *) <invalid>;
				a2Out = v18_n;
				struct Eq_n * a5_n;
				a5Out = a5_n;
				a6Out = a6_n;
				word32 d0_n;
				return (int32) (d0_n != 0x00 ? ~0x00 : 0x00);
			}
		}
		else
		{
			Eq_n v13_n;
			v13_n.u1 = a7_n->t0004.u1;
			word32 * a6_n = *a6_n;
			d3Out = d3_n;
			d4Out = d4_n;
			d5Out = (struct Eq_n *) <invalid>;
			d6Out = (struct Eq_n *) <invalid>;
			d7Out = (struct Eq_n *) <invalid>;
			a2Out = v13_n;
			a5Out = a5_n;
			a6Out = a6_n;
			return ~0x00;
		}
	}
	else
	{
		int32 d0_n = fn00001E04(a5, 0x00, out d3_n, out d4_n, out a5_n, out a6_n);
		word32 * a6_n = *a6_n;
		d3Out = d3_n;
		d4Out = d4_n;
		d5Out = (struct Eq_n *) <invalid>;
		d6Out = (struct Eq_n *) <invalid>;
		d7Out = (struct Eq_n *) <invalid>;
		Eq_n a2;
		a2Out = a2;
		a5Out = a5_n;
		a6Out = a6_n;
		return d0_n;
	}
}

// 00001D80: Register word32 fn00001D80(Register (ptr32 Eq_n) a5, Stack (ptr32 Eq_n) dwArg04, Register out word32 d3Out, Register out word32 d4Out, Register out word32 a2Out, Register out (ptr32 Eq_n) a5Out, Register out word32 a6Out)
// Called from:
//      fn00001680
//      fn00001D24
//      fn00002068
word32 fn00001D80(struct Eq_n * a5, struct Eq_n * dwArg04, word32 & d3Out, word32 & d4Out, word32 & a2Out, struct Eq_n & a5Out, word32 & a6Out)
{
	ptr32 fp;
	Eq_n d1_n;
	d1_n.u2 = dwArg04->t000C.u2;
	word32 * a6_n = fp - 0x04;
	word32 * a7_n = fp - 0x10;
	word32 d3_n = 0x00;
	struct Eq_n * a2_n = dwArg04;
	if ((d1_n & 0x03) == 0x02 && ((word16) d1_n & 0x0108) != 0x00)
	{
		Eq_n d0_n;
		d0_n.u1 = dwArg04->t0008.u1;
		int32 d4_n = dwArg04->a0000[0].u1 - d0_n;
		if (d4_n > 0x00)
		{
			a5[0x0092]();
			word32 a7_n;
			a7_n = a7_n + 0x0C;
			word32 d0_n;
			word32 d4_n;
			if (d0_n == d4_n)
			{
				Eq_n d0_n;
				d0_n.u2 = a2_n->t000C.u2;
				if (!__btst<byte>((byte) d0_n, 0x07))
				{
					Eq_n d0_n;
					__bclr<word32>(d0_n, 0x01, out d0_n);
					a2_n->t000C.u2 = (struct Eq_n *) d0_n;
				}
			}
			else
			{
				__bset<word16>(a2_n->t000F.u1, 0x05, out a2_n->t000F.u1);
				d3_n = ~0x00;
			}
		}
	}
	a2_n->a0000[0].u1 = a2_n->t0008.u1;
	a2_n->t0004.u1 = (union Eq_n *) 0x00;
	struct Eq_n * a7_n = (struct Eq_n *) (a7_n + 1);
	word32 d4_n = a7_n->dw0000;
	word32 a2_n = a7_n->dw0004;
	word32 a6_n = *a6_n;
	d3Out = *a7_n;
	d4Out = d4_n;
	a2Out = a2_n;
	a5Out = a5;
	a6Out = a6_n;
	return d3_n;
}

// 00001DF4: void fn00001DF4(Register (ptr32 Eq_n) a5)
void fn00001DF4(struct Eq_n * a5)
{
	word32 d3_n;
	word32 d4_n;
	word32 a5_n;
	word32 a6_n;
	fn00001E04(a5, 0x01, out d3_n, out d4_n, out a5_n, out a6_n);
}

// 00001E04: Register word32 fn00001E04(Register (ptr32 Eq_n) a5, Stack word32 dwArg04, Register out word32 d3Out, Register out word32 d4Out, Register out (ptr32 Eq_n) a5Out, Register out word32 a6Out)
// Called from:
//      fn00001D24
//      fn00001DF4
word32 fn00001E04(struct Eq_n * a5, word32 dwArg04, word32 & d3Out, word32 & d4Out, struct Eq_n & a5Out, word32 & a6Out)
{
	word32 d7_n;
	ptr32 fp;
	word32 * a6_n = fp - 0x04;
	struct Eq_n * a7_n = fp - 0x1C;
	word32 d6_n = 0x01;
	struct Eq_n * a2_n = (struct Eq_n *) ((char *) a5 - 2688);
	word32 d4_n = 0x00;
	word32 d5_n = 0x00;
	word32 d3_n;
	if ((char *) a5 - 2688 <= a5->dwFFFFF800)
	{
		d3_n = dwArg04;
		do
		{
			if (d3_n == d6_n && (a2_n->w000C & 131) != 0x00)
			{
				a7_n->ptrFFFFFFFC = a2_n;
				// Failed to bind call argument.
				// Please report this issue at https://github.com/uxmal/reko
				struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
				struct Eq_n * stackArg4 = (struct Eq_n *) <invalid>;
				a7_n = (struct Eq_n *) &a7_n->t0004.u0;
				word32 d7_n;
				if (fn00001D24(a5, stackArg4, out d3_n, out d4_n, out d5_n, out d6_n, out d7_n, out a2_n, out a5, out a6_n) != d7_n)
					d4_n += d6_n;
			}
			else if (d3_n == 0x00 && !__btst<word32>(a2_n->dw000F, d6_n))
			{
				a7_n->ptrFFFFFFFC = a2_n;
				// Failed to bind call argument.
				// Please report this issue at https://github.com/uxmal/reko
				struct Eq_n * stackArg4 = (struct Eq_n *) <invalid>;
				struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
				word32 d0_n = fn00001D24(a5, stackArg4, out d3_n, out d4_n, out d5_n, out d6_n, out d7_n, out a2_n, out a5, out a6_n);
				a7_n = (struct Eq_n *) &a7_n->t0004.u0;
				if (d0_n == d7_n)
					d5_n = d0_n;
			}
			++a2_n;
		} while (a2_n <= a5->dwFFFFF800);
	}
	else
		d3_n = dwArg04;
	if (d3_n != 0x01)
		d4_n = d5_n;
	word32 d4_n = a7_n->dw0004;
	word32 a6_n = *a6_n;
	d3Out = a7_n->dw0000;
	d4Out = d4_n;
	a5Out = a5;
	a6Out = a6_n;
	return d4_n;
}

// 00001E94: Register ui32 fn00001E94(Register (ptr32 Eq_n) a5, Stack (ptr32 Eq_n) dwArg08, Register out word32 d3Out, Register out word32 d4Out, Register out word32 d5Out, Register out word32 a2Out, Register out word32 a3Out, Register out (ptr32 Eq_n) a5Out, Register out ptr32 a6Out)
// Called from:
//      fn00001C40
ui32 fn00001E94(struct Eq_n * a5, struct Eq_n * dwArg08, word32 & d3Out, word32 & d4Out, word32 & d5Out, word32 & a2Out, word32 & a3Out, struct Eq_n & a5Out, ptr32 & a6Out)
{
	struct Eq_n * a3_n;
	ptr32 fp;
	Eq_n d0_n;
	d0_n.u2 = dwArg08->t000C.u2;
	struct Eq_n * a6_n = fp - 0x04;
	word32 * a7_n = fp - 0x1C;
	struct Eq_n * a3_n = dwArg08;
	int32 d3_n = dwArg08->dw0010;
	struct Eq_n * a2_n = (struct Eq_n *) &dwArg08->t000C.u0;
	if (((word16) d0_n & 0x82) != 0x00 && !__btst<byte>((byte) d0_n, 0x06))
	{
		if (__btst<byte>((byte) d0_n, 0x00))
		{
l00001EDA:
			Eq_n d0_n;
			__bset<word16>(dwArg08->t000C.u2, 0x01, out d0_n);
			dwArg08->t000C.u2 = (struct Eq_n *) d0_n;
			Eq_n d0_n;
			__bclr<word32>(d0_n, 0x04, out d0_n);
			dwArg08->t000C.u2 = (struct Eq_n *) d0_n;
			dwArg08->dw0004 = 0x00;
			int32 d4_n = 0x00;
			if ((dwArg08->t000C.u0 & 0x010C) == 0x00)
			{
				if (dwArg08 == (char *) a5 - 2656 || dwArg08 == (char *) a5 - 2624)
				{
					(*((char *) &a5->dwFFFFFAA8 + 0x05DA))();
					word32 a7_n;
					a7_n = a7_n + 0x04;
					word32 d0_n;
					if (d0_n != 0x00)
						goto l00001F1C;
				}
				struct Eq_n ** a7_n = a7_n - 4;
				*a7_n = (struct Eq_n **) a3_n;
				struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
				a2_n = fn00002014(a2_n, a5, a6_n, *a7_n, out a5, out a6_n);
				a7_n = (word32 *) &a7_n->t0004.u0;
			}
l00001F1C:
			int32 d5_n;
			if ((a2_n->dw0000 & 0x0108) != 0x00)
			{
				uint8 * d0_n = a3_n->ptr0008;
				d5_n = a3_n->ptr0000 - d0_n;
				a3_n->ptr0000 = d0_n + 1;
				a3_n->dw0004 = a3_n->dw0018 - 0x01;
				if (d5_n > 0x00)
				{
					struct Eq_n * a7_n = a7_n - 4;
					a7_n->dw0000 = d5_n;
					a7_n->ptrFFFFFFFC = a3_n->ptr0008;
					a7_n->dwFFFFFFF8 = d3_n;
					(*((char *) &a5->dwFFFFFAA8 + 1514))();
					uint8 * a0_n = a3_n->ptr0008;
					*a0_n = a6_n->b000B;
					word32 a7_n;
					a7_n = a7_n + 0x0C;
					int32 d0_n;
					d4_n = d0_n;
				}
				else
				{
					if (!__btst<byte>(((char *) a5 - 0x06A8)[d3_n], 0x05))
					{
						struct Eq_n * a7_n = a7_n - 4;
						a7_n->dw0000 = 0x02;
						a7_n->dwFFFFFFFC = 0x00;
						a7_n->dwFFFFFFF8 = d3_n;
						(*((char *) &a5->dwFFFFFAA8 + 1522))();
						word32 a7_n;
						a7_n = a7_n + 0x0C;
					}
					*a3_n->ptr0008 = a6_n->b000B;
				}
			}
			else
			{
				a6_n->bFFFFFFFF = a6_n->b000B;
				struct Eq_n * a7_n = a7_n - 4;
				a7_n->dw0000 = 0x01;
				a7_n->ptrFFFFFFFC = &a6_n->bFFFFFFFF;
				a7_n->dwFFFFFFF8 = d3_n;
				(*((char *) &a5->dwFFFFFAA8 + 1514))();
				word32 a7_n;
				a7_n = a7_n + 0x0C;
				int32 d0_n;
				d4_n = d0_n;
			}
			if (d4_n == d5_n)
			{
				struct Eq_n * a7_n = (struct Eq_n *) (a7_n + 1);
				ui32 d0_n = a6_n->dw0008;
				word32 d4_n = a7_n->dw0000;
				word32 d5_n = a7_n->dw0004;
				word32 a2_n = a7_n->dw0008;
				word32 a3_n = a7_n->dw000C;
				ptr32 a6_n = a6_n->ptr0000;
				d3Out = *a7_n;
				d4Out = d4_n;
				d5Out = d5_n;
				a2Out = a2_n;
				a3Out = a3_n;
				a5Out = a5;
				a6Out = a6_n;
				return d0_n & 0xFF;
			}
			else
			{
				__bset<word16>(a2_n->t0003.u1, 0x05, out a2_n->t0003.u1);
				struct Eq_n * a7_n = (struct Eq_n *) (a7_n + 1);
				word32 d4_n = a7_n->dw0000;
				word32 d5_n = a7_n->dw0004;
				word32 a2_n = a7_n->dw0008;
				word32 a3_n = a7_n->dw000C;
				ptr32 a6_n = a6_n->ptr0000;
				d3Out = *a7_n;
				d4Out = d4_n;
				d5Out = d5_n;
				a2Out = a2_n;
				a3Out = a3_n;
				a5Out = a5;
				a6Out = a6_n;
				return ~0x00;
			}
		}
		dwArg08->dw0004 = 0x00;
		d0_n.u2 = dwArg08->t000C.u2;
		if (!__btst<byte>((byte) d0_n, 0x04))
		{
			dwArg08->ptr0000 = dwArg08->ptr0008;
			__bclr<byte>(dwArg08->b000F, 0x00, out dwArg08->b000F);
			goto l00001EDA;
		}
	}
	Eq_n d0_n;
	__bset<word16>(d0_n, 0x05, out d0_n);
	dwArg08->t000C.u2 = (struct Eq_n *) d0_n;
	word32 d3;
	d3Out = d3;
	word32 d4;
	d4Out = d4;
	word32 d5;
	d5Out = d5;
	word32 a2;
	a2Out = a2;
	word32 a3;
	a3Out = a3;
	a5Out = a5;
	ptr32 a6;
	a6Out = a6;
	return ~0x00;
}

// 00001FD8: void fn00001FD8(Register (ptr32 Eq_n) a5)
void fn00001FD8(struct Eq_n * a5)
{
	ptr32 fp;
	ptr32 a7_n = fp - 0x14;
	word32 d3_n = 0x00;
	struct Eq_n * d4_n = (struct Eq_n *) ((char *) a5 - 2592);
	if ((char *) a5 - 2592 <= a5->dwFFFFF800)
	{
		up32 d4_n;
		do
		{
			struct Eq_n ** a7_n = a7_n - 4;
			*a7_n = (struct Eq_n **) d4_n;
			struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
			a7_n = &a7_n->t0004.u0;
			word32 a6_n;
			if (fn00002068(d3_n, a5, *a7_n, out d3_n, out d4_n, out a5, out a6_n) != ~0x00)
				++d3_n;
			d4_n = d4_n + 0x20;
		} while (d4_n + 0x20 <= a5->dwFFFFF800);
	}
}

// 00002014: Register (ptr32 Eq_n) fn00002014(Register (ptr32 Eq_n) a2, Register (ptr32 Eq_n) a5, Register (ptr32 Eq_n) a6, Stack (ptr32 Eq_n) dwArg04, Register out ptr32 a5Out, Register out ptr32 a6Out)
// Called from:
//      fn00001E94
struct Eq_n * fn00002014(struct Eq_n * a2, struct Eq_n * a5, struct Eq_n * a6, struct Eq_n * dwArg04, ptr32 & a5Out, ptr32 & a6Out)
{
	ptr32 * a6_n;
	struct Eq_n * a7_n;
	++a5->dwFFFFFAA8;
	(*((char *) &a5->dwFFFFFAA8 + 0x05CA))();
	struct Eq_n * a2_n;
	ptr32 d0_n;
	a2_n->ptr0008 = d0_n;
	if (d0_n != null)
	{
		__bset<word16>(a2_n->t000F.u1, 0x03, out a2_n->t000F.u1);
		a2_n->dw0018 = 0x0200;
	}
	else
	{
		__bset<word16>(a2_n->t000F.u1, 0x02, out a2_n->t000F.u1);
		a2_n->ptr0008 = (char *) &a2_n->t000F + 5;
		a2_n->dw0018 = 0x01;
	}
	a2_n->ptr0000 = a2_n->ptr0008;
	a2_n->dw0004 = 0x00;
	struct Eq_n * v17_n = a7_n->ptr0004;
	ptr32 a6_n = *a6_n;
	ptr32 a5_n;
	a5Out = a5_n;
	a6Out = a6_n;
	return v17_n;
}

// 00002068: Register word32 fn00002068(Register word32 d3, Register (ptr32 Eq_n) a5, Stack (ptr32 Eq_n) dwArg04, Register out word32 d3Out, Register out word32 d4Out, Register out (ptr32 Eq_n) a5Out, Register out word32 a6Out)
// Called from:
//      fn00001FD8
word32 fn00002068(word32 d3, struct Eq_n * a5, struct Eq_n * dwArg04, word32 & d3Out, word32 & d4Out, struct Eq_n & a5Out, word32 & a6Out)
{
	word32 a6_n;
	ptr32 a5_n;
	word32 a6_n;
	ptr32 a5_n;
	Eq_n a2_n;
	word32 d4_n;
	word32 d3_n;
	ptr32 fp;
	Eq_n d0_n;
	d0_n.u2 = dwArg04->t000C.u2;
	word32 * a6_n = fp - 0x04;
	struct Eq_n * a7_n = fp - 0x0C;
	word32 d3_n = ~0x00;
	struct Eq_n * a2_n = dwArg04;
	word32 d4;
	if (__btst<byte>((byte) d0_n, 0x06))
	{
		if (((word16) d0_n & 131) != 0x00)
		{
			word32 d0_n = fn00001D80(a5, dwArg04, out d3_n, out d4_n, out a2_n, out a5_n, out a6_n);
			struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
			a7_n->a0000[0].u1 = (union Eq_n *) a2_n;
			struct Eq_n * a2_n = fn000020F0(a5_n, a7_n->a0000[0].u1, out a5_n, out a6_n);
			struct Eq_n * a7_n = (struct Eq_n *) <invalid>;
			a7_n->a0000[0].u1 = a2_n->t0010.u1;
			(*((word32) a5_n + 0x00A2))();
			word32 * a7_n;
			a7_n = (struct Eq_n *) (a7_n + 1);
			int32 d0_n;
			if (d0_n < 0x00)
				d3_n = ~0x00;
			else
			{
				word32 d0_n = a2_n->dw001C;
				if (d0_n != 0x00)
				{
					*a7_n = d0_n;
					a5[0x00B2]();
					word32 d0_n;
					if (d0_n != 0x00)
					{
						word32 d3_n = ~0x00;
					}
					word32 * a7_n;
					struct Eq_n * a2_n;
					*a7_n = a2_n->dw001C;
					ptr32 a5_n;
					(*((word32) a5_n + 122))();
					a2_n->dw001C = 0x00;
					word32 a7_n;
					a7_n = a7_n + 0x04;
				}
			}
		}
		a2_n->t000C.u2 = (struct Eq_n *) 0x00;
		word32 a6_n = *a6_n;
		d3Out = a7_n->dw0004;
		d4Out = d4;
		a5Out = a5;
		a6Out = a6_n;
		return d3_n;
	}
	else
	{
		dwArg04->t000C.u2 = (struct Eq_n *) 0x00;
		d3Out = d3;
		d4Out = d4;
		a5Out = a5;
		word32 a6;
		a6Out = a6;
		return ~0x00;
	}
}

// 000020F0: Register word32 fn000020F0(Register ptr32 a5, Stack Eq_n dwArg04, Register out ptr32 a5Out, Register out word32 a6Out)
// Called from:
//      fn00002068
word32 fn000020F0(ptr32 a5, Eq_n dwArg04, ptr32 & a5Out, word32 & a6Out)
{
	ptr32 fp;
	word32 d0_n = (word32) *((word32) dwArg04 + 0x0C);
	word32 * a6_n = fp - 0x04;
	word32 * a7_n = fp - 0x08;
	if (((word16) d0_n & 131) != 0x00 && !__btst<byte>((byte) d0_n, 0x03))
	{
		(*((word32) a5 + 122))();
		struct Eq_n * a2_n;
		__bclr<byte>(a2_n->b000F, 0x03, out a2_n->b000F);
		a2_n->dw0000 = 0x00;
		a2_n->dw0008 = 0x00;
		a2_n->dw0004 = 0x00;
		word32 a7_n;
		a7_n = a7_n + 0x04;
	}
	word32 v17_n = *a7_n;
	word32 a6_n = *a6_n;
	a5Out = a5;
	a6Out = a6_n;
	return v17_n;
}

