// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movl $0x0, -0x438(%rbp)
movl $0x0, -0x43c(%rbp)
leaq 0xa352b(%rip), %rdi     # 0xb0a01
leaq 0xa2765(%rip), %rsi     # 0xafc42
callq 0x2f500
movq %rax, -0x448(%rbp)
cmpq $0x0, -0x448(%rbp)
jne 0xd52f
leaq 0xa350f(%rip), %rdi     # 0xb0a09
leaq 0xa2741(%rip), %rsi     # 0xafc42
callq 0x2f500
movq %rax, -0x448(%rbp)
cmpq $0x0, %rax
jne 0xd52d
leaq 0xa34f7(%rip), %rdi     # 0xb0a11
movb $0x0, %al
callq 0x37c90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd9f2
jmp 0xd52f
leaq 0x170fea(%rip), %rdi    # 0x17e520
xorl %esi, %esi
movl $0x38400, %edx          # imm = 0x38400
callq 0x62d0
leaq 0xa34e0(%rip), %rdi     # 0xb0a29
movb $0x0, %al
callq 0x37c90
leaq -0x410(%rbp), %rdi
movq -0x448(%rbp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x65f0
cmpq $0x0, %rax
je 0xd9c5
leaq -0x410(%rbp), %rdi
callq 0x63d0
movl %eax, -0x440(%rbp)
cmpl $0x1, -0x440(%rbp)
jl 0xd5f0
cmpl $0x1, -0x440(%rbp)
jle 0xd5c3
movl -0x440(%rbp), %eax
subl $0x2, %eax
cltq
movsbl -0x410(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0xd5c1
movl -0x440(%rbp), %eax
subl $0x2, %eax
cltq
movb $0x0, -0x410(%rbp,%rax)
jmp 0xd5c3
movl -0x440(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x410(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0xd5ee
movl -0x440(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x410(%rbp,%rax)
jmp 0xd5f0
leaq -0x410(%rbp), %rax
movq %rax, -0x418(%rbp)
movl -0x43c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x43c(%rbp)
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xd630
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0xd60d
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xd644
jmp 0xd550
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0xd96c
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xd68c
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0xd669
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xd6a0
jmp 0xd550
movq -0x418(%rbp), %rdi
leaq 0xa338c(%rip), %rsi     # 0xb0a3a
movl $0x7, %edx
callq 0x6240
cmpl $0x0, %eax
jne 0xd96a
movq -0x418(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x418(%rbp)
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xd6f6
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0xd6d3
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xd721
movl -0x43c(%rbp), %esi
subl $0x1, %esi
leaq 0xa332d(%rip), %rdi     # 0xb0a42
movb $0x0, %al
callq 0x37c90
jmp 0xd550
movq -0x418(%rbp), %rax
movq %rax, -0x420(%rbp)
movq -0x418(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x20, %ecx
movb %al, -0x449(%rbp)
je 0xd75c
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x449(%rbp)
movb -0x449(%rbp), %al
testb $0x1, %al
jne 0xd768
jmp 0xd77c
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0xd72f
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xd947
movq -0x418(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x418(%rbp)
movb $0x0, (%rax)
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xd7ca
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0xd7a7
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xd7fc
movq -0x420(%rbp), %rsi
movl -0x43c(%rbp), %edx
subl $0x1, %edx
leaq 0xa3277(%rip), %rdi     # 0xb0a67
movb $0x0, %al
callq 0x37c90
jmp 0xd550
movq -0x418(%rbp), %rax
movq %rax, -0x428(%rbp)
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xd82d
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0xd80a
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xd846
movq -0x418(%rbp), %rax
movb $0x0, (%rax)
movq -0x428(%rbp), %rdi
leaq -0x430(%rbp), %rsi
movl $0xa, %edx
callq 0x68a0
movl %eax, -0x434(%rbp)
movq -0x430(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xd886
movq -0x430(%rbp), %rax
movq %rax, -0x418(%rbp)
jmp 0xd996
cmpl $0x0, -0x434(%rbp)
jl 0xd89b
cmpl $0x2400, -0x434(%rbp)   # imm = 0x2400
jl 0xd8c4
movl -0x434(%rbp), %esi
movq -0x420(%rbp), %rdx
movl -0x43c(%rbp), %ecx
subl $0x1, %ecx
leaq 0xa31df(%rip), %rdi     # 0xb0a97
movb $0x0, %al
callq 0x37c90
jmp 0xd550
movq -0x420(%rbp), %rdi
callq 0x63d0
cmpq $0x18, %rax
jbe 0xd8f4
movq -0x420(%rbp), %rsi
movl -0x43c(%rbp), %edx
subl $0x1, %edx
leaq 0xa31e3(%rip), %rdi     # 0xb0ad0
movb $0x0, %al
callq 0x37c90
movslq -0x434(%rbp), %rax
leaq 0x170c1e(%rip), %rdi    # 0x17e520
imulq $0x19, %rax, %rax
addq %rax, %rdi
movq -0x420(%rbp), %rsi
movl $0x18, %edx
callq 0x6180
movslq -0x434(%rbp), %rcx
leaq 0x170bf8(%rip), %rax    # 0x17e520
imulq $0x19, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x18(%rax)
movl -0x438(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x438(%rbp)
jmp 0xd550
movq -0x420(%rbp), %rsi
movl -0x43c(%rbp), %edx
subl $0x1, %edx
leaq 0xa3109(%rip), %rdi     # 0xb0a67
movb $0x0, %al
callq 0x37c90
jmp 0xd550
jmp 0xd996
movq -0x418(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xd992
movq -0x418(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0xd990
jmp 0xd550
jmp 0xd992
jmp 0xd994
jmp 0xd996
movq -0x418(%rbp), %rax
leaq -0x410(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movl -0x43c(%rbp), %edx
subl $0x1, %edx
leaq 0xa315c(%rip), %rdi     # 0xb0b15
movb $0x0, %al
callq 0x37c90
jmp 0xd550
movl -0x43c(%rbp), %esi
movl -0x438(%rbp), %edx
leaq 0xa3178(%rip), %rdi     # 0xb0b50
movb $0x0, %al
callq 0x37c90
movq -0x448(%rbp), %rdi
callq 0x6420
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nop