	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function moxa_open
_moxa_open:                             ## @moxa_open
	.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
	movl	(%rdi), %ebx
	movq	_MAX_PORTS@GOTPCREL(%rip), %rax
	cmpl	(%rax), %ebx
	jne	LBB0_2
## %bb.1:
	movq	_CAP_SYS_ADMIN@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	callq	_capable
	movq	_EPERM@GOTPCREL(%rip), %rcx
	xorl	%ebx, %ebx
	subl	(%rcx), %ebx
	xorl	%ecx, %ecx
	testq	%rax, %rax
	cmovnel	%ecx, %ebx
	jmp	LBB0_19
LBB0_2:
	movq	%rsi, %r14
	movq	%rdi, %r13
	movq	_moxa_openlock@GOTPCREL(%rip), %rdi
	callq	_mutex_lock_interruptible
	testq	%rax, %rax
	je	LBB0_5
## %bb.3:
	movq	_ERESTARTSYS@GOTPCREL(%rip), %rax
	jmp	LBB0_4
LBB0_5:
	movq	_moxa_boards@GOTPCREL(%rip), %rax
	movq	(%rax), %rcx
	movq	_MAX_PORTS_PER_BOARD@GOTPCREL(%rip), %rsi
	movl	%ebx, %eax
	cltd
	idivl	(%rsi)
	cltq
	leaq	(%rax,%rax,2), %rax
	cmpl	$0, 16(%rcx,%rax,8)
	je	LBB0_6
## %bb.7:
	cmpl	(%rcx,%rax,8), %edx
	jge	LBB0_6
## %bb.8:
	movq	8(%rcx,%rax,8), %rbx
	movslq	%edx, %r15
	shlq	$5, %r15
	leaq	(%rbx,%r15), %r12
	leaq	(%rbx,%r15), %rdi
	addq	$8, %rdi
	incq	8(%rbx,%r15)
	movq	%r12, 8(%r13)
	movq	%rdi, -48(%rbp)                 ## 8-byte Spill
	movq	%r13, %rsi
	callq	_tty_port_tty_set
	movq	_ASYNC_INITIALIZED@GOTPCREL(%rip), %rcx
	movl	(%rcx), %eax
	testl	%eax, 16(%rbx,%r15)
	jne	LBB0_10
## %bb.9:
	movq	$0, 24(%rbx,%r15)
	movl	4(%r13), %esi
	movq	%r13, %rdi
	movq	%rcx, %rbx
	callq	_moxa_set_tty_param
	movq	%r12, %rdi
	movl	$1, %esi
	movl	$1, %edx
	callq	_MoxaPortLineCtrl
	movq	%r12, %rdi
	callq	_MoxaPortEnable
	movq	(%r12), %rax
	movq	_PORT_16550A@GOTPCREL(%rip), %rcx
	xorl	%esi, %esi
	cmpq	(%rcx), %rax
	sete	%sil
	movq	%r12, %rdi
	callq	_MoxaSetFifo
	movl	(%rbx), %eax
	movq	-48(%rbp), %rcx                 ## 8-byte Reload
	orl	%eax, 8(%rcx)
LBB0_10:
	movq	_moxa_openlock@GOTPCREL(%rip), %rdi
	callq	_mutex_unlock
	movq	_O_NONBLOCK@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	testl	%eax, (%r14)
	jne	LBB0_12
## %bb.11:
	movq	%r13, %rdi
	callq	_C_CLOCAL
	testl	%eax, %eax
	je	LBB0_14
LBB0_12:
	movq	_moxa_openlock@GOTPCREL(%rip), %rdi
	callq	_mutex_lock
	movq	-48(%rbp), %rcx                 ## 8-byte Reload
LBB0_13:
	movq	_ASYNC_NORMAL_ACTIVE@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	orl	%eax, 8(%rcx)
	xorl	%ebx, %ebx
LBB0_18:
	movq	_moxa_openlock@GOTPCREL(%rip), %rdi
	callq	_mutex_unlock
	jmp	LBB0_19
LBB0_6:
	movq	_moxa_openlock@GOTPCREL(%rip), %rdi
	callq	_mutex_unlock
	movq	_ENODEV@GOTPCREL(%rip), %rax
LBB0_4:
	xorl	%ebx, %ebx
	subl	(%rax), %ebx
LBB0_19:
	movl	%ebx, %eax
	addq	$8, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_14:
	movq	%r13, %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	callq	_moxa_block_till_ready
	movl	%eax, %ebx
	movq	_moxa_openlock@GOTPCREL(%rip), %rdi
	callq	_mutex_lock
	testl	%ebx, %ebx
	movq	-48(%rbp), %rcx                 ## 8-byte Reload
	je	LBB0_13
## %bb.15:
	movq	(%rcx), %rax
	testq	%rax, %rax
	je	LBB0_18
## %bb.16:
	decq	%rax
	movq	%rax, (%rcx)
	jne	LBB0_18
## %bb.17:
	movq	%r13, %rdi
	callq	_moxa_close_port
	jmp	LBB0_18
	.cfi_endproc
                                        ## -- End function
	.comm	_MAX_PORTS,4,2                  ## @MAX_PORTS
	.comm	_CAP_SYS_ADMIN,4,2              ## @CAP_SYS_ADMIN
	.comm	_EPERM,4,2                      ## @EPERM
	.comm	_moxa_openlock,4,2              ## @moxa_openlock
	.comm	_ERESTARTSYS,4,2                ## @ERESTARTSYS
	.comm	_moxa_boards,8,3                ## @moxa_boards
	.comm	_MAX_PORTS_PER_BOARD,4,2        ## @MAX_PORTS_PER_BOARD
	.comm	_ENODEV,4,2                     ## @ENODEV
	.comm	_ASYNC_INITIALIZED,4,2          ## @ASYNC_INITIALIZED
	.comm	_PORT_16550A,8,3                ## @PORT_16550A
	.comm	_O_NONBLOCK,4,2                 ## @O_NONBLOCK
	.comm	_ASYNC_NORMAL_ACTIVE,4,2        ## @ASYNC_NORMAL_ACTIVE
	.no_dead_strip	_moxa_open
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function moxa_open
_moxa_open:                             ; @moxa_open
	.cfi_startproc
