// File: /workspace/github_c_makefile_star2_O1/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 0x110d9e(%rip), %r12    # 0x17d0d0
movl $0x3, (%r12)
movb $0x0, 0x65ff97(%rip)    # 0x6cc2d8
leaq 0x6600a8(%rip), %rbx    # 0x6cc3f0
xorl %r14d, %r14d
movl $0x1800, %edx           # imm = 0x1800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x62f0
leaq 0x66188f(%rip), %r13    # 0x6cdbf0
movzbl (%r13), %eax
testq %rax, %rax
je 0x6c38b
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 0x6c361
movl $0x2000, %edi           # imm = 0x2000
callq 0x6500
testl %eax, %eax
je 0x6c3ba
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1106f(%rip), %rdi     # 0x7d430
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1ff50
movl %eax, %ebp
testl %eax, %eax
js 0x6c3ed
movl %ebp, %edi
callq 0x204d2
movl %eax, %r14d
testl %eax, %eax
js 0x6c3ef
movl %r14d, %edi
incl %edi
callq 0x69a0
movq %rax, %rbx
jmp 0x6c3f1
jmp 0x6c3f1
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x6c429
movl %ebp, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x201c2
movl %eax, %r14d
cltq
movb $0x0, 0x1(%rax,%rbx)
movl %ebp, %edi
callq 0x20671
testl %r14d, %r14d
js 0x6c429
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6bd0
movq %rax, %r14
jmp 0x6c42c
xorl %r14d, %r14d
testq %r14, %r14
je 0x6c45b
movq %r14, %rdi
xorl %esi, %esi
callq 0x64d0
leaq 0x11003(%rip), %rdi     # 0x7d445
movl %eax, %esi
xorl %eax, %eax
callq 0x24cb4
movq %rbx, %rdi
callq 0x61c0
movq %r14, %rdi
callq 0x6cd0
callq 0x65b0
testl %eax, %eax
jle 0x6c505
callq 0x65b0
movl %eax, %ebx
leaq 0x1100d(%rip), %rdi     # 0x7d483
callq 0x32200
testl %ebx, %ebx
jle 0x6c4c5
leaq 0x11010(%rip), %r14     # 0x7d496
xorl %ebp, %ebp
movl %ebp, %edi
callq 0x6c20
testl %eax, %eax
je 0x6c4bf
movl %ebp, %edi
callq 0x6070
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x24cb4
cmpq $0x0, 0x661b41(%rip)    # 0x6cdff0
jne 0x6c4bf
movl %ebp, %edi
callq 0x67e0
movq %rax, 0x661b31(%rip)    # 0x6cdff0
incl %ebp
cmpl %ebp, %ebx
jne 0x6c488
movq 0x661b24(%rip), %rdi    # 0x6cdff0
testq %rdi, %rdi
je 0x6c516
callq 0x6b20
leaq 0x10fc1(%rip), %rdi     # 0x7d49e
movq %rax, %rsi
xorl %eax, %eax
callq 0x24cb4
orb $0x4, (%r12)
leaq 0x110bf1(%rip), %rax    # 0x17d0e4
movb $0x6, (%rax)
leaq 0x110be8(%rip), %rax    # 0x17d0e5
movb $0x15, (%rax)
jmp 0x6c3a9
leaq 0x10f5c(%rip), %rdi     # 0x7d468
callq 0x32200
jmp 0x6c3a9
leaq 0x10f96(%rip), %rdi     # 0x7d4b3
xorl %eax, %eax
callq 0x24cb4
jmp 0x6c3a9