// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/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();

	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_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 (tmpsamplerate >= 0) {
		option[7] = (tmpsamplerate & 0x0f) << 4;
		option[7] |= 1<<1;	// 16-bit
		option[7] |= 1<<2;	// stereo
	}
	if (tmpmusic >= 0) {
		option[2] = !!tmpmusic;
	}
	if (tmpmouse == 0) {
		option[3] &= ~1;
	} else if (tmpmouse > 0) {
		option[3] |= 1;
	}
	if (tmpjoystick == 0) {
		option[3] &= ~2;
	} else if (tmpjoystick > 0) {
		option[3] |= 2;
	}
	OSD_CaptureKey(keys[19]);

	gamestuff[3] = min(max(gamestuff[3],0),15);	// Brightness.

	scriptfile_close(cfg);
	scriptfile_clearsymbols();

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x571da
testq %rax, %rax
je 0x97a0
movq %rax, %rbx
callq 0x57449
pushq $-0x18
popq %r12
leaq 0xbc6a4(%rip), %r13     # 0xc5cc0
leaq 0x769e1(%rip), %r15     # 0x80004
movq %rbx, %rdi
callq 0x56ac4
testq %rax, %rax
je 0x974b
movq %rax, %rbp
movq %r12, %rcx
leaq 0x20(%rcx), %r14
cmpq $0x5e8, %r14            # imm = 0x5E8
je 0x96b7
movq 0x18(%rcx,%r13), %rsi
movq %rbp, %rdi
callq 0x8bc0
movq %r14, %rcx
testl %eax, %eax
jne 0x963a
movq %rbx, %rdi
callq 0x56b29
leaq 0x769ba(%rip), %rdi     # 0x80024
movq %rax, %rsi
callq 0x8bc0
testl %eax, %eax
jne 0x967e
movq %rbx, %rdi
callq 0x56ac4
movl (%r14,%r13), %eax
cmpq $0x3, %rax
ja 0x973a
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x56bd6
testl %eax, %eax
jne 0x9623
xorl %eax, %eax
cmpl $0x0, (%rsp)
setne %al
jmp 0x9703
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x56b91
leaq 0x7697d(%rip), %rdi     # 0x80047
movl %eax, %esi
xorl %eax, %eax
callq 0x33127
jmp 0x9623
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x56bd6
jmp 0x96f8
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x56cae
testl %eax, %eax
jne 0x9623
movl (%rsp), %eax
movq 0x8(%r14,%r13), %rcx
movl %eax, (%rcx)
jmp 0x9623
andq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x56cb6
testl %eax, %eax
jne 0x9623
movsd (%rsp), %xmm0
movq 0x8(%r14,%r13), %rax
movsd %xmm0, (%rax)
jmp 0x9623
leaq 0x768e5(%rip), %rdi     # 0x80026
callq 0x4198d
jmp 0x9623
movl 0xbe1ef(%rip), %edi     # 0xc7940
testl %edi, %edi
js 0x975a
callq 0x4a8e6
movl 0xbe1e4(%rip), %eax     # 0xc7944
testl %eax, %eax
js 0x9773
shlb $0x4, %al
orb $0x6, %al
leaq 0xbe208(%rip), %rcx     # 0xc7978
movb %al, 0x7(%rcx)
cmpl $0x0, 0xbe1ce(%rip)     # 0xc7948
js 0x9787
leaq 0xbe1f5(%rip), %rax     # 0xc7978
setne 0x2(%rax)
cmpl $0x0, 0xbe1be(%rip)     # 0xc794c
je 0x97a5
jle 0x97bb
leaq 0xbe1df(%rip), %rax     # 0xc7978
movb 0x3(%rax), %al
orb $0x1, %al
jmp 0x97b1
pushq $-0x1
popq %rbp
jmp 0x9823
leaq 0xbe1cc(%rip), %rax     # 0xc7978
movb 0x3(%rax), %al
andb $-0x2, %al
leaq 0xbe1c0(%rip), %rcx     # 0xc7978
movb %al, 0x3(%rcx)
cmpl $0x0, 0xbe18e(%rip)     # 0xc7950
je 0x97d4
jle 0x97ea
leaq 0xbe1ab(%rip), %rax     # 0xc7978
movb 0x3(%rax), %al
orb $0x2, %al
jmp 0x97e0
leaq 0xbe19d(%rip), %rax     # 0xc7978
movb 0x3(%rax), %al
andb $-0x3, %al
leaq 0xbe191(%rip), %rcx     # 0xc7978
movb %al, 0x3(%rcx)
leaq 0xbe18f(%rip), %rax     # 0xc7980
movl 0x4c(%rax), %edi
callq 0x5581d
leaq 0xbe2a0(%rip), %rax     # 0xc7aa0
movl 0xc(%rax), %ecx
xorl %ebp, %ebp
testl %ecx, %ecx
cmovlel %ebp, %ecx
cmpl $0xf, %ecx
pushq $0xf
popq %rdx
cmovll %ecx, %edx
movl %edx, 0xc(%rax)
movq %rbx, %rdi
callq 0x57309
callq 0x57449
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq