// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/sdlayer2.c
// Function: initinput
int initinput(void)
{
	int i;

	inputdevices = 1|2; // keyboard (1) and mouse (2)
	mouseacquired = 0;

	memset(keynames,0,sizeof(keynames));
	for (i=0; i<SDL_NUM_SCANCODES; i++) {
		if (!keytranslation[i].normal) continue;
		strncpy(keynames[ keytranslation[i].normal ], SDL_GetScancodeName(i), sizeof(keynames[i])-1);
	}

	if (!SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)) {
		int flen, fh;
		char *dbuf = NULL;
		SDL_RWops *rwops = NULL;

		// Load an available controller mappings file.
		fh = kopen4load("gamecontrollerdb.txt", 0);
		if (fh >= 0) {
			flen = kfilelength(fh);
			if (flen >= 0) {
				dbuf = (char *)malloc(flen + 1);
			}
		}
		if (dbuf) {
			flen = kread(fh, dbuf, flen);
			dbuf[flen+1] = 0;
			kclose(fh);
			if (flen >= 0) {
				rwops = SDL_RWFromConstMem(dbuf, flen);
			}
		}
		if (rwops) {
			i = SDL_GameControllerAddMappingsFromRW(rwops, 0);
			buildprintf("Added %d game controller mappings\n", i);
			free(dbuf);
			SDL_free(rwops);
		}

		// Enumerate game controllers.
		if (SDL_NumJoysticks() < 1) {
			buildputs("No game controllers found\n");
		} else {
			int numjoysticks = SDL_NumJoysticks();
			buildputs("Game controllers:\n");
			for (i = 0; i < numjoysticks; i++) {
				if (SDL_IsGameController(i)) {
					buildprintf("  - %s\n", SDL_GameControllerNameForIndex(i));
					if (!controller) {
						controller = SDL_GameControllerOpen(i);
					}
				}
			}
			if (controller) {
				buildprintf("Using controller %s\n", SDL_GameControllerName(controller));

				inputdevices |= 4;
				joynumaxes    = min(Barraylen(joyaxis), SDL_CONTROLLER_AXIS_MAX);
				joynumbuttons = SDL_CONTROLLER_BUTTON_MAX;
			} else {
				buildprintf("No controllers are usable\n");
			}
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x110062(%rip), %r12    # 0x17e0d0
movl $0x3, (%r12)
movb $0x0, 0x65f24b(%rip)    # 0x6cd2c8
leaq 0x65f35c(%rip), %rbx    # 0x6cd3e0
xorl %r14d, %r14d
movl $0x1800, %edx           # imm = 0x1800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x62f0
leaq 0x660b43(%rip), %r13    # 0x6cebe0
movzbl (%r13), %eax
testq %rax, %rax
je 0x6e0c7
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax,8), %r15
movl %r14d, %edi
callq 0x6690
movl $0x17, %edx
movq %r15, %rdi
movq %rax, %rsi
callq 0x6190
incq %r14
addq $0x2, %r13
cmpq $0x200, %r14            # imm = 0x200
jne 0x6e09d
movl $0x2000, %edi           # imm = 0x2000
callq 0x6500
testl %eax, %eax
je 0x6e0f6
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x107d3(%rip), %rdi     # 0x7e8d0
xorl %esi, %esi
callq 0x2043c
testl %eax, %eax
js 0x6e18d
movl %eax, %ebp
movl %eax, %edi
callq 0x209a1
testl %eax, %eax
js 0x6e18d
movl %eax, %r14d
leal 0x1(%r14), %edi
callq 0x69a0
testq %rax, %rax
je 0x6e18d
movq %rax, %rbx
movl %ebp, %edi
movq %rax, %rsi
movl %r14d, %edx
callq 0x20684
movl %eax, %r14d
cltq
movb $0x0, 0x1(%rbx,%rax)
movl %ebp, %edi
callq 0x20b40
testl %r14d, %r14d
js 0x6e18d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6bd0
testq %rax, %rax
je 0x6e18d
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x64d0
leaq 0x10771(%rip), %rdi     # 0x7e8e5
movl %eax, %esi
xorl %eax, %eax
callq 0x25221
movq %rbx, %rdi
callq 0x61c0
movq %r14, %rdi
callq 0x6cd0
callq 0x65b0
testl %eax, %eax
jle 0x6e237
callq 0x65b0
movl %eax, %ebx
leaq 0x1077b(%rip), %rdi     # 0x7e923
callq 0x32d18
testl %ebx, %ebx
jle 0x6e1f7
leaq 0x1077e(%rip), %r14     # 0x7e936
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x6c20
testl %eax, %eax
je 0x6e1f1
movl %ebp, %edi
callq 0x6070
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x25221
cmpq $0x0, 0x660dff(%rip)    # 0x6cefe0
jne 0x6e1f1
movl %ebp, %edi
callq 0x67e0
movq %rax, 0x660def(%rip)    # 0x6cefe0
incl %ebp
cmpl %ebp, %ebx
jne 0x6e1ba
movq 0x660de2(%rip), %rdi    # 0x6cefe0
testq %rdi, %rdi
je 0x6e248
callq 0x6b20
leaq 0x1072f(%rip), %rdi     # 0x7e93e
movq %rax, %rsi
xorl %eax, %eax
callq 0x25221
orb $0x4, (%r12)
leaq 0x10febf(%rip), %rax    # 0x17e0e4
movb $0x6, (%rax)
leaq 0x10feb6(%rip), %rax    # 0x17e0e5
movb $0x15, (%rax)
jmp 0x6e0e5
leaq 0x106ca(%rip), %rdi     # 0x7e908
callq 0x32d18
jmp 0x6e0e5
leaq 0x10704(%rip), %rdi     # 0x7e953
xorl %eax, %eax
callq 0x25221
jmp 0x6e0e5