// File: /workspace/github_c_makefile_star2_O3/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 0x61939
testq %rax, %rax
je 0xa3d7
movq %rax, %rbx
callq 0x61bce
movq %rbx, %rdi
callq 0x611b4
testq %rax, %rax
je 0xa382
movq %rax, %r12
leaq 0x83e32(%rip), %r14     # 0x8e076
leaq 0xc5a75(%rip), %r15     # 0xcfcc0
leaq 0x83db2(%rip), %r13     # 0x8e004
movq %r12, %rdi
movq %r14, %rsi
callq 0x8bc0
movq %r15, %rbp
testl %eax, %eax
je 0xa28a
xorl %ecx, %ecx
leaq 0x20(%rcx), %rbp
cmpq $0x5e0, %rbp            # imm = 0x5E0
je 0xa2e9
movq 0x20(%rcx,%r15), %rsi
movq %r12, %rdi
callq 0x8bc0
movq %rbp, %rcx
testl %eax, %eax
jne 0xa266
addq %r15, %rbp
movq %rbx, %rdi
callq 0x611ee
leaq 0x83d8b(%rip), %rdi     # 0x8e024
movq %rax, %rsi
callq 0x8bc0
testl %eax, %eax
jne 0xa2ad
movq %rbx, %rdi
callq 0x611b4
movl 0x8(%rbp), %eax
cmpq $0x3, %rax
ja 0xa362
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x612a5
testl %eax, %eax
jne 0xa36e
xorl %eax, %eax
cmpl $0x0, (%rsp)
setne %al
jmp 0xa334
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x61258
leaq 0x83d4b(%rip), %rdi     # 0x8e047
movl %eax, %esi
xorl %eax, %eax
callq 0x372d1
jmp 0xa36e
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x612a5
jmp 0xa32d
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x613a8
testl %eax, %eax
jne 0xa36e
movl (%rsp), %eax
movq 0x10(%rbp), %rcx
movl %eax, (%rcx)
jmp 0xa36e
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x613b2
testl %eax, %eax
jne 0xa36e
movsd (%rsp), %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0xa36e
leaq 0x83cbd(%rip), %rdi     # 0x8e026
callq 0x44dc8
movq %rbx, %rdi
callq 0x611b4
movq %rax, %r12
testq %rax, %rax
jne 0xa252
movl 0xc75b8(%rip), %edi     # 0xd1940
testl %edi, %edi
js 0xa391
callq 0x4fae4
movl 0xc75ad(%rip), %eax     # 0xd1944
testl %eax, %eax
js 0xa3aa
shlb $0x4, %al
orb $0x6, %al
leaq 0xc75d1(%rip), %rcx     # 0xd1978
movb %al, 0x7(%rcx)
cmpl $0x0, 0xc7597(%rip)     # 0xd1948
js 0xa3be
leaq 0xc75be(%rip), %rax     # 0xd1978
setne 0x2(%rax)
cmpl $0x0, 0xc7587(%rip)     # 0xd194c
je 0xa3e1
jle 0xa3f7
leaq 0xc75a8(%rip), %rax     # 0xd1978
movb 0x3(%rax), %al
orb $0x1, %al
jmp 0xa3ed
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xa461
leaq 0xc7590(%rip), %rax     # 0xd1978
movb 0x3(%rax), %al
andb $-0x2, %al
leaq 0xc7584(%rip), %rcx     # 0xd1978
movb %al, 0x3(%rcx)
cmpl $0x0, 0xc7552(%rip)     # 0xd1950
je 0xa410
jle 0xa426
leaq 0xc756f(%rip), %rax     # 0xd1978
movb 0x3(%rax), %al
orb $0x2, %al
jmp 0xa41c
leaq 0xc7561(%rip), %rax     # 0xd1978
movb 0x3(%rax), %al
andb $-0x3, %al
leaq 0xc7555(%rip), %rcx     # 0xd1978
movb %al, 0x3(%rcx)
leaq 0xc7553(%rip), %rax     # 0xd1980
movl 0x4c(%rax), %edi
callq 0x5f853
leaq 0xc7664(%rip), %rax     # 0xd1aa0
movl 0xc(%rax), %ecx
xorl %ebp, %ebp
testl %ecx, %ecx
cmovlel %ebp, %ecx
cmpl $0xf, %ecx
movl $0xf, %edx
cmovll %ecx, %edx
movl %edx, 0xc(%rax)
movq %rbx, %rdi
callq 0x61a70
callq 0x61bce
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq