// File: /workspace/github_c_makefile_star2_O3/salextpuru[P]speccy-toochain/src/spgbld/func.cxx
// Function: load_ini(char*)
void load_ini(char *name)
{
	char t[256];
	char v[256];
	char v1[256];
	char v2[256];
	int a = 0;
	int b = 0;
	int nblk = 0;
	FILE* f = fopen(name, "r");

	if (!f)
		error(INI);

	while (!feof(f)) {
		*t = 0;
		fscanf(f, "%256[^ =\n\r\t]%*[ =]%256[^\n\r]%*c", t, v);

		if (!*t) {
			fscanf(f, "%*c");
			continue;
		}

		if (t[0] == ';')
			continue;

		strlwr(t);

		// description string
		if (!strcmp(t, STR(F_DESC))) {
			strncpy(hdr.desc, v, 32);
			printf("Description:\t%s\n", v);
			continue;
		}

		// stack address
		if (!strcmp(t, STR(F_SP))) {
			hdr.sp = (u16)num(v);
			printf("SP:\t\t#%04X\n", hdr.sp);
			continue;
		}

		// resident address
		if (!strcmp(t, STR(F_RES))) {
			hdr.resid = (u16)num(v);
			printf("Resident at:\t#%04X\n", hdr.resid);
			continue;
		}

		// pager address
		if (!strcmp(t, STR(F_PAGER))) {
			hdr.pager = (u16)num(v);

			if (hdr.pager)
				printf("Pager at:\t#%04X\n", hdr.pager);

			else
				printf("Pager:\t\tNot used\n");

			continue;
		}

		// start address
		if (!strcmp(t, STR(F_START))) {
			hdr.start = (u16)num(v);
			printf("Start:\t\t#%04X\n", hdr.start);
			continue;
		}

		// page3
		if (!strcmp(t, STR(F_PAGE3))) {
			hdr.page3 = (u8)num(v);
			printf("Page #C000:\t#%02X\n", hdr.page3);
			continue;
		}

		// clock
		if (!strcmp(t, STR(F_CLOCK))) {
			hdr.clk = (u8)num(v);
			printf("Clock:\t\t");

			switch (hdr.clk) {
			case 0: {
				printf("3.5");
				break;
			}

			case 1: {
				printf("7");
				break;
			}

			case 2: {
				printf("14");
				break;
			}

			case 3: {
				printf("14+");
				break;
			}
			}

			printf(" MHz\n");
			continue;
		}

		// INT
		if (!strcmp(t, STR(F_INT))) {
			hdr.ei = num(v);
			printf("Interrupts:\t");

			if (hdr.ei)
				printf("EI\n");

			else
				printf("DI\n");

			continue;
		}

		// block
		if (!strcmp(t, STR(F_BLK))) {
			int size;
			int offset = 0;
			sscanf(v, "%[^ ,\t]%*[ ,\t]%[^ ,\t]%*[ ,\t]%s", v1, v2, v);
			a = num(v1);
			b = num(v2);

			if (a & 0x1FF)
				error(ALGN);

			if ((a < 0xC000) || (a > 0xFE00))
				error(ADDR);

			a -= 0xC000;
			printf("Block:\t\tStart: #%04X  Page: #%02X  File: %s\n", a, b, v);
			struct stat st;
			stat(v, &st);
			size = st.st_size;

			if (size < 0) {
				printf("%s: ", v);
				error(FNFD);
			}

			if (size == 0) {
				printf("%s: ", v);
				error(ZERO);
			}

			while (size) {
				int curr_size = min(size, 0x4000 - a);
				strncpy(blk[nblk].fname, v, sizeof(blk[nblk].fname));
				hdr.blk[nblk].addr = a >> 9;
				hdr.blk[nblk].page = b++;
				blk[nblk].offset = offset;
				blk[nblk].size = curr_size;
				a = 0;
				offset += curr_size;
				size -= curr_size;

				if (++nblk == 256)
					goto end_of_ini;
			}

			continue;
		}

		// unknown tag
		printf("%s: ", t);
		error(UNK);
	}

end_of_ini:

	if (!nblk)
		error(0BLK);

	conf.n_blocks = nblk;
	hdr.num_blk = conf.n_blocks;
	hdr.blk[conf.n_blocks - 1].last = 1;
	fclose(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
leaq 0x1ace(%rip), %rsi      # 0x40e7
callq 0x2130
testq %rax, %rax
je 0x2b8c
movq %rax, %r15
movq %rax, %rdi
callq 0x21e0
testl %eax, %eax
jne 0x2b68
leaq 0x21(%rsp), %r14
leaq 0x1a39(%rip), %r13      # 0x407f
leaq 0x20(%rsp), %rbp
leaq 0x3b0e(%rip), %r12      # 0x6160
movl $0x0, 0x4(%rsp)
movb $0x0, 0x20(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
leaq 0x120(%rsp), %rcx
xorl %eax, %eax
callq 0x2230
movzbl 0x20(%rsp), %eax
testl %eax, %eax
je 0x27b8
movq %r14, %rbx
cmpl $0x3b, %eax
je 0x28a0
movsbl %al, %edi
callq 0x21b0
movb %al, -0x1(%rbx)
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x2690
movl 0x20(%rsp), %eax
movl $0x63736564, %ecx       # imm = 0x63736564
xorl %ecx, %eax
movzbl 0x24(%rsp), %ecx
orl %eax, %ecx
je 0x27ce
movl 0x20(%rsp), %eax
movl $0x63617473, %ecx       # imm = 0x63617473
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x6b, %ecx
orl %eax, %ecx
je 0x27fc
movq 0x20(%rsp), %rax
movabsq $0x746e656469736572, %rcx # imm = 0x746E656469736572
xorq %rcx, %rax
movzbl 0x28(%rsp), %ecx
orq %rax, %rcx
je 0x281b
movl 0x20(%rsp), %eax
movl $0x65676170, %ecx       # imm = 0x65676170
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x72, %ecx
orl %eax, %ecx
je 0x283a
movl 0x20(%rsp), %eax
movl $0x72617473, %ecx       # imm = 0x72617473
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x74, %ecx
orl %eax, %ecx
je 0x285e
movl 0x20(%rsp), %eax
movl $0x65676170, %ecx       # imm = 0x65676170
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x33, %ecx
orl %eax, %ecx
je 0x287d
movl 0x20(%rsp), %eax
movl $0x636f6c63, %ecx       # imm = 0x636F6C63
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x6b, %ecx
orl %eax, %ecx
je 0x28c1
cmpl $0x746e69, 0x20(%rsp)   # imm = 0x746E69
jne 0x2912
leaq 0x120(%rsp), %rdi
callq 0x25c6
movb 0x35(%r12), %cl
shlb $0x2, %al
andb $0x4, %al
andb $-0x5, %cl
orb %al, %cl
movb %cl, 0x35(%r12)
leaq 0x19a9(%rip), %rdi      # 0x4142
xorl %eax, %eax
callq 0x2030
testb $0x4, 0x35(%r12)
jne 0x2ad4
leaq 0x1be4(%rip), %rdi      # 0x4397
jmp 0x2b07
movq %r15, %rdi
leaq 0x18d8(%rip), %rsi      # 0x409a
xorl %eax, %eax
callq 0x2230
jmp 0x28a0
movl $0x20, %edx
movq %r12, %rdi
leaq 0x120(%rsp), %rbx
movq %rbx, %rsi
callq 0x2060
leaq 0x18b6(%rip), %rdi      # 0x40a3
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2030
jmp 0x28a0
leaq 0x120(%rsp), %rdi
callq 0x25c6
movw %ax, 0x32(%r12)
movzwl %ax, %esi
leaq 0x18a1(%rip), %rdi      # 0x40ba
jmp 0x2899
leaq 0x120(%rsp), %rdi
callq 0x25c6
movw %ax, 0x38(%r12)
movzwl %ax, %esi
leaq 0x1897(%rip), %rdi      # 0x40cf
jmp 0x2899
leaq 0x120(%rsp), %rdi
callq 0x25c6
movw %ax, 0x36(%r12)
testw %ax, %ax
je 0x28b5
movzwl %ax, %esi
leaq 0x188d(%rip), %rdi      # 0x40e9
jmp 0x2899
leaq 0x120(%rsp), %rdi
callq 0x25c6
movw %ax, 0x30(%r12)
movzwl %ax, %esi
leaq 0x1885(%rip), %rdi      # 0x4100
jmp 0x2899
leaq 0x120(%rsp), %rdi
callq 0x25c6
movb %al, 0x34(%r12)
movzbl %al, %esi
leaq 0x187c(%rip), %rdi      # 0x4115
xorl %eax, %eax
callq 0x2030
movq %r15, %rdi
callq 0x21e0
testl %eax, %eax
je 0x265a
jmp 0x2b11
leaq 0x1ac5(%rip), %rdi      # 0x4381
jmp 0x2b07
leaq 0x120(%rsp), %rdi
callq 0x25c6
movb 0x35(%r12), %cl
andb $0x3, %al
andb $-0x4, %cl
orb %al, %cl
movb %cl, 0x35(%r12)
leaq 0x1848(%rip), %rdi      # 0x412e
xorl %eax, %eax
callq 0x2030
movzbl 0x35(%r12), %eax
andl $0x3, %eax
leaq 0x1707(%rip), %rcx      # 0x4004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x182a(%rip), %rdi      # 0x4137
jmp 0x2aed
movl 0x20(%rsp), %eax
movl $0x636f6c62, %ecx       # imm = 0x636F6C62
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x6b, %ecx
orl %eax, %ecx
jne 0x2bb0
leaq 0x120(%rsp), %rdi
leaq 0x1819(%rip), %rsi      # 0x4155
leaq 0x3b0(%rsp), %rbx
movq %rbx, %rdx
leaq 0x2b0(%rsp), %r13
movq %r13, %rcx
movq %rdi, %r8
xorl %eax, %eax
callq 0x20f0
movq %rbx, %rdi
callq 0x25c6
movq %rax, %r14
movq %r13, %rdi
callq 0x25c6
testl $0x1ff, %r14d           # imm = 0x1FF
jne 0x2be7
movq %rax, %rdx
movq %r14, %rax
addq $-0xfe01, %rax          # imm = 0xFFFF01FF
cmpq $-0x3e02, %rax          # imm = 0xC1FE
jbe 0x2c7f
addl $0xffff4000, %r14d      # imm = 0xFFFF4000
leaq 0x1821(%rip), %rdi      # 0x41c3
movl %r14d, %esi
movq %rdx, 0x10(%rsp)
leaq 0x120(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
leaq 0x220(%rsp), %rsi
callq 0x20c0
movl 0x250(%rsp), %r13d
testl %r13d, %r13d
js 0x2c45
movq %r15, 0x8(%rsp)
movl 0x4(%rsp), %ecx
je 0x2c0b
movslq %ecx, %rdx
imulq $0x4408, %rdx, %r15     # imm = 0x4408
addq 0x35e3(%rip), %r15      # 0x5fe0
leaq (%rdx,%rdx,2), %rax
leaq (%r12,%rax), %rbx
addq $0x100, %rbx            # imm = 0x100
incq %rdx
xorl %r12d, %r12d
movl %ecx, 0x4(%rsp)
testl %r13d, %r13d
je 0x2ab2
movl $0x4000, %ebp           # imm = 0x4000
subl %r14d, %ebp
cmpl %ebp, %r13d
cmovll %r13d, %ebp
movq %rdx, 0x18(%rsp)
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
leaq 0x120(%rsp), %rsi
callq 0x2060
shrl $0x9, %r14d
movzwl (%rbx), %eax
andl $0x1f, %r14d
andl $-0x20, %eax
orl %r14d, %eax
movw %ax, (%rbx)
movq 0x10(%rsp), %rdx
movb %dl, 0x2(%rbx)
movl %r12d, 0x400(%r15)
movl %ebp, 0x404(%r15)
addl %ebp, %r12d
subl %ebp, %r13d
movl 0x4(%rsp), %ecx
incl %ecx
addq $0x4408, %r15           # imm = 0x4408
addq $0x3, %rbx
movq 0x18(%rsp), %rsi
movq %rsi, %rax
incq %rax
incb %dl
movq %rdx, 0x10(%rsp)
xorl %r14d, %r14d
cmpl $0x100, %esi            # imm = 0x100
movq %rax, %rdx
jne 0x2a12
jmp 0x2b55
movq 0x8(%rsp), %r15
leaq 0x36a2(%rip), %r12      # 0x6160
leaq 0x21(%rsp), %r14
leaq 0x15b5(%rip), %r13      # 0x407f
leaq 0x20(%rsp), %rbp
jmp 0x28a0
leaq 0x18bf(%rip), %rdi      # 0x439a
jmp 0x2b07
leaq 0x1657(%rip), %rdi      # 0x413b
jmp 0x2aed
leaq 0x1651(%rip), %rdi      # 0x413e
xorl %eax, %eax
callq 0x2030
jmp 0x2b00
movl $0x37, %edi
callq 0x2180
leaq 0x188b(%rip), %rdi      # 0x4392
callq 0x21d0
jmp 0x28a0
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
je 0x2b68
leaq 0x444240(%rip), %rax    # 0x446d60
movl %ecx, 0x18(%rax)
movw %cx, 0x3a(%r12)
decl %ecx
movslq %ecx, %rax
leaq (%rax,%rax,2), %rax
orb $-0x80, 0x100(%r12,%rax)
movq %r15, %rdi
callq 0x2100
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x100, %ecx            # imm = 0x100
movq 0x8(%rsp), %r15
leaq 0x35fa(%rip), %r12      # 0x6160
jmp 0x2b19
leaq 0x16b7(%rip), %rdi      # 0x4226
xorl %eax, %eax
callq 0x2030
leaq 0x1753(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x8, %edi
callq 0x2150
leaq 0x14e0(%rip), %rdi      # 0x4073
xorl %eax, %eax
callq 0x2030
leaq 0x172f(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x2, %edi
callq 0x2150
leaq 0x1639(%rip), %rdi      # 0x41f0
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x164f(%rip), %rdi      # 0x4219
xorl %eax, %eax
callq 0x2030
leaq 0x16f8(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x3, %edi
callq 0x2150
leaq 0x1586(%rip), %rdi      # 0x4174
xorl %eax, %eax
callq 0x2030
leaq 0x16d4(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x4, %edi
callq 0x2150
leaq 0x15de(%rip), %rdi      # 0x41f0
leaq 0x120(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x15dd(%rip), %rdi      # 0x4205
xorl %eax, %eax
callq 0x2030
leaq 0x169a(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0xa, %edi
callq 0x2150
leaq 0x15a4(%rip), %rdi      # 0x41f0
leaq 0x120(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x1593(%rip), %rdi      # 0x41f5
xorl %eax, %eax
callq 0x2030
leaq 0x1660(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x5, %edi
callq 0x2150
leaq 0x1513(%rip), %rdi      # 0x4199
xorl %eax, %eax
callq 0x2030
leaq 0x163c(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0xd, %edi
callq 0x2150