// File: /workspace/github_c_makefile_star2_O3/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
movl $0x3, %ebx
cmpl $0x13, 0x8(%rsi)
je 0x5401
movq %rsi, %r13
movq %rdi, %r14
movq 0x10(%rsi), %rdi
callq 0x5018
cmpl $0x4, %eax
je 0x5401
movq 0x10(%r13), %rdi
callq 0x5044
cmpl $0x3, %eax
je 0x5401
movq 0x10(%r13), %rdi
callq 0x50bd
cmpl $0x2, %eax
je 0x5401
movq (%r13), %r12
movl $0x88, %edi
movl $0x1, %esi
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 0x526e
movl %eax, %ebp
movl %eax, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x20f0
testl %eax, %eax
jne 0x5253
movl %ebp, %edi
movl $0x4, %esi
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 0x527b
movl 0x8(%r13), %r12d
movq 0x10(%r13), %rdi
callq 0x5018
movl %eax, 0xc(%rsp)
movq 0x10(%r13), %rdi
callq 0x5044
movl %eax, 0x10(%rsp)
movq 0x10(%r13), %rdi
callq 0x50bd
cmpq $0x12, %r12
ja 0x53f9
movl $0x7f5ff, %ecx          # imm = 0x7F5FF
btl %r12d, %ecx
jae 0x53f9
cmpl $0x3, 0xc(%rsp)
ja 0x53f9
leaq 0x47e7(%rip), %rcx      # 0x9a14
movl (%rcx,%r12,4), %esi
movl 0x10(%rsp), %r13d
testl %r13d, %r13d
je 0x5292
cmpl $0x2, %r13d
je 0x5288
cmpl $0x1, %r13d
jne 0x53f9
movl $0x100, %r13d           # imm = 0x100
jmp 0x528e
movq 0x8d9e(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x4789(%rip), %rsi      # 0x99ed
movq %r12, %rdx
xorl %eax, %eax
callq 0x2170
movq %r15, %rdi
callq 0x2030
jmp 0x5401
movq %r13, %rdi
callq 0x2958
jmp 0x51db
movl $0x300, %r13d           # imm = 0x300
xorl %ecx, %ecx
jmp 0x5294
movb $0x1, %cl
movl %eax, %edx
testl %eax, %eax
je 0x52a8
cmpl $0x1, %eax
jne 0x53f9
movl $0x40, %edx
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 0x5338
orb $0x10, (%rbp)
movw $0x5, 0x56(%r15)
movl (%r15), %edi
xorl %esi, %esi
callq 0x20c0
movl (%r15), %edi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x2220
testl %eax, %eax
jne 0x53f9
movl (%r15), %edi
leaq 0x1c(%rsp), %r13
movq %r13, %rsi
callq 0x2210
movl 0x14(%rsp), %ecx
movl (%r13), %eax
cmpl 0x40(%r15), %eax
jne 0x53f9
movl 0x20(%rsp), %eax
cmpl 0x44(%r15), %eax
jne 0x53f9
movl 0x24(%rsp), %eax
cmpl 0x48(%r15), %eax
jne 0x53f9
movl 0x28(%rsp), %eax
cmpl 0x4c(%r15), %eax
jne 0x53f9
movq %r15, %r13
addq $0x7c, %r13
movl %ecx, %ebx
movl %r12d, %edi
callq 0x5004
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %edi
callq 0x5038
movl %eax, %r12d
movl 0x10(%rsp), %edi
callq 0x50a3
movsbl %al, %ebp
movl %ebx, %edi
callq 0x50e8
movl %eax, (%rsp)
leaq 0x4630(%rip), %rdx      # 0x9a08
xorl %ebx, %ebx
movl $0xb, %esi
movq %r13, %rdi
movl 0x8(%rsp), %ecx
movl %r12d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x20e0
movq %r15, 0x50(%r14)
jmp 0x5401
movq %r15, %rdi
callq 0x55b9
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq