// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8d1b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x96bc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9a95
callq 0x8d650
movq -0x18(%rbp), %rdi
callq 0x8c2a0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x96da
jmp 0x98df
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rcx
leaq 0x1101f4(%rip), %rax    # 0x1198e0
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x989c
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rcx
leaq 0x1101d4(%rip), %rax    # 0x1198e0
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x8b00
cmpl $0x0, %eax
jne 0x988c
movq -0x18(%rbp), %rdi
callq 0x8c390
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
leaq 0xce8e8(%rip), %rdi     # 0xd8024
callq 0x8b00
cmpl $0x0, %eax
jne 0x974f
movq -0x18(%rbp), %rdi
callq 0x8c2a0
movslq -0x24(%rbp), %rax
shlq $0x5, %rax
leaq 0x110182(%rip), %rcx    # 0x1198e0
movl 0x8(%rax,%rcx), %eax
movq %rax, -0x40(%rbp)
subq $0x3, %rax
ja 0x987e
movq -0x40(%rbp), %rax
leaq 0xce889(%rip), %rcx     # 0xd8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8c500
cmpl $0x0, %eax
je 0x97a2
jmp 0x988a
cmpl $0x0, -0x28(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %ecx
movslq -0x24(%rbp), %rdx
leaq 0x110127(%rip), %rax    # 0x1198e0
shlq $0x5, %rdx
addq %rdx, %rax
movq 0x10(%rax), %rax
movl %ecx, (%rax)
jmp 0x988a
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x8c500
cmpl $0x0, %eax
je 0x97e9
jmp 0x988a
movl -0x2c(%rbp), %ecx
movslq -0x24(%rbp), %rdx
leaq 0x1100e9(%rip), %rax    # 0x1198e0
shlq $0x5, %rdx
addq %rdx, %rax
movq 0x10(%rax), %rax
movl %ecx, (%rax)
jmp 0x988a
movl $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x8c6f0
cmpl $0x0, %eax
je 0x9824
jmp 0x988a
movl -0x30(%rbp), %ecx
movslq -0x24(%rbp), %rdx
leaq 0x1100ae(%rip), %rax    # 0x1198e0
shlq $0x5, %rdx
addq %rdx, %rax
movq 0x10(%rax), %rax
movl %ecx, (%rax)
jmp 0x988a
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8c720
cmpl $0x0, %eax
je 0x985d
jmp 0x988a
movsd -0x38(%rbp), %xmm0
movslq -0x24(%rbp), %rcx
leaq 0x110073(%rip), %rax    # 0x1198e0
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movsd %xmm0, (%rax)
jmp 0x988a
leaq 0xce7a1(%rip), %rdi     # 0xd8026
callq 0x650c0
jmp 0x989c
jmp 0x988e
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x96e1
movslq -0x24(%rbp), %rcx
leaq 0x110039(%rip), %rax    # 0x1198e0
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x98da
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x8c460
movl %eax, %esi
leaq 0xce779(%rip), %rdi     # 0xd8047
movb $0x0, %al
callq 0x52630
jmp 0x96c1
jmp 0x96c1
cmpl $0x0, 0x1105fa(%rip)    # 0x119ee0
jl 0x98f3
movl 0x1105f2(%rip), %edi    # 0x119ee0
callq 0x75100
cmpl $0x0, 0x1105ea(%rip)    # 0x119ee4
jl 0x9948
movl 0x1105e2(%rip), %eax    # 0x119ee4
andl $0xf, %eax
shll $0x4, %eax
movb %al, %cl
leaq 0x110607(%rip), %rax    # 0x119f18
movb %cl, 0x7(%rax)
leaq 0x1105fd(%rip), %rax    # 0x119f18
movzbl 0x7(%rax), %eax
orl $0x2, %eax
movb %al, %cl
leaq 0x1105ed(%rip), %rax    # 0x119f18
movb %cl, 0x7(%rax)
leaq 0x1105e3(%rip), %rax    # 0x119f18
movzbl 0x7(%rax), %eax
orl $0x4, %eax
movb %al, %cl
leaq 0x1105d3(%rip), %rax    # 0x119f18
movb %cl, 0x7(%rax)
cmpl $0x0, 0x110599(%rip)    # 0x119ee8
jl 0x9970
cmpl $0x0, 0x110590(%rip)    # 0x119ee8
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
leaq 0x1105ab(%rip), %rax    # 0x119f18
movb %cl, 0x2(%rax)
cmpl $0x0, 0x110575(%rip)    # 0x119eec
jne 0x9995
leaq 0x110598(%rip), %rax    # 0x119f18
movzbl 0x3(%rax), %eax
andl $-0x2, %eax
movb %al, %cl
leaq 0x110588(%rip), %rax    # 0x119f18
movb %cl, 0x3(%rax)
jmp 0x99ba
cmpl $0x0, 0x110550(%rip)    # 0x119eec
jle 0x99b8
leaq 0x110573(%rip), %rax    # 0x119f18
movzbl 0x3(%rax), %eax
orl $0x1, %eax
movb %al, %cl
leaq 0x110563(%rip), %rax    # 0x119f18
movb %cl, 0x3(%rax)
jmp 0x99ba
cmpl $0x0, 0x11052f(%rip)    # 0x119ef0
jne 0x99df
leaq 0x11054e(%rip), %rax    # 0x119f18
movzbl 0x3(%rax), %eax
andl $-0x3, %eax
movb %al, %cl
leaq 0x11053e(%rip), %rax    # 0x119f18
movb %cl, 0x3(%rax)
jmp 0x9a04
cmpl $0x0, 0x11050a(%rip)    # 0x119ef0
jle 0x9a02
leaq 0x110529(%rip), %rax    # 0x119f18
movzbl 0x3(%rax), %eax
orl $0x2, %eax
movb %al, %cl
leaq 0x110519(%rip), %rax    # 0x119f18
movb %cl, 0x3(%rax)
jmp 0x9a04
leaq 0x110515(%rip), %rax    # 0x119f20
movl 0x4c(%rax), %edi
callq 0x89f70
leaq 0x110626(%rip), %rax    # 0x11a040
cmpl $0x0, 0xc(%rax)
jle 0x9a2f
leaq 0x110619(%rip), %rax    # 0x11a040
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x9a36
xorl %eax, %eax
movl %eax, -0x44(%rbp)
jmp 0x9a36
movl -0x44(%rbp), %eax
cmpl $0xf, %eax
jge 0x9a69
leaq 0x1105fb(%rip), %rax    # 0x11a040
cmpl $0x0, 0xc(%rax)
jle 0x9a5a
leaq 0x1105ee(%rip), %rax    # 0x11a040
movl 0xc(%rax), %eax
movl %eax, -0x48(%rbp)
jmp 0x9a61
xorl %eax, %eax
movl %eax, -0x48(%rbp)
jmp 0x9a61
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x9a73
movl $0xf, %eax
movl %eax, -0x4c(%rbp)
jmp 0x9a73
movl -0x4c(%rbp), %ecx
leaq 0x1105c3(%rip), %rax    # 0x11a040
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rdi
callq 0x8d390
callq 0x8d650
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop