// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
leaq 0x115b01(%rip), %rax    # 0x1bac30
movl $0x3, (%rax)
movb $0x0, 0x61b16c(%rip)    # 0x6c02a8
leaq 0x61b26d(%rip), %rdi    # 0x6c03b0
xorl %esi, %esi
movl $0x1800, %edx           # imm = 0x1800
callq 0x62d0
movl $0x0, -0x4(%rbp)
cmpl $0x200, -0x4(%rbp)      # imm = 0x200
jge 0xa51b9
movslq -0x4(%rbp), %rcx
leaq 0x61ca46(%rip), %rax    # 0x6c1bb0
cmpb $0x0, (%rax,%rcx,2)
jne 0xa5172
jmp 0xa51ae
movslq -0x4(%rbp), %rcx
leaq 0x61ca33(%rip), %rax    # 0x6c1bb0
movzbl (%rax,%rcx,2), %eax
movl %eax, %ecx
leaq 0x61b226(%rip), %rax    # 0x6c03b0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x4(%rbp), %edi
callq 0x6620
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movl $0x17, %edx
callq 0x6180
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xa5156
movl $0x2000, %edi           # imm = 0x2000
callq 0x64a0
cmpl $0x0, %eax
jne 0xa538a
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq 0x15545(%rip), %rdi     # 0xba728
xorl %esi, %esi
callq 0x2fee0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0xa5218
movl -0xc(%rbp), %edi
callq 0x30750
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jl 0xa5216
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x68f0
movq %rax, -0x18(%rbp)
jmp 0xa5218
cmpq $0x0, -0x18(%rbp)
je 0xa5262
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rsi
movl -0x8(%rbp), %edx
callq 0x302b0
movl %eax, -0x8(%rbp)
movq -0x18(%rbp), %rax
movl -0x8(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0xc(%rbp), %edi
callq 0x30960
cmpl $0x0, -0x8(%rbp)
jl 0xa5260
movq -0x18(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x6b00
movq %rax, -0x20(%rbp)
jmp 0xa5262
cmpq $0x0, -0x20(%rbp)
je 0xa529a
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x6470
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %esi
leaq 0x154bc(%rip), %rdi     # 0xba73d
movb $0x0, %al
callq 0x37c90
movq -0x18(%rbp), %rdi
callq 0x61c0
movq -0x20(%rbp), %rdi
callq 0x6c00
callq 0x6550
cmpl $0x1, %eax
jge 0xa52b5
leaq 0x154b5(%rip), %rdi     # 0xba760
callq 0x4a720
jmp 0xa5388
callq 0x6550
movl %eax, -0x24(%rbp)
leaq 0x154b7(%rip), %rdi     # 0xba77b
callq 0x4a720
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xa5326
movl -0x4(%rbp), %edi
callq 0x6b50
cmpl $0x0, %eax
je 0xa5319
movl -0x4(%rbp), %edi
callq 0x6070
movq %rax, %rsi
leaq 0x15497(%rip), %rdi     # 0xba78e
movb $0x0, %al
callq 0x37c90
cmpq $0x0, 0x61ccaa(%rip)    # 0x6c1fb0
jne 0xa5317
movl -0x4(%rbp), %edi
callq 0x6730
movq %rax, 0x61cc99(%rip)    # 0x6c1fb0
jmp 0xa5319
jmp 0xa531b
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xa52d0
cmpq $0x0, 0x61cc82(%rip)    # 0x6c1fb0
je 0xa5378
movq 0x61cc79(%rip), %rdi    # 0x6c1fb0
callq 0x6a40
movq %rax, %rsi
leaq 0x15450(%rip), %rdi     # 0xba796
movb $0x0, %al
callq 0x37c90
leaq 0x1158dc(%rip), %rax    # 0x1bac30
movl (%rax), %ecx
orl $0x4, %ecx
leaq 0x1158d0(%rip), %rax    # 0x1bac30
movl %ecx, (%rax)
leaq 0x1158db(%rip), %rax    # 0x1bac44
movb $0x6, (%rax)
leaq 0x1158d2(%rip), %rax    # 0x1bac45
movb $0x15, (%rax)
jmp 0xa5386
leaq 0x1542c(%rip), %rdi     # 0xba7ab
movb $0x0, %al
callq 0x37c90
jmp 0xa5388
jmp 0xa538a
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)