// File: /workspace/github_c_makefile_star2_O2/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/./serial_posix.c
// Function: serial_posix_open
static port_err_t serial_posix_open(struct port_interface *port,
				    struct port_options *ops)
{
	serial_t *h;

	/* 1. check options */
	if (ops->baudRate == SERIAL_BAUD_INVALID)
		return PORT_ERR_UNKNOWN;
	if (serial_get_bits(ops->serial_mode) == SERIAL_BITS_INVALID)
		return PORT_ERR_UNKNOWN;
	if (serial_get_parity(ops->serial_mode) == SERIAL_PARITY_INVALID)
		return PORT_ERR_UNKNOWN;
	if (serial_get_stopbit(ops->serial_mode) == SERIAL_STOPBIT_INVALID)
		return PORT_ERR_UNKNOWN;

	/* 2. open it */
	h = serial_open(ops->device);
	if (h == NULL)
		return PORT_ERR_UNKNOWN;

	/* 3. check for tty (but only warn) */
	if (!isatty(h->fd))
		fprintf(stderr, "Warning: Not a tty: %s\n", ops->device);

	/* 4. set options */
	if (serial_setup(h, ops->baudRate,
			 serial_get_bits(ops->serial_mode),
			 serial_get_parity(ops->serial_mode),
			 serial_get_stopbit(ops->serial_mode)
			) != PORT_ERR_OK) {
		serial_close(h);
		return PORT_ERR_UNKNOWN;
	}

	port->private = h;
	return PORT_ERR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
pushq $0x3
popq %rbx
cmpl $0x13, 0x8(%rsi)
je 0x496b
movq %rsi, %r13
movq %rdi, %r14
movq 0x10(%rsi), %rdi
callq 0x458f
cmpl $0x4, %eax
je 0x496b
movq 0x10(%r13), %rdi
callq 0x45b7
cmpl $0x3, %eax
je 0x496b
movq 0x10(%r13), %rdi
callq 0x4625
cmpl $0x2, %eax
je 0x496b
movq (%r13), %r12
pushq $0x1
popq %rsi
movl $0x88, %edi
callq 0x2150
movq %rax, %r15
movq %r12, %rdi
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x2230
movl %eax, (%r15)
testl %eax, %eax
js 0x47ca
movl %eax, %ebp
pushq $0x2
popq %rsi
movl %eax, %edi
xorl %edx, %edx
callq 0x20f0
testl %eax, %eax
jne 0x47af
pushq $0x4
popq %rsi
movl %ebp, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2080
leaq 0x4(%r15), %rsi
movl %ebp, %edi
callq 0x2210
movl (%r15), %edi
leaq 0x40(%r15), %rbp
movq %rbp, %rsi
callq 0x2210
movl (%r15), %edi
callq 0x2060
testl %eax, %eax
je 0x47d7
movl 0x8(%r13), %r12d
movq 0x10(%r13), %rdi
callq 0x458f
movl %eax, 0xc(%rsp)
movq 0x10(%r13), %rdi
callq 0x45b7
movl %eax, 0x10(%rsp)
movq 0x10(%r13), %rdi
callq 0x4625
cmpq $0x12, %r12
ja 0x4963
movl $0x7f5ff, %ecx          # imm = 0x7F5FF
btl %r12d, %ecx
jae 0x4963
cmpl $0x3, 0xc(%rsp)
ja 0x4963
leaq 0x4297(%rip), %rcx      # 0x8a20
movl (%rcx,%r12,4), %esi
movl 0x10(%rsp), %r13d
testl %r13d, %r13d
je 0x4802
cmpl $0x2, %r13d
je 0x47f8
cmpl $0x1, %r13d
jne 0x4963
movl $0x100, %r13d           # imm = 0x100
jmp 0x47fe
movq 0x883a(%rip), %rax      # 0xcff0
movq (%rax), %rdi
leaq 0x4239(%rip), %rsi      # 0x89f9
movq %r12, %rdx
xorl %eax, %eax
callq 0x2170
movq %r15, %rdi
callq 0x2030
jmp 0x496b
movq 0x8812(%rip), %rax      # 0xcff0
movq (%rax), %rdi
movq (%r13), %rdx
leaq 0x41f5(%rip), %rsi      # 0x89e1
xorl %eax, %eax
callq 0x2170
jmp 0x4737
movl $0x300, %r13d           # imm = 0x300
xorl %ecx, %ecx
jmp 0x4804
movb $0x1, %cl
movl %eax, %edx
testl %eax, %eax
je 0x4816
cmpl $0x1, %eax
jne 0x4963
pushq $0x40
popq %rdx
movl %eax, 0x14(%rsp)
movl %ecx, 0x8(%rsp)
movl 0xc(%rsp), %ecx
shll $0x4, %ecx
orl $0x880, %ecx            # imm = 0x880
orl %ecx, %r13d
orl %edx, %r13d
movl %r13d, 0x18(%rsp)
movq %rbp, %rdi
movl %esi, %r13d
callq 0x2200
movq 0x48(%r15), %xmm0
movabsq $-0xa2080000031, %rax   # imm = 0xFFFFF5DF7FFFFFCF
movq %rax, %xmm1
pand %xmm0, %xmm1
movq 0x40(%r15), %xmm0
movabsq $-0x500001c05, %rax     # imm = 0xFFFFFFFAFFFFE3FB
movq %rax, %xmm2
pand %xmm0, %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movdqu %xmm2, 0x40(%r15)
movq %rbp, %rdi
movl %r13d, %esi
callq 0x2240
movq %rbp, %rdi
movl %r13d, %esi
callq 0x20a0
movl 0x18(%rsp), %eax
orl %eax, 0x48(%r15)
cmpb $0x0, 0x8(%rsp)
jne 0x48a6
orb $0x10, (%rbp)
movw $0x5, 0x56(%r15)
movq %r15, %rdi
callq 0x4b34
movl (%r15), %edi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x2220
testl %eax, %eax
jne 0x4963
movl (%r15), %edi
leaq 0x1c(%rsp), %r13
movq %r13, %rsi
callq 0x2210
movl 0x14(%rsp), %ecx
movl (%r13), %eax
cmpl 0x40(%r15), %eax
jne 0x4963
movl 0x20(%rsp), %eax
cmpl 0x44(%r15), %eax
jne 0x4963
movl 0x24(%rsp), %eax
cmpl 0x48(%r15), %eax
jne 0x4963
movl 0x28(%rsp), %eax
cmpl 0x4c(%r15), %eax
jne 0x4963
movq %r15, %r13
addq $0x7c, %r13
movl %ecx, %ebx
movl %r12d, %edi
callq 0x457b
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %edi
callq 0x45ab
movl %eax, %r12d
movl 0x10(%rsp), %edi
callq 0x460d
movsbl %al, %ebp
movl %ebx, %edi
callq 0x464e
movl %eax, (%rsp)
leaq 0x40d0(%rip), %rdx      # 0x8a14
xorl %ebx, %ebx
pushq $0xb
popq %rsi
movq %r13, %rdi
movl 0x8(%rsp), %ecx
movl %r12d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x20e0
movq %r15, 0x50(%r14)
jmp 0x496b
movq %r15, %rdi
callq 0x4b03
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq