// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/build.c
// Function: loadnames
int loadnames(void)
{
	char buffer[1024], *p, *name, *number, *endptr;
	int num, syms=0, line=0, a;
	BFILE *fp;

	fp = fopenfrompath("NAMES.H","r");
	if (!fp) {
		if ((fp = fopenfrompath("names.h","r")) == NULL) {
			buildprintf("Failed to open NAMES.H\n");
			return -1;
		}
	}

	//clearbufbyte(names, sizeof(names), 0);
	memset(names,0,sizeof(names));

	buildprintf("Loading NAMES.H\n");

	while (Bfgets(buffer, 1024, fp)) {
		a = (int)strlen(buffer);
		if (a >= 1) {
			if (a > 1)
				if (buffer[a-2] == '\r') buffer[a-2] = 0;
			if (buffer[a-1] == '\n') buffer[a-1] = 0;
		}

		p = buffer;
		line++;
		while (*p == 32) p++;
		if (*p == 0) continue;	// blank line

		if (*p == '#') {
			p++;
			while (*p == 32) p++;
			if (*p == 0) continue;	// null directive

			if (!Bstrncmp(p, "define ", 7)) {
				// #define_...
				p += 7;
				while (*p == 32) p++;
				if (*p == 0) {
					buildprintf("Error: Malformed #define at line %d\n", line-1);
					continue;
				}

				name = p;
				while (*p != 32 && *p != 0) p++;
				if (*p == 32) {
					*(p++) = 0;
					while (*p == 32) p++;
					if (*p == 0) {	// #define_NAME with no number
						buildprintf("Error: No number given for name \"%s\" (line %d)\n", name, line-1);
						continue;
					}

					number = p;
					while (*p != 0) p++;
					if (*p != 0) *p = 0;

					// add to list
					num = (int)strtol(number, &endptr, 10);
					if (*endptr != 0) {
						p = endptr;
						goto badline;
					}
					if (num < 0 || num >= MAXTILES) {
						buildprintf("Error: Constant %d for name \"%s\" out of range (line %d)\n", num, name, line-1);
						continue;
					}

					if (Bstrlen(name) > 24)
						buildprintf("Warning: Name \"%s\" longer than 24 characters (line %d). Truncating.\n", name, line-1);

					Bstrncpy(names[num], name, 24);
					names[num][24] = 0;

					syms++;

					continue;

				} else {	// #define_NAME with no number
					buildprintf("Error: No number given for name \"%s\" (line %d)\n", name, line-1);
					continue;
				}
			} else goto badline;
		} else if (*p == '/') {
			if (*(p+1) == '/') continue;	// comment
		}
badline:
		buildprintf("Error: Invalid statement found at character %d on line %d\n", (int)(p-buffer), line-1);
	}
	buildprintf("Read %d lines, loaded %d names.\n", line, syms);

	Bfclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
leaq 0x6815b(%rip), %rdi     # 0x73aa8
leaq 0x673a4(%rip), %rsi     # 0x72cf8
callq 0x1f96c
testq %rax, %rax
jne 0xb97a
leaq 0x6814b(%rip), %rdi     # 0x73ab0
leaq 0x6738c(%rip), %rsi     # 0x72cf8
callq 0x1f96c
testq %rax, %rax
je 0xbbd6
movq %rax, %rbx
leaq 0x13543c(%rip), %rdi    # 0x140dc0
movl $0x38400, %edx          # imm = 0x38400
xorl %esi, %esi
callq 0x62f0
leaq 0x68139(%rip), %rdi     # 0x73ad0
xorl %eax, %eax
callq 0x24cb4
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x6660
movl $0x0, 0x4(%rsp)
movl $0x0, %r14d
testq %rax, %rax
je 0xbba5
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
movl %r14d, %ebp
movq %r13, %rdi
callq 0x6420
testl %eax, %eax
jle 0xba11
cmpl $0x1, %eax
je 0xb9fc
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
addl %eax, %ecx
cmpb $0xd, 0x10(%rsp,%rcx)
jne 0xb9fc
movb $0x0, 0x10(%rsp,%rcx)
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
addl %ecx, %eax
incl %eax
cmpb $0xa, 0x10(%rsp,%rax)
jne 0xba11
movb $0x0, 0x10(%rsp,%rax)
leal 0x1(%rbp), %r14d
movq %r13, %r15
movzbl (%r15), %eax
cmpl $0x20, %eax
jne 0xba26
incq %r15
jmp 0xba18
testl %eax, %eax
je 0xba90
cmpl $0x2f, %eax
je 0xba73
cmpl $0x23, %eax
jne 0xba7a
movzbl 0x1(%r15), %eax
incq %r15
cmpl $0x20, %eax
je 0xba34
testl %eax, %eax
je 0xba90
movl $0x7, %edx
movq %r15, %rdi
leaq 0x6808d(%rip), %rsi     # 0x73ae1
callq 0x6250
testl %eax, %eax
jne 0xba7a
addq $0x7, %r15
movq %r15, %r12
movzbl (%r12), %eax
cmpl $0x20, %eax
jne 0xbaae
incq %r12
jmp 0xba64
cmpb $0x2f, 0x1(%r15)
je 0xba90
subl %r13d, %r15d
leaq 0x68138(%rip), %rdi     # 0x73bbc
movl %r15d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x24cb4
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x6660
testq %rax, %rax
jne 0xb9d5
jmp 0xbba5
movq %r12, %rdi
testl %eax, %eax
jne 0xbac7
leaq 0x6802d(%rip), %rdi     # 0x73ae9
movl %ebp, %esi
xorl %eax, %eax
callq 0x24cb4
jmp 0xba90
movzbl (%rdi), %eax
testl %eax, %eax
je 0xbaee
cmpl $0x20, %eax
je 0xbad8
incq %rdi
jmp 0xbac7
movb $0x0, (%rdi)
movzbl 0x1(%rdi), %ecx
incq %rdi
cmpl $0x20, %ecx
je 0xbadb
movq %rdi, %rax
testl %ecx, %ecx
jne 0xbb03
leaq 0x68019(%rip), %rdi     # 0x73b0e
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x24cb4
jmp 0xba90
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0xbb03
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x6940
movq 0x8(%rsp), %r15
cmpb $0x0, (%r15)
jne 0xba7a
cmpl $0x2400, %eax           # imm = 0x2400
jb 0xbb4b
leaq 0x68006(%rip), %rdi     # 0x73b3e
movl %eax, %esi
movq %r12, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x24cb4
jmp 0xba90
movq %rax, %r15
movq %r12, %rdi
callq 0x6420
cmpq $0x19, %rax
jb 0xbb6f
leaq 0x68014(%rip), %rdi     # 0x73b77
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x24cb4
andl $0x3fff, %r15d          # imm = 0x3FFF
leaq (%r15,%r15,4), %rax
leaq (%rax,%rax,4), %r15
leaq 0x13523b(%rip), %rbp    # 0x140dc0
leaq (%r15,%rbp), %rdi
movl $0x18, %edx
movq %r12, %rsi
callq 0x6190
movb $0x0, 0x18(%rbp,%r15)
incl 0x4(%rsp)
jmp 0xba90
leaq 0x6804b(%rip), %rdi     # 0x73bf7
movl %r14d, %esi
movl 0x4(%rsp), %edx
xorl %eax, %eax
callq 0x24cb4
movq %rbx, %rdi
callq 0x6480
xorl %eax, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x67edb(%rip), %rdi     # 0x73ab8
xorl %eax, %eax
callq 0x24cb4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xbbc4