// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/config.c
// Function: loadsetup
int loadsetup(const char *fn)
{
	scriptfile *cfg;
	char *token;
	int item;

	cfg = scriptfile_fromfile(fn);
	if (!cfg) {
		return -1;
	}

	scriptfile_clearsymbols();

	option[0] = 1;	// vesa all the way...
	option[1] = 1;	// sound all the way...
	option[4] = 0;	// no multiplayer
	option[5] = 0;

	while (1) {
		token = scriptfile_gettoken(cfg);
		if (!token) break;	//EOF

		for (item = 0; configspec[item].name; item++) {
			if (!Bstrcasecmp(token, configspec[item].name)) {
				// Seek past any = symbol.
				token = scriptfile_peektoken(cfg);
				if (!Bstrcasecmp("=", token)) {
					scriptfile_gettoken(cfg);
				}

				switch (configspec[item].type) {
					case type_bool: {
						int value = 0;
						if (scriptfile_getnumber(cfg, &value)) break;
						*(int*)configspec[item].store = (value != 0);
						break;
					}
					case type_int: {
						int value = 0;
						if (scriptfile_getnumber(cfg, &value)) break;
						*(int*)configspec[item].store = value;
						break;
					}
					case type_hex: {
						int value = 0;
						if (scriptfile_gethex(cfg, &value)) break;
						*(int*)configspec[item].store = value;
						break;
					}
					case type_fixed16: {
						double value = 0.0;
						if (scriptfile_getdouble(cfg, &value)) break;
						*(int*)configspec[item].store = (int)(value*65536.0);
						break;
					}
					case type_double: {
						double value = 0.0;
						if (scriptfile_getdouble(cfg, &value)) break;
						*(double*)configspec[item].store = value;
						break;
					}
					default: {
						buildputs("loadsetup: unhandled value type\n");
						break;
					}
				}
				break;
			}
		}
		if (!configspec[item].name) {
			buildprintf("loadsetup: error on line %d\n", scriptfile_getlinum(cfg, cfg->ltextptr));
			continue;
		}
	}

#if USE_POLYMOST
	if (tmprenderer >= 0) {
		setrendermode(tmprenderer);
	}
#endif
#ifdef RENDERTYPEWIN
	win_setmaxrefreshfreq(tmpmaxrefreshfreq);
#endif
	if (tmpbrightness >= 0) {
		brightness = min(max(tmpbrightness,0),15);
	}
	OSD_CaptureKey(keys[19]);

	scriptfile_close(cfg);
	scriptfile_clearsymbols();

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x4dbed
testq %rax, %rax
je 0x1e073
movq %rax, %rbx
callq 0x4de82
leaq 0x7581c(%rip), %rax     # 0x936b0
movw $0x101, (%rax)          # imm = 0x101
movw $0x0, 0x4(%rax)
movq %rbx, %rdi
callq 0x4d468
testq %rax, %rax
je 0x1e025
movq %rax, %r12
leaq 0x5723f(%rip), %r14     # 0x750f9
leaq 0x7472f(%rip), %r15     # 0x925f0
leaq 0x571c0(%rip), %r13     # 0x75088
movq %r12, %rdi
movq %r14, %rsi
callq 0x6880
movq %r15, %rbp
testl %eax, %eax
je 0x1df00
xorl %ecx, %ecx
leaq 0x20(%rcx), %rbp
cmpq $0x400, %rbp            # imm = 0x400
je 0x1df5f
movq 0x20(%rcx,%r15), %rsi
movq %r12, %rdi
callq 0x6880
movq %rbp, %rcx
testl %eax, %eax
jne 0x1dedc
addq %r15, %rbp
movq %rbx, %rdi
callq 0x4d4a2
leaq 0x56101(%rip), %rdi     # 0x74010
movq %rax, %rsi
callq 0x6880
testl %eax, %eax
jne 0x1df23
movq %rbx, %rdi
callq 0x4d468
movl 0x8(%rbp), %eax
cmpq $0x4, %rax
ja 0x1e005
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4d559
testl %eax, %eax
jne 0x1e011
xorl %eax, %eax
cmpl $0x0, (%rsp)
setne %al
jmp 0x1dfd7
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x4d50c
leaq 0x5715f(%rip), %rdi     # 0x750d1
movl %eax, %esi
xorl %eax, %eax
callq 0x25221
jmp 0x1e011
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4d666
testl %eax, %eax
jne 0x1e011
movsd (%rsp), %xmm0
mulsd 0x570d4(%rip), %xmm0    # 0x75078
cvttsd2si %xmm0, %eax
jmp 0x1dfd7
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4d559
jmp 0x1dfd0
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4d65c
testl %eax, %eax
jne 0x1e011
movl (%rsp), %eax
movq 0x10(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x1e011
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4d666
testl %eax, %eax
jne 0x1e011
movsd (%rsp), %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x1e011
leaq 0x570a4(%rip), %rdi     # 0x750b0
callq 0x32d18
movq %rbx, %rdi
callq 0x4d468
movq %rax, %r12
testq %rax, %rax
jne 0x1dec8
movl 0x85ff1(%rip), %edi     # 0xa401c
testl %edi, %edi
js 0x1e034
callq 0x3da34
movl 0x85fe6(%rip), %eax     # 0xa4020
testl %eax, %eax
js 0x1e053
cmpl $0xf, %eax
movl $0xf, %ecx
cmovbl %eax, %ecx
leaq 0x10f8cc(%rip), %rax    # 0x12d91c
movw %cx, (%rax)
leaq 0x75666(%rip), %rax     # 0x936c0
movl 0x4c(%rax), %edi
callq 0x4bb07
movq %rbx, %rdi
callq 0x4dd24
callq 0x4de82
xorl %eax, %eax
jmp 0x1e078
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq