// File: /workspace/github_c_makefile_star2_O1/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 0x4b43d
testq %rax, %rax
je 0x1dbf6
movq %rax, %rbx
callq 0x4b6e4
leaq 0x74ca8(%rip), %rax     # 0x926b0
movw $0x101, (%rax)          # imm = 0x101
movw $0x0, 0x4(%rax)
movq %rbx, %rdi
callq 0x4ac84
testq %rax, %rax
je 0x1dba8
movq %rax, %r12
leaq 0x73b82(%rip), %r14     # 0x915b0
leaq 0x5656b(%rip), %r15     # 0x73fa0
movq %r12, %rdi
leaq 0x565d2(%rip), %rsi     # 0x74011
callq 0x6880
testl %eax, %eax
je 0x1da7e
xorl %ecx, %ecx
leaq 0x20(%rcx), %rbp
cmpq $0x400, %rbp            # imm = 0x400
je 0x1db78
movq 0x20(%rcx,%r14), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x6880
movq %rbp, %rcx
testl %eax, %eax
jne 0x1da4a
testq %r13, %r13
sete %r12b
addq %r14, %rbp
jmp 0x1da84
xorl %r12d, %r12d
movq %r14, %rbp
movq %rbx, %rdi
callq 0x4acc2
leaq 0x55531(%rip), %rdi     # 0x72fc4
movq %rax, %rsi
callq 0x6880
testl %eax, %eax
jne 0x1daa7
movq %rbx, %rdi
callq 0x4ac84
movl 0x8(%rbp), %eax
cmpq $0x4, %rax
ja 0x1db67
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4ad79
testl %eax, %eax
jne 0x1db73
xorl %eax, %eax
cmpl $0x0, (%rsp)
setne %al
jmp 0x1db39
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4ae87
testl %eax, %eax
jne 0x1db73
movsd (%rsp), %xmm0
mulsd 0x5648a(%rip), %xmm0    # 0x73f90
cvttsd2si %xmm0, %eax
jmp 0x1db39
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4ad79
jmp 0x1db32
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4ae7d
testl %eax, %eax
jne 0x1db73
movl (%rsp), %eax
movq 0x10(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x1db73
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4ae87
testl %eax, %eax
jne 0x1db73
movsd (%rsp), %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x1db73
leaq 0x5645a(%rip), %rdi     # 0x73fc8
callq 0x32200
testb %r12b, %r12b
je 0x1db94
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x4ad2c
leaq 0x5645e(%rip), %rdi     # 0x73fe9
movl %eax, %esi
xorl %eax, %eax
callq 0x24cb4
movq %rbx, %rdi
callq 0x4ac84
movq %rax, %r12
testq %rax, %rax
jne 0x1da35
movl 0x8546e(%rip), %edi     # 0xa301c
testl %edi, %edi
js 0x1dbb7
callq 0x3c5be
movl 0x85463(%rip), %eax     # 0xa3020
testl %eax, %eax
js 0x1dbd6
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
leaq 0x10ed49(%rip), %rax    # 0x12c91c
movw %cx, (%rax)
leaq 0x74ae3(%rip), %rax     # 0x926c0
movl 0x4c(%rax), %edi
callq 0x49647
movq %rbx, %rdi
callq 0x4b574
callq 0x4b6e4
xorl %eax, %eax
jmp 0x1dbfb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq