// File: /workspace/github_c_makefile_star2_O2/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 0x1147ba(%rip), %r13    # 0x1770d0
movl $0x3, (%r13)
movb $0x0, 0x6639a3(%rip)    # 0x6c62c8
leaq 0x663ab4(%rip), %rbx    # 0x6c63e0
xorl %r14d, %r14d
movl $0x1800, %edx           # imm = 0x1800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x62f0
leaq 0x66529b(%rip), %rbp    # 0x6c7be0
pushq $0x17
popq %r15
cmpq $0x200, %r14            # imm = 0x200
je 0x62981
movzbl (%rbp), %eax
testq %rax, %rax
je 0x62978
imulq $0x18, %rax, %r12
addq %rbx, %r12
movl %r14d, %edi
callq 0x6690
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x6190
incq %r14
addq $0x2, %rbp
jmp 0x62949
movl $0x2000, %edi           # imm = 0x2000
callq 0x6500
testl %eax, %eax
je 0x629a0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10d89(%rip), %rdi     # 0x73730
xorl %esi, %esi
callq 0x1dc36
testl %eax, %eax
js 0x62a37
movl %eax, %ebp
movl %eax, %edi
callq 0x1e14c
testl %eax, %eax
js 0x62a37
movl %eax, %r14d
leal 0x1(%r14), %edi
callq 0x69a0
testq %rax, %rax
je 0x62a37
movq %rax, %rbx
movl %ebp, %edi
movq %rax, %rsi
movl %r14d, %edx
callq 0x1de3f
movl %eax, %r14d
cltq
movb $0x0, 0x1(%rbx,%rax)
movl %ebp, %edi
callq 0x1e2db
testl %r14d, %r14d
js 0x62a37
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6bd0
testq %rax, %rax
je 0x62a37
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x64d0
leaq 0x10d27(%rip), %rdi     # 0x73745
movl %eax, %esi
xorl %eax, %eax
callq 0x22427
movq %rbx, %rdi
callq 0x61c0
movq %r14, %rdi
callq 0x6cd0
callq 0x65b0
testl %eax, %eax
jle 0x62ae6
callq 0x65b0
movl %eax, %ebx
leaq 0x10d31(%rip), %rdi     # 0x73783
callq 0x30c8d
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
leaq 0x10d31(%rip), %r14     # 0x73796
xorl %ebp, %ebp
cmpl %ebp, %ebx
je 0x62aa6
movl %ebp, %edi
callq 0x6c20
testl %eax, %eax
je 0x62aa2
movl %ebp, %edi
callq 0x6070
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x22427
cmpq $0x0, 0x66554e(%rip)    # 0x6c7fe0
jne 0x62aa2
movl %ebp, %edi
callq 0x67e0
movq %rax, 0x66553e(%rip)    # 0x6c7fe0
incl %ebp
jmp 0x62a67
movq 0x665533(%rip), %rdi    # 0x6c7fe0
testq %rdi, %rdi
je 0x62af7
callq 0x6b20
leaq 0x10ce0(%rip), %rdi     # 0x7379e
movq %rax, %rsi
xorl %eax, %eax
callq 0x22427
orb $0x4, (%r13)
leaq 0x114610(%rip), %rax    # 0x1770e4
movb $0x6, (%rax)
leaq 0x114607(%rip), %rax    # 0x1770e5
movb $0x15, (%rax)
jmp 0x6298f
leaq 0x10c7b(%rip), %rdi     # 0x73768
callq 0x30c8d
jmp 0x6298f
leaq 0x10cb5(%rip), %rdi     # 0x737b3
xorl %eax, %eax
callq 0x22427
jmp 0x6298f