// File: /workspace/github_c_makefile_star2_O2/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 0x44c62
testq %rax, %rax
je 0x1bb17
movq %rax, %rbx
callq 0x44ed1
leaq 0x70d54(%rip), %rax     # 0x8c6b0
movw $0x101, (%rax)          # imm = 0x101
andw $0x0, 0x4(%rax)
pushq $-0x18
popq %r12
leaq 0x6fc5f(%rip), %r13     # 0x8b5d0
leaq 0x4e650(%rip), %r15     # 0x69fc8
movq %rbx, %rdi
callq 0x4454c
testq %rax, %rax
je 0x1bacb
movq %rax, %rbp
movq %r12, %rcx
leaq 0x20(%rcx), %r14
cmpq $0x408, %r14            # imm = 0x408
je 0x1ba0c
movq 0x18(%rcx,%r13), %rsi
movq %rbp, %rdi
callq 0x6880
movq %r14, %rcx
testl %eax, %eax
jne 0x1b98f
movq %rbx, %rdi
callq 0x445b1
leaq 0x4d60f(%rip), %rdi     # 0x68fce
movq %rax, %rsi
callq 0x6880
testl %eax, %eax
jne 0x1b9d3
movq %rbx, %rdi
callq 0x4454c
movl (%r14,%r13), %eax
cmpq $0x4, %rax
ja 0x1baba
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4465e
testl %eax, %eax
jne 0x1b978
xorl %eax, %eax
cmpl $0x0, (%rsp)
setne %al
jmp 0x1ba83
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x44619
leaq 0x4e5f2(%rip), %rdi     # 0x6a011
movl %eax, %esi
xorl %eax, %eax
callq 0x22427
jmp 0x1b978
andq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4473e
testl %eax, %eax
jne 0x1b978
movsd (%rsp), %xmm0
mulsd 0x4e566(%rip), %xmm0    # 0x69fb8
cvttsd2si %xmm0, %eax
jmp 0x1ba83
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4465e
jmp 0x1ba78
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x44736
testl %eax, %eax
jne 0x1b978
movl (%rsp), %eax
movq 0x8(%r14,%r13), %rcx
movl %eax, (%rcx)
jmp 0x1b978
andq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x4473e
testl %eax, %eax
jne 0x1b978
movsd (%rsp), %xmm0
movq 0x8(%r14,%r13), %rax
movsd %xmm0, (%rax)
jmp 0x1b978
leaq 0x4e52f(%rip), %rdi     # 0x69ff0
callq 0x30c8d
jmp 0x1b978
movl 0x8154b(%rip), %edi     # 0x9d01c
testl %edi, %edi
js 0x1bada
callq 0x39be6
movl 0x81540(%rip), %eax     # 0x9d020
testl %eax, %eax
js 0x1baf7
cmpl $0xf, %eax
pushq $0xf
popq %rcx
cmovbl %eax, %ecx
leaq 0x10ae28(%rip), %rax    # 0x12691c
movw %cx, (%rax)
leaq 0x70bc2(%rip), %rax     # 0x8c6c0
movl 0x4c(%rax), %edi
callq 0x432a5
movq %rbx, %rdi
callq 0x44d91
callq 0x44ed1
xorl %eax, %eax
jmp 0x1bb1a
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq