	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function arm_ccn_pmu_event_alloc
_arm_ccn_pmu_event_alloc:               ## @arm_ccn_pmu_event_alloc
	.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	%rdi, %r13
	movl	24(%rdi), %edi
	callq	_pmu_to_arm_ccn
	movq	%rax, %r14
	movl	(%r13), %edi
	callq	_CCN_CONFIG_NODE
	movq	%rax, %r15
	movl	(%r13), %edi
	callq	_CCN_CONFIG_TYPE
	movq	%rax, %rbx
	movl	(%r13), %edi
	callq	_CCN_CONFIG_EVENT
	movq	%rax, %r12
	movq	_CCN_TYPE_CYCLES@GOTPCREL(%rip), %rax
	cmpq	(%rax), %rbx
	jne	LBB0_3
## %bb.1:
	movq	_CCN_IDX_PMU_CYCLE_COUNTER@GOTPCREL(%rip), %rbx
	movq	(%rbx), %rdi
	movl	8(%r14), %esi
	callq	_test_and_set_bit
	testq	%rax, %rax
	je	LBB0_5
## %bb.2:
	movq	_EAGAIN@GOTPCREL(%rip), %rax
	xorl	%ebx, %ebx
	jmp	LBB0_8
LBB0_3:
	movl	8(%r14), %edi
	movq	_CCN_NUM_PMU_EVENT_COUNTERS@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	callq	_arm_ccn_pmu_alloc_bit
	movq	%rax, 8(%r13)
	movq	_CCN_TYPE_XP@GOTPCREL(%rip), %rcx
	xorl	%edx, %edx
	cmpq	(%rcx), %rbx
	sete	%dl
	movq	24(%r14,%rdx,8), %rcx
	leaq	(%rcx,%r15,8), %rsi
	movq	(%r14), %rdi
	shlq	$4, %rax
	movq	%rsi, 8(%rdi,%rax)
	movq	_CCN_EVENT_WATCHPOINT@GOTPCREL(%rip), %rax
	cmpq	(%rax), %r12
	sete	%al
	leaq	(%rcx,%r15,8), %rcx
	addq	$4, %rcx
	testb	%al, %dl
	cmoveq	%rsi, %rcx
	movl	(%rcx), %edi
	movq	_CCN_NUM_PMU_EVENTS@GOTPCREL(%rip), %rax
	cmovneq	_CCN_NUM_XP_WATCHPOINTS@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	callq	_arm_ccn_pmu_alloc_bit
	testl	%eax, %eax
	js	LBB0_7
## %bb.4:
	movl	%eax, 16(%r13)
	movq	(%r14), %rax
	movq	8(%r13), %rcx
	shlq	$4, %rcx
	movq	%r13, (%rax,%rcx)
	jmp	LBB0_6
LBB0_5:
	movq	(%rbx), %rax
	movq	%rax, 8(%r13)
	movq	(%r14), %rcx
	shlq	$4, %rax
	movq	%r13, (%rcx,%rax)
LBB0_6:
	xorl	%ebx, %ebx
	jmp	LBB0_9
LBB0_7:
	movl	16(%r14), %edi
	leaq	L_.str.1(%rip), %rsi
	xorl	%ebx, %ebx
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	_dev_dbg
	movq	8(%r13), %rdi
	movl	8(%r14), %esi
	callq	_clear_bit
	movq	_EAGAIN@GOTPCREL(%rip), %rax
LBB0_8:
	subl	(%rax), %ebx
