// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movl $0x3, %ebp
cmpl $0x13, 0x8(%rsi)
je 0x54c8
movq %rsi, %r12
movq %rdi, %rbx
movq 0x10(%rsi), %rdi
callq 0x50fc
cmpl $0x4, %eax
je 0x54c8
movq 0x10(%r12), %rdi
callq 0x5128
cmpl $0x3, %eax
je 0x54c8
movq 0x10(%r12), %rdi
callq 0x51a1
cmpl $0x2, %eax
je 0x54c8
movq (%r12), %r15
movl $0x88, %edi
movl $0x1, %esi
callq 0x2150
movq %rax, %r14
movq %r15, %rdi
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x2230
movl %eax, (%r14)
testl %eax, %eax
js 0x52c6
movl %eax, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x20f0
testl %eax, %eax
jne 0x52ab
movl (%r14), %edi
movl $0x4, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2080
movl (%r14), %edi
leaq 0x4(%r14), %rsi
callq 0x2210
movl (%r14), %edi
movq %r14, %rsi
addq $0x40, %rsi
callq 0x2210
jmp 0x52d1
movq 0x8d46(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x471d(%rip), %rsi      # 0x99d9
movq %r15, %rdx
xorl %eax, %eax
callq 0x2170
movq %r14, %rdi
callq 0x2030
xorl %r14d, %r14d
testq %r14, %r14
je 0x54c8
movl (%r14), %edi
callq 0x2060
testl %eax, %eax
je 0x535b
movl 0x8(%r12), %r15d
movq 0x10(%r12), %rdi
callq 0x50fc
movl %eax, 0x14(%rsp)
movq 0x10(%r12), %rdi
callq 0x5128
movl %eax, %r13d
movq 0x10(%r12), %rdi
callq 0x51a1
cmpq $0x12, %r15
ja 0x54c0
movl $0x7f5ff, %ecx          # imm = 0x7F5FF
btl %r15d, %ecx
jae 0x54c0
cmpl $0x3, 0x14(%rsp)
ja 0x54c0
leaq 0x46c5(%rip), %rcx      # 0x9a00
movl (%rcx,%r15,4), %esi
testl %r13d, %r13d
je 0x536e
cmpl $0x2, %r13d
je 0x5365
cmpl $0x1, %r13d
jne 0x54c0
movl $0x100, %edi            # imm = 0x100
jmp 0x536a
movq %r12, %rdi
callq 0x2a24
jmp 0x52e6
movl $0x300, %edi            # imm = 0x300
xorl %ecx, %ecx
jmp 0x5373
movb $0x1, %cl
movl %r13d, %edi
movl %eax, %edx
testl %eax, %eax
je 0x5387
cmpl $0x1, %eax
jne 0x54c0
movl $0x40, %edx
movl %eax, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
movl 0x14(%rsp), %ecx
shll $0x4, %ecx
orl $0x880, %ecx            # imm = 0x880
orl %ecx, %edi
orl %edx, %edi
movl %edi, 0x24(%rsp)
leaq 0x40(%r14), %r12
movq %r12, %rdi
movl %esi, 0x18(%rsp)
callq 0x2200
andl $0x7fffffcf, 0x48(%r14) # imm = 0x7FFFFFCF
andl $0xffffe3fb, 0x40(%r14) # imm = 0xFFFFE3FB
andl $0xfffff5df, 0x4c(%r14) # imm = 0xFFFFF5DF
andb $-0x6, 0x44(%r14)
movq %r12, %rdi
movl 0x18(%rsp), %esi
callq 0x2240
movq %r12, %rdi
movl 0x18(%rsp), %esi
callq 0x20a0
movl 0x24(%rsp), %eax
orl %eax, 0x48(%r14)
cmpb $0x0, 0x28(%rsp)
jne 0x53fd
orb $0x10, (%r12)
movw $0x5, 0x56(%r14)
movl (%r14), %edi
xorl %esi, %esi
callq 0x20c0
movl (%r14), %edi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2220
testl %eax, %eax
jne 0x54c0
movl (%r14), %edi
leaq 0x2c(%rsp), %r12
movq %r12, %rsi
callq 0x2210
movl 0x20(%rsp), %ecx
movl (%r12), %eax
cmpl 0x40(%r14), %eax
jne 0x54c0
movl 0x30(%rsp), %eax
cmpl 0x44(%r14), %eax
jne 0x54c0
movl 0x34(%rsp), %eax
cmpl 0x48(%r14), %eax
jne 0x54c0
movl 0x38(%rsp), %eax
cmpl 0x4c(%r14), %eax
jne 0x54c0
leaq 0x7c(%r14), %rax
movq %rax, 0x18(%rsp)
movl %ecx, %ebp
movl %r15d, %edi
callq 0x50e8
movl %eax, %r15d
movl 0x14(%rsp), %edi
callq 0x511c
movl %eax, %r12d
movl %r13d, %edi
callq 0x5187
movsbl %al, %r13d
movl %ebp, %edi
callq 0x51cc
movl %eax, (%rsp)
leaq 0x4556(%rip), %rdx      # 0x99f4
xorl %ebp, %ebp
movl $0xb, %esi
movq 0x18(%rsp), %rdi
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
xorl %eax, %eax
callq 0x20e0
movq %r14, 0x50(%rbx)
jmp 0x54c8
movq %r14, %rdi
callq 0x5680
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq