	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_PERMacJoyScan                  ## -- Begin function PERMacJoyScan
	.p2align	4, 0x90
_PERMacJoyScan:                         ## @PERMacJoyScan
	.cfi_startproc
## %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	pushq	%rax
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	_joycount@GOTPCREL(%rip), %r15
	cmpl	$0, (%r15)
	jle	LBB0_31
## %bb.1:
	xorl	%r13d, %r13d
	movq	_joys@GOTPCREL(%rip), %rbx
LBB0_2:                                 ## =>This Loop Header: Depth=1
                                        ##     Child Loop BB0_5 Depth 2
                                        ##     Child Loop BB0_14 Depth 2
                                        ##     Child Loop BB0_21 Depth 2
                                        ##       Child Loop BB0_24 Depth 3
                                        ##       Child Loop BB0_26 Depth 3
	movq	(%rbx), %rax
	movq	(%rax,%r13,8), %r14
	testq	%r14, %r14
	je	LBB0_30
## %bb.3:                               ##   in Loop: Header=BB0_2 Depth=1
	cmpl	$0, (%r14)
	jle	LBB0_12
## %bb.4:                               ##   in Loop: Header=BB0_2 Depth=1
	xorl	%ebx, %ebx
	jmp	LBB0_5
	.p2align	4, 0x90
LBB0_11:                                ##   in Loop: Header=BB0_5 Depth=2
	incq	%rbx
	movslq	(%r14), %rax
	cmpq	%rax, %rbx
	jge	LBB0_12
LBB0_5:                                 ##   Parent Loop BB0_2 Depth=1
                                        ## =>  This Inner Loop Header: Depth=2
	movq	32(%r14), %rax
	movl	(%rax,%rbx,8), %edi
	movl	4(%rax,%rbx,8), %esi
	callq	_MIDDLE
	movl	%eax, %r15d
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_joy_read_axis
	movl	%eax, %r12d
	movq	32(%r14), %rax
	movl	4(%rax,%rbx,8), %esi
	testl	%esi, %esi
	jle	LBB0_8
## %bb.6:                               ##   in Loop: Header=BB0_5 Depth=2
	movl	%r15d, %edi
	callq	_MIDDLE
	cmpl	%eax, %r12d
	jg	LBB0_16
## %bb.7:                               ##   in Loop: Header=BB0_5 Depth=2
	movq	32(%r14), %rax
LBB0_8:                                 ##   in Loop: Header=BB0_5 Depth=2
	movl	(%rax,%rbx,8), %esi
	testl	%esi, %esi
	jns	LBB0_11
## %bb.9:                               ##   in Loop: Header=BB0_5 Depth=2
	movl	%r15d, %edi
	callq	_MIDDLE
	cmpl	%eax, %r12d
	jge	LBB0_11
	jmp	LBB0_10
	.p2align	4, 0x90
LBB0_12:                                ##   in Loop: Header=BB0_2 Depth=1
	cmpl	$0, 4(%r14)
	movq	_joycount@GOTPCREL(%rip), %r15
	jle	LBB0_19
## %bb.13:                              ##   in Loop: Header=BB0_2 Depth=1
	movl	$1, %ebx
	.p2align	4, 0x90
LBB0_14:                                ##   Parent Loop BB0_2 Depth=1
                                        ## =>  This Inner Loop Header: Depth=2
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_joy_read_button
	movq	24(%r14), %rcx
	cmpl	(%rcx,%rbx,4), %eax
	jg	LBB0_15
## %bb.18:                              ##   in Loop: Header=BB0_14 Depth=2
	leaq	1(%rbx), %rax
	movslq	4(%r14), %rcx
	cmpq	%rcx, %rbx
	movq	%rax, %rbx
	jl	LBB0_14
LBB0_19:                                ##   in Loop: Header=BB0_2 Depth=1
	cmpl	$0, 8(%r14)
	movq	_joys@GOTPCREL(%rip), %rbx
	jle	LBB0_30
## %bb.20:                              ##   in Loop: Header=BB0_2 Depth=1
	movq	16(%r14), %r8
	xorl	%r12d, %r12d
	jmp	LBB0_21
	.p2align	4, 0x90
LBB0_29:                                ##   in Loop: Header=BB0_21 Depth=2
	incq	%r12
	movslq	8(%r14), %rax
	cmpq	%rax, %r12
	jge	LBB0_30
LBB0_21:                                ##   Parent Loop BB0_2 Depth=1
                                        ## =>  This Loop Header: Depth=2
                                        ##       Child Loop BB0_24 Depth 3
                                        ##       Child Loop BB0_26 Depth 3
	leaq	(%r8,%r12,8), %rsi
	movq	%r14, %rdi
	callq	_joy_read_element
	movq	16(%r14), %r8
	movl	(%r8,%r12,8), %edx
	movl	4(%r8,%r12,8), %esi
	cmpl	%esi, %edx
	jge	LBB0_29
## %bb.22:                              ##   in Loop: Header=BB0_21 Depth=2
	movl	%edx, %ecx
	notl	%ecx
	addl	%esi, %ecx
	movl	%eax, %edi
	subl	%edx, %edi
	cmpl	%edi, %ecx
	cmovbl	%ecx, %edi
	incl	%edi
	cmpl	$17, %edi
	jb	LBB0_26
## %bb.23:                              ##   in Loop: Header=BB0_21 Depth=2
	movl	%edi, %ecx
	andl	$15, %ecx
	movl	$16, %ebx
	cmovel	%ebx, %ecx
	subl	%ecx, %edi
	addl	%edi, %edx
	.p2align	4, 0x90
LBB0_24:                                ##   Parent Loop BB0_2 Depth=1
                                        ##     Parent Loop BB0_21 Depth=2
                                        ## =>    This Inner Loop Header: Depth=3
	addl	$-16, %edi
	jne	LBB0_24
## %bb.25:                              ##   in Loop: Header=BB0_21 Depth=2
	movq	_joys@GOTPCREL(%rip), %rbx
	.p2align	4, 0x90
LBB0_26:                                ##   Parent Loop BB0_2 Depth=1
                                        ##     Parent Loop BB0_21 Depth=2
                                        ## =>    This Inner Loop Header: Depth=3
	cmpl	%edx, %eax
	je	LBB0_27
## %bb.28:                              ##   in Loop: Header=BB0_26 Depth=3
	incl	%edx
	cmpl	%edx, %esi
	jne	LBB0_26
	jmp	LBB0_29
	.p2align	4, 0x90
LBB0_30:                                ##   in Loop: Header=BB0_2 Depth=1
	incq	%r13
	movslq	(%r15), %rax
	cmpq	%rax, %r13
	jl	LBB0_2
LBB0_31:
	xorl	%ebx, %ebx
	jmp	LBB0_32
LBB0_27:
	shll	$24, %r13d
	movq	_HAT_VALUE@GOTPCREL(%rip), %rcx
	shll	$8, %eax
	orl	%r12d, %r13d
	orl	%eax, %r13d
	orl	(%rcx), %r13d
	movl	%r13d, %ebx
	jmp	LBB0_32
LBB0_15:
	shll	$24, %r13d
	orl	%r13d, %ebx
	jmp	LBB0_32
LBB0_16:
	shll	$24, %r13d
	movq	_AXIS_POSITIVE_VALUE@GOTPCREL(%rip), %rax
	jmp	LBB0_17
LBB0_10:
	shll	$24, %r13d
	movq	_AXIS_NEGATIVE_VALUE@GOTPCREL(%rip), %rax
LBB0_17:
	orl	%r13d, %ebx
	orl	(%rax), %ebx
LBB0_32:
	movl	%ebx, %eax
	addq	$8, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.comm	_joycount,4,2                   ## @joycount
	.comm	_joys,8,3                       ## @joys
	.comm	_AXIS_POSITIVE_VALUE,4,2        ## @AXIS_POSITIVE_VALUE
	.comm	_AXIS_NEGATIVE_VALUE,4,2        ## @AXIS_NEGATIVE_VALUE
	.comm	_HAT_VALUE,4,2                  ## @HAT_VALUE
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_PERMacJoyScan                  ; -- Begin function PERMacJoyScan
	.p2align	2
_PERMacJoyScan:                         ; @PERMacJoyScan
	.cfi_startproc