LBB0_9:
	movl	%ebx, %eax
	addq	$8, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.comm	_CCN_TYPE_CYCLES,8,3            ## @CCN_TYPE_CYCLES
	.comm	_CCN_IDX_PMU_CYCLE_COUNTER,8,3  ## @CCN_IDX_PMU_CYCLE_COUNTER
	.comm	_EAGAIN,4,2                     ## @EAGAIN
	.comm	_CCN_NUM_PMU_EVENT_COUNTERS,4,2 ## @CCN_NUM_PMU_EVENT_COUNTERS
	.comm	_CCN_TYPE_XP,8,3                ## @CCN_TYPE_XP
	.comm	_CCN_EVENT_WATCHPOINT,8,3       ## @CCN_EVENT_WATCHPOINT
	.comm	_CCN_NUM_XP_WATCHPOINTS,4,2     ## @CCN_NUM_XP_WATCHPOINTS
	.comm	_CCN_NUM_PMU_EVENTS,4,2         ## @CCN_NUM_PMU_EVENTS
	.section	__TEXT,__cstring,cstring_literals
L_.str.1:                               ## @.str.1
	.asciz	"No more event sources/watchpoints on node/XP %d!\n"

	.no_dead_strip	_arm_ccn_pmu_event_alloc
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function arm_ccn_pmu_event_alloc
_arm_ccn_pmu_event_alloc:               ; @arm_ccn_pmu_event_alloc
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #80
	.cfi_def_cfa_offset 80
	stp	x24, x23, [sp, #16]             ; 16-byte Folded Spill
	stp	x22, x21, [sp, #32]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #48]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #64]             ; 16-byte Folded Spill
	add	x29, sp, #64
	.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
	mov	x19, x0
	ldr	w0, [x0, #24]
	bl	_pmu_to_arm_ccn
	mov	x20, x0
	ldr	w0, [x19]
	bl	_CCN_CONFIG_NODE
	mov	x21, x0
	ldr	w0, [x19]
	bl	_CCN_CONFIG_TYPE
	mov	x23, x0
	ldr	w0, [x19]
	bl	_CCN_CONFIG_EVENT
Lloh0:
	adrp	x8, _CCN_TYPE_CYCLES@GOTPAGE
Lloh1:
	ldr	x8, [x8, _CCN_TYPE_CYCLES@GOTPAGEOFF]
Lloh2:
	ldr	x8, [x8]
	cmp	x23, x8
	b.ne	LBB0_3
; %bb.1:
Lloh3:
	adrp	x21, _CCN_IDX_PMU_CYCLE_COUNTER@GOTPAGE
Lloh4:
	ldr	x21, [x21, _CCN_IDX_PMU_CYCLE_COUNTER@GOTPAGEOFF]
	ldr	x0, [x21]
	ldr	w1, [x20, #8]
	bl	_test_and_set_bit
	cbnz	x0, LBB0_6
; %bb.2:
	ldr	x8, [x21]
	str	x8, [x19, #8]
	ldr	x9, [x20]
	lsl	x8, x8, #4
	str	x19, [x9, x8]
	b	LBB0_7
LBB0_3:
	mov	x22, x0
	ldr	w0, [x20, #8]
Lloh5:
	adrp	x8, _CCN_NUM_PMU_EVENT_COUNTERS@GOTPAGE
Lloh6:
	ldr	x8, [x8, _CCN_NUM_PMU_EVENT_COUNTERS@GOTPAGEOFF]
Lloh7:
	ldr	w1, [x8]
	bl	_arm_ccn_pmu_alloc_bit
	str	x0, [x19, #8]
Lloh8:
	adrp	x8, _CCN_TYPE_XP@GOTPAGE
Lloh9:
	ldr	x8, [x8, _CCN_TYPE_XP@GOTPAGEOFF]
Lloh10:
	ldr	x8, [x8]
	mov	w9, #24
	mov	w10, #32
	cmp	x23, x8
	csel	x8, x10, x9, eq
	cset	w9, eq
	ldr	x8, [x20, x8]
	add	x8, x8, x21, lsl #3
	ldr	x10, [x20]
	add	x10, x10, x0, lsl #4
	str	x8, [x10, #8]
Lloh11:
	adrp	x10, _CCN_EVENT_WATCHPOINT@GOTPAGE
Lloh12:
	ldr	x10, [x10, _CCN_EVENT_WATCHPOINT@GOTPAGEOFF]
Lloh13:
	ldr	x10, [x10]
	cmp	x22, x10
	cset	w10, eq
	add	x11, x8, #4
	tst	w9, w10
	csel	x8, x11, x8, ne
	ldr	w0, [x8]
Lloh14:
	adrp	x8, _CCN_NUM_XP_WATCHPOINTS@GOTPAGE
Lloh15:
	ldr	x8, [x8, _CCN_NUM_XP_WATCHPOINTS@GOTPAGEOFF]
Lloh16:
	adrp	x9, _CCN_NUM_PMU_EVENTS@GOTPAGE
Lloh17:
	ldr	x9, [x9, _CCN_NUM_PMU_EVENTS@GOTPAGEOFF]
	csel	x8, x8, x9, ne
	ldr	w1, [x8]
	bl	_arm_ccn_pmu_alloc_bit
	mov	x8, x0
	tbnz	w8, #31, LBB0_5
; %bb.4:
	mov	w0, #0
	str	w8, [x19, #16]
	ldr	x8, [x20]
	ldr	x9, [x19, #8]
	lsl	x9, x9, #4
	str	x19, [x8, x9]
	b	LBB0_7
LBB0_5:
	ldr	w0, [x20, #16]
	str	x21, [sp]
Lloh18:
	adrp	x1, l_.str.1@PAGE
Lloh19:
	add	x1, x1, l_.str.1@PAGEOFF
	bl	_dev_dbg
	ldr	x0, [x19, #8]
	ldr	w1, [x20, #8]
	bl	_clear_bit
LBB0_6:
Lloh20:
	adrp	x8, _EAGAIN@GOTPAGE
Lloh21:
	ldr	x8, [x8, _EAGAIN@GOTPAGEOFF]
Lloh22:
	ldr	w8, [x8]
	neg	w0, w8
LBB0_7:
	ldp	x29, x30, [sp, #64]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #48]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #32]             ; 16-byte Folded Reload
	ldp	x24, x23, [sp, #16]             ; 16-byte Folded Reload
	add	sp, sp, #80
	ret
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpLdrGot	Lloh3, Lloh4
	.loh AdrpLdrGot	Lloh16, Lloh17
	.loh AdrpLdrGot	Lloh14, Lloh15
	.loh AdrpLdrGotLdr	Lloh11, Lloh12, Lloh13
	.loh AdrpLdrGotLdr	Lloh8, Lloh9, Lloh10
	.loh AdrpLdrGotLdr	Lloh5, Lloh6, Lloh7
	.loh AdrpAdd	Lloh18, Lloh19
	.loh AdrpLdrGotLdr	Lloh20, Lloh21, Lloh22
	.cfi_endproc
                                        ; -- End function
	.comm	_CCN_TYPE_CYCLES,8,3            ; @CCN_TYPE_CYCLES
	.comm	_CCN_IDX_PMU_CYCLE_COUNTER,8,3  ; @CCN_IDX_PMU_CYCLE_COUNTER
	.comm	_EAGAIN,4,2                     ; @EAGAIN
	.comm	_CCN_NUM_PMU_EVENT_COUNTERS,4,2 ; @CCN_NUM_PMU_EVENT_COUNTERS
	.comm	_CCN_TYPE_XP,8,3                ; @CCN_TYPE_XP
	.comm	_CCN_EVENT_WATCHPOINT,8,3       ; @CCN_EVENT_WATCHPOINT
	.comm	_CCN_NUM_XP_WATCHPOINTS,4,2     ; @CCN_NUM_XP_WATCHPOINTS
	.comm	_CCN_NUM_PMU_EVENTS,4,2         ; @CCN_NUM_PMU_EVENTS
	.section	__TEXT,__cstring,cstring_literals
l_.str.1:                               ; @.str.1
	.asciz	"No more event sources/watchpoints on node/XP %d!\n"

	.no_dead_strip	_arm_ccn_pmu_event_alloc
.subsections_via_symbols