; %bb.0:
	stp	x24, x23, [sp, #-64]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 64
	stp	x22, x21, [sp, #16]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #32]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #48]             ; 16-byte Folded Spill
	add	x29, sp, #48
	.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
	ldr	w21, [x0]
Lloh0:
	adrp	x8, _MAX_PORTS@GOTPAGE
Lloh1:
	ldr	x8, [x8, _MAX_PORTS@GOTPAGEOFF]
Lloh2:
	ldr	w8, [x8]
	cmp	w21, w8
	b.ne	LBB0_2
; %bb.1:
Lloh3:
	adrp	x8, _CAP_SYS_ADMIN@GOTPAGE
Lloh4:
	ldr	x8, [x8, _CAP_SYS_ADMIN@GOTPAGEOFF]
Lloh5:
	ldr	w0, [x8]
	bl	_capable
Lloh6:
	adrp	x8, _EPERM@GOTPAGE
Lloh7:
	ldr	x8, [x8, _EPERM@GOTPAGEOFF]
Lloh8:
	ldr	w8, [x8]
	cmp	x0, #0
	csneg	w20, wzr, w8, ne
	b	LBB0_15
LBB0_2:
	mov	x20, x1
	mov	x19, x0
Lloh9:
	adrp	x0, _moxa_openlock@GOTPAGE
Lloh10:
	ldr	x0, [x0, _moxa_openlock@GOTPAGEOFF]
	bl	_mutex_lock_interruptible
	cbz	x0, LBB0_4
; %bb.3:
Lloh11:
	adrp	x8, _ERESTARTSYS@GOTPAGE
Lloh12:
	ldr	x8, [x8, _ERESTARTSYS@GOTPAGEOFF]
	b	LBB0_14
LBB0_4:
Lloh13:
	adrp	x8, _moxa_boards@GOTPAGE
Lloh14:
	ldr	x8, [x8, _moxa_boards@GOTPAGEOFF]
Lloh15:
	adrp	x9, _MAX_PORTS_PER_BOARD@GOTPAGE
Lloh16:
	ldr	x9, [x9, _MAX_PORTS_PER_BOARD@GOTPAGEOFF]
Lloh17:
	ldr	x8, [x8]
Lloh18:
	ldr	w10, [x9]
	sdiv	w9, w21, w10
	mov	w11, #24
	smaddl	x11, w9, w11, x8
	ldr	w11, [x11, #16]
	cbz	w11, LBB0_13
; %bb.5:
	sxtw	x9, w9
	msub	w10, w9, w10, w21
	mov	w11, #24
	mul	x11, x9, x11
	ldr	w11, [x8, x11]
	cmp	w10, w11
	b.ge	LBB0_13
; %bb.6:
	mov	w11, #24
	madd	x8, x9, x11, x8
	ldr	x8, [x8, #8]
	sxtw	x9, w10
	add	x22, x8, x9, lsl #5
	mov	x21, x22
	ldr	x8, [x21, #8]!
	add	x8, x8, #1
	str	x8, [x21]
	str	x22, [x19, #8]
	mov	x0, x21
	mov	x1, x19
	bl	_tty_port_tty_set
	mov	x23, x22
	ldr	w8, [x23, #16]!
Lloh19:
	adrp	x24, _ASYNC_INITIALIZED@GOTPAGE
Lloh20:
	ldr	x24, [x24, _ASYNC_INITIALIZED@GOTPAGEOFF]
	ldr	w9, [x24]
	tst	w9, w8
	b.ne	LBB0_8
; %bb.7:
	str	xzr, [x22, #24]
	ldr	w1, [x19, #4]
	mov	x0, x19
	bl	_moxa_set_tty_param
	mov	x0, x22
	mov	w1, #1
	mov	w2, #1
	bl	_MoxaPortLineCtrl
	mov	x0, x22
	bl	_MoxaPortEnable
	ldr	x8, [x22]
Lloh21:
	adrp	x9, _PORT_16550A@GOTPAGE
Lloh22:
	ldr	x9, [x9, _PORT_16550A@GOTPAGEOFF]
Lloh23:
	ldr	x9, [x9]
	cmp	x8, x9
	cset	w1, eq
	mov	x0, x22
	bl	_MoxaSetFifo
	ldr	w8, [x24]
	ldr	w9, [x23]
	orr	w8, w9, w8
	str	w8, [x23]
LBB0_8:
Lloh24:
	adrp	x0, _moxa_openlock@GOTPAGE
Lloh25:
	ldr	x0, [x0, _moxa_openlock@GOTPAGEOFF]
	bl	_mutex_unlock
	ldr	w8, [x20]
Lloh26:
	adrp	x9, _O_NONBLOCK@GOTPAGE
Lloh27:
	ldr	x9, [x9, _O_NONBLOCK@GOTPAGEOFF]
Lloh28:
	ldr	w9, [x9]
	tst	w9, w8
	b.ne	LBB0_10
; %bb.9:
	mov	x0, x19
	bl	_C_CLOCAL
	cbz	w0, LBB0_16
LBB0_10:
Lloh29:
	adrp	x0, _moxa_openlock@GOTPAGE
Lloh30:
	ldr	x0, [x0, _moxa_openlock@GOTPAGEOFF]
	bl	_mutex_lock
LBB0_11:
	mov	w20, #0
Lloh31:
	adrp	x8, _ASYNC_NORMAL_ACTIVE@GOTPAGE
Lloh32:
	ldr	x8, [x8, _ASYNC_NORMAL_ACTIVE@GOTPAGEOFF]
Lloh33:
	ldr	w8, [x8]
	ldr	w9, [x23]
	orr	w8, w9, w8
	str	w8, [x23]
LBB0_12:
Lloh34:
	adrp	x0, _moxa_openlock@GOTPAGE
Lloh35:
	ldr	x0, [x0, _moxa_openlock@GOTPAGEOFF]
	bl	_mutex_unlock
	b	LBB0_15
LBB0_13:
Lloh36:
	adrp	x0, _moxa_openlock@GOTPAGE
Lloh37:
	ldr	x0, [x0, _moxa_openlock@GOTPAGEOFF]
	bl	_mutex_unlock
Lloh38:
	adrp	x8, _ENODEV@GOTPAGE
Lloh39:
	ldr	x8, [x8, _ENODEV@GOTPAGEOFF]
LBB0_14:
	ldr	w8, [x8]
	neg	w20, w8
LBB0_15:
	mov	x0, x20
	ldp	x29, x30, [sp, #48]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #32]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #16]             ; 16-byte Folded Reload
	ldp	x24, x23, [sp], #64             ; 16-byte Folded Reload
	ret
LBB0_16:
	mov	x0, x19
	mov	x1, x20
	mov	x2, x22
	bl	_moxa_block_till_ready
	mov	x20, x0
Lloh40:
	adrp	x0, _moxa_openlock@GOTPAGE
Lloh41:
	ldr	x0, [x0, _moxa_openlock@GOTPAGEOFF]
	bl	_mutex_lock
	cbz	w20, LBB0_11
; %bb.17:
	ldr	x8, [x21]
	cbz	x8, LBB0_12
; %bb.18:
	subs	x8, x8, #1
	str	x8, [x21]
	b.ne	LBB0_12
; %bb.19:
	mov	x0, x19
	bl	_moxa_close_port
	b	LBB0_12
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpLdrGotLdr	Lloh6, Lloh7, Lloh8
	.loh AdrpLdrGotLdr	Lloh3, Lloh4, Lloh5
	.loh AdrpLdrGot	Lloh9, Lloh10
	.loh AdrpLdrGot	Lloh11, Lloh12
	.loh AdrpLdrGotLdr	Lloh15, Lloh16, Lloh18
	.loh AdrpLdrGotLdr	Lloh13, Lloh14, Lloh17
	.loh AdrpLdrGot	Lloh19, Lloh20
	.loh AdrpLdrGotLdr	Lloh21, Lloh22, Lloh23
	.loh AdrpLdrGotLdr	Lloh26, Lloh27, Lloh28
	.loh AdrpLdrGot	Lloh24, Lloh25
	.loh AdrpLdrGot	Lloh29, Lloh30
	.loh AdrpLdrGotLdr	Lloh31, Lloh32, Lloh33
	.loh AdrpLdrGot	Lloh34, Lloh35
	.loh AdrpLdrGot	Lloh38, Lloh39
	.loh AdrpLdrGot	Lloh36, Lloh37
	.loh AdrpLdrGot	Lloh40, Lloh41
	.cfi_endproc
                                        ; -- End function
	.comm	_MAX_PORTS,4,2                  ; @MAX_PORTS
	.comm	_CAP_SYS_ADMIN,4,2              ; @CAP_SYS_ADMIN
	.comm	_EPERM,4,2                      ; @EPERM
	.comm	_moxa_openlock,4,2              ; @moxa_openlock
	.comm	_ERESTARTSYS,4,2                ; @ERESTARTSYS
	.comm	_moxa_boards,8,3                ; @moxa_boards
	.comm	_MAX_PORTS_PER_BOARD,4,2        ; @MAX_PORTS_PER_BOARD
	.comm	_ENODEV,4,2                     ; @ENODEV
	.comm	_ASYNC_INITIALIZED,4,2          ; @ASYNC_INITIALIZED
	.comm	_PORT_16550A,8,3                ; @PORT_16550A
	.comm	_O_NONBLOCK,4,2                 ; @O_NONBLOCK
	.comm	_ASYNC_NORMAL_ACTIVE,4,2        ; @ASYNC_NORMAL_ACTIVE
	.no_dead_strip	_moxa_open
.subsections_via_symbols