; %bb.0:
	stp	x28, x27, [sp, #-96]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 96
	stp	x26, x25, [sp, #16]             ; 16-byte Folded Spill
	stp	x24, x23, [sp, #32]             ; 16-byte Folded Spill
	stp	x22, x21, [sp, #48]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #64]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #80]             ; 16-byte Folded Spill
	add	x29, sp, #80
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
	.cfi_offset w19, -24
	.cfi_offset w20, -32
	.cfi_offset w21, -40
	.cfi_offset w22, -48
	.cfi_offset w23, -56
	.cfi_offset w24, -64
	.cfi_offset w25, -72
	.cfi_offset w26, -80
	.cfi_offset w27, -88
	.cfi_offset w28, -96
Lloh0:
	adrp	x24, _joycount@GOTPAGE
Lloh1:
	ldr	x24, [x24, _joycount@GOTPAGEOFF]
	ldr	w8, [x24]
	cmp	w8, #1
	b.lt	LBB0_26
; %bb.1:
	mov	x23, #0
Lloh2:
	adrp	x25, _joys@GOTPAGE
Lloh3:
	ldr	x25, [x25, _joys@GOTPAGEOFF]
	mov	w26, #64
LBB0_2:                                 ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_6 Depth 2
                                        ;     Child Loop BB0_13 Depth 2
                                        ;     Child Loop BB0_18 Depth 2
                                        ;       Child Loop BB0_21 Depth 3
                                        ;       Child Loop BB0_23 Depth 3
	ldr	x8, [x25]
	ldr	x19, [x8, x23, lsl #3]
	cbz	x19, LBB0_25
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	ldr	w8, [x19]
	cmp	w8, #1
	b.lt	LBB0_11
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	mov	x27, #0
	mov	x20, #0
	b	LBB0_6
LBB0_5:                                 ;   in Loop: Header=BB0_6 Depth=2
	add	x20, x20, #1
	ldrsw	x8, [x19]
	add	x27, x27, #8
	cmp	x20, x8
	b.ge	LBB0_11
LBB0_6:                                 ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	ldr	x8, [x19, #32]
	add	x8, x8, x27
	ldp	w0, w1, [x8]
	bl	_MIDDLE
	mov	x21, x0
	mov	x0, x19
	mov	x1, x20
	bl	_joy_read_axis
	mov	x22, x0
	ldr	x8, [x19, #32]
	add	x9, x8, x27
	ldr	w1, [x9, #4]
	cmp	w1, #1
	b.lt	LBB0_9
; %bb.7:                                ;   in Loop: Header=BB0_6 Depth=2
	mov	x0, x21
	bl	_MIDDLE
	cmp	w22, w0
	b.gt	LBB0_29
; %bb.8:                                ;   in Loop: Header=BB0_6 Depth=2
	ldr	x8, [x19, #32]
LBB0_9:                                 ;   in Loop: Header=BB0_6 Depth=2
	ldr	w1, [x8, x27]
	tbz	w1, #31, LBB0_5
; %bb.10:                               ;   in Loop: Header=BB0_6 Depth=2
	mov	x0, x21
	bl	_MIDDLE
	cmp	w22, w0
	b.ge	LBB0_5
	b	LBB0_30
LBB0_11:                                ;   in Loop: Header=BB0_2 Depth=1
	ldr	w8, [x19, #4]
	cmp	w8, #1
	b.lt	LBB0_15
; %bb.12:                               ;   in Loop: Header=BB0_2 Depth=1
	mov	w20, #1
LBB0_13:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	mov	x0, x19
	mov	x1, x20
	bl	_joy_read_button
	ldr	x8, [x19, #24]
	ldr	w8, [x8, x20, lsl #2]
	cmp	w0, w8
	b.gt	LBB0_28
; %bb.14:                               ;   in Loop: Header=BB0_13 Depth=2
	add	x8, x20, #1
	ldrsw	x9, [x19, #4]
	cmp	x20, x9
	mov	x20, x8
	b.lt	LBB0_13
LBB0_15:                                ;   in Loop: Header=BB0_2 Depth=1
	ldr	w8, [x19, #8]
	cmp	w8, #1
	b.lt	LBB0_25
; %bb.16:                               ;   in Loop: Header=BB0_2 Depth=1
	mov	x20, #0
	ldr	x8, [x19, #16]
	b	LBB0_18
LBB0_17:                                ;   in Loop: Header=BB0_18 Depth=2
	add	x20, x20, #1
	ldrsw	x9, [x19, #8]
	cmp	x20, x9
	b.ge	LBB0_25
LBB0_18:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_21 Depth 3
                                        ;       Child Loop BB0_23 Depth 3
	lsl	x21, x20, #3
	add	x1, x8, x21
	mov	x0, x19
	bl	_joy_read_element
	ldr	x8, [x19, #16]
	add	x10, x8, x21
	ldp	w9, w10, [x10]
	cmp	w9, w10
	b.ge	LBB0_17
; %bb.19:                               ;   in Loop: Header=BB0_18 Depth=2
	mvn	w11, w9
	add	w11, w10, w11
	sub	w12, w0, w9
	cmp	w11, w12
	csel	w11, w11, w12, lo
	add	w11, w11, #1
	cmp	w11, #65
	b.lo	LBB0_22
; %bb.20:                               ;   in Loop: Header=BB0_18 Depth=2
	ands	w12, w11, #0x3f
	csel	w12, w26, w12, eq
	sub	w11, w11, w12
	add	w9, w9, w11
LBB0_21:                                ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_18 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	subs	w11, w11, #64
	b.ne	LBB0_21
LBB0_22:                                ;   in Loop: Header=BB0_18 Depth=2
	sub	w11, w0, w9
	sub	w9, w10, w9
LBB0_23:                                ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_18 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	cbz	w11, LBB0_27
; %bb.24:                               ;   in Loop: Header=BB0_23 Depth=3
	sub	w11, w11, #1
	subs	w9, w9, #1
	b.ne	LBB0_23
	b	LBB0_17
LBB0_25:                                ;   in Loop: Header=BB0_2 Depth=1
	add	x23, x23, #1
	ldrsw	x8, [x24]
	cmp	x23, x8
	b.lt	LBB0_2
LBB0_26:
	mov	w0, #0
	b	LBB0_33
LBB0_27:
Lloh4:
	adrp	x8, _HAT_VALUE@GOTPAGE
Lloh5:
	ldr	x8, [x8, _HAT_VALUE@GOTPAGEOFF]
Lloh6:
	ldr	w8, [x8]
	orr	w9, w20, w23, lsl #24
	orr	w9, w9, w0, lsl #8
	b	LBB0_32
LBB0_28:
	orr	w0, w20, w23, lsl #24
	b	LBB0_33
LBB0_29:
Lloh7:
	adrp	x8, _AXIS_POSITIVE_VALUE@GOTPAGE
Lloh8:
	ldr	x8, [x8, _AXIS_POSITIVE_VALUE@GOTPAGEOFF]
	b	LBB0_31
LBB0_30:
Lloh9:
	adrp	x8, _AXIS_NEGATIVE_VALUE@GOTPAGE
Lloh10:
	ldr	x8, [x8, _AXIS_NEGATIVE_VALUE@GOTPAGEOFF]
LBB0_31:
	ldr	w8, [x8]
	orr	w9, w20, w23, lsl #24
LBB0_32:
	orr	w0, w9, w8
LBB0_33:
	ldp	x29, x30, [sp, #80]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #64]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #48]             ; 16-byte Folded Reload
	ldp	x24, x23, [sp, #32]             ; 16-byte Folded Reload
	ldp	x26, x25, [sp, #16]             ; 16-byte Folded Reload
	ldp	x28, x27, [sp], #96             ; 16-byte Folded Reload
	ret
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpLdrGot	Lloh2, Lloh3
	.loh AdrpLdrGotLdr	Lloh4, Lloh5, Lloh6
	.loh AdrpLdrGot	Lloh7, Lloh8
	.loh AdrpLdrGot	Lloh9, Lloh10
	.cfi_endproc
                                        ; -- End function
	.comm	_joycount,4,2                   ; @joycount
	.comm	_joys,8,3                       ; @joys
	.comm	_AXIS_POSITIVE_VALUE,4,2        ; @AXIS_POSITIVE_VALUE
	.comm	_AXIS_NEGATIVE_VALUE,4,2        ; @AXIS_NEGATIVE_VALUE
	.comm	_HAT_VALUE,4,2                  ; @HAT_VALUE
.subsections_via_symbols
