// File: /workspace/github_c_makefile_star2_O1/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 0x5e2b5
testq %rax, %rax
je 0xa3c5
movq %rax, %rbx
callq 0x5e55c
movq %rbx, %rdi
callq 0x5dafc
testq %rax, %rax
je 0xa370
movq %rax, %r12
leaq 0xc2a2c(%rip), %r14     # 0xccc50
leaq 0x80dd9(%rip), %r15     # 0x8b004
movq %r12, %rdi
leaq 0x80e41(%rip), %rsi     # 0x8b076
callq 0x8bc0
testl %eax, %eax
je 0xa274
xorl %ecx, %ecx
leaq 0x20(%rcx), %rbp
cmpq $0x5e0, %rbp            # imm = 0x5E0
je 0xa340
movq 0x20(%rcx,%r14), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x8bc0
movq %rbp, %rcx
testl %eax, %eax
jne 0xa240
testq %r13, %r13
sete %r12b
addq %r14, %rbp
jmp 0xa27a
xorl %r12d, %r12d
movq %r14, %rbp
movq %rbx, %rdi
callq 0x5db3a
leaq 0x80d9b(%rip), %rdi     # 0x8b024
movq %rax, %rsi
callq 0x8bc0
testl %eax, %eax
jne 0xa29d
movq %rbx, %rdi
callq 0x5dafc
movl 0x8(%rbp), %eax
cmpq $0x3, %rax
ja 0xa32f
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x5dbf1
testl %eax, %eax
jne 0xa33b
xorl %eax, %eax
cmpl $0x0, (%rsp)
setne %al
jmp 0xa301
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x5dbf1
jmp 0xa2fa
movl $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x5dcf5
testl %eax, %eax
jne 0xa33b
movl (%rsp), %eax
movq 0x10(%rbp), %rcx
movl %eax, (%rcx)
jmp 0xa33b
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x5dcff
testl %eax, %eax
jne 0xa33b
movsd (%rsp), %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0xa33b
leaq 0x80cf0(%rip), %rdi     # 0x8b026
callq 0x4359c
testb %r12b, %r12b
je 0xa35c
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x5dba4
leaq 0x80cf4(%rip), %rdi     # 0x8b047
movl %eax, %esi
xorl %eax, %eax
callq 0x36050
movq %rbx, %rdi
callq 0x5dafc
movq %rax, %r12
testq %rax, %rax
jne 0xa22b
movl 0xc45ca(%rip), %edi     # 0xce940
testl %edi, %edi
js 0xa37f
callq 0x4d95a
movl 0xc45bf(%rip), %eax     # 0xce944
testl %eax, %eax
js 0xa398
shlb $0x4, %al
orb $0x6, %al
leaq 0xc45e3(%rip), %rcx     # 0xce978
movb %al, 0x7(%rcx)
cmpl $0x0, 0xc45a9(%rip)     # 0xce948
js 0xa3ac
leaq 0xc45d0(%rip), %rax     # 0xce978
setne 0x2(%rax)
cmpl $0x0, 0xc4599(%rip)     # 0xce94c
je 0xa3cf
jle 0xa3e5
leaq 0xc45ba(%rip), %rax     # 0xce978
movb 0x3(%rax), %al
orb $0x1, %al
jmp 0xa3db
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xa44f
leaq 0xc45a2(%rip), %rax     # 0xce978
movb 0x3(%rax), %al
andb $-0x2, %al
leaq 0xc4596(%rip), %rcx     # 0xce978
movb %al, 0x3(%rcx)
cmpl $0x0, 0xc4564(%rip)     # 0xce950
je 0xa3fe
jle 0xa414
leaq 0xc4581(%rip), %rax     # 0xce978
movb 0x3(%rax), %al
orb $0x2, %al
jmp 0xa40a
leaq 0xc4573(%rip), %rax     # 0xce978
movb 0x3(%rax), %al
andb $-0x3, %al
leaq 0xc4567(%rip), %rcx     # 0xce978
movb %al, 0x3(%rcx)
leaq 0xc4565(%rip), %rax     # 0xce980
movl 0x4c(%rax), %edi
callq 0x5c4bf
leaq 0xc4676(%rip), %rax     # 0xceaa0
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 0x5e3ec
callq 0x5e55c
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq