// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/./serial_posix.c
// Function: serial_setup
static port_err_t serial_setup(serial_t *h, const serial_baud_t baud,
			       const serial_bits_t bits,
			       const serial_parity_t parity,
			       const serial_stopbit_t stopbit)
{
	speed_t	port_baud;
	tcflag_t port_bits;
	tcflag_t port_parity;
	tcflag_t port_stop;
	struct termios settings;

	switch (baud) {
		case SERIAL_BAUD_1200:    port_baud = B1200; break;
		case SERIAL_BAUD_1800:    port_baud = B1800; break;
		case SERIAL_BAUD_2400:    port_baud = B2400; break;
		case SERIAL_BAUD_4800:    port_baud = B4800; break;
		case SERIAL_BAUD_9600:    port_baud = B9600; break;
		case SERIAL_BAUD_19200:   port_baud = B19200; break;
		case SERIAL_BAUD_38400:   port_baud = B38400; break;
		case SERIAL_BAUD_57600:   port_baud = B57600; break;
		case SERIAL_BAUD_115200:  port_baud = B115200; break;
		case SERIAL_BAUD_230400:  port_baud = B230400; break;
#ifdef B460800
		case SERIAL_BAUD_460800:  port_baud = B460800; break;
#endif /* B460800 */
#ifdef B921600
		case SERIAL_BAUD_921600:  port_baud = B921600; break;
#endif /* B921600 */
#ifdef B500000
		case SERIAL_BAUD_500000:  port_baud = B500000; break;
#endif /* B500000 */
#ifdef B576000
		case SERIAL_BAUD_576000:  port_baud = B576000; break;
#endif /* B576000 */
#ifdef B1000000
		case SERIAL_BAUD_1000000: port_baud = B1000000; break;
#endif /* B1000000 */
#ifdef B1500000
		case SERIAL_BAUD_1500000: port_baud = B1500000; break;
#endif /* B1500000 */
#ifdef B2000000
		case SERIAL_BAUD_2000000: port_baud = B2000000; break;
#endif /* B2000000 */

		case SERIAL_BAUD_INVALID:
		default:
			return PORT_ERR_UNKNOWN;
	}

	switch (bits) {
		case SERIAL_BITS_5: port_bits = CS5; break;
		case SERIAL_BITS_6: port_bits = CS6; break;
		case SERIAL_BITS_7: port_bits = CS7; break;
		case SERIAL_BITS_8: port_bits = CS8; break;

		default:
			return PORT_ERR_UNKNOWN;
	}

	switch (parity) {
		case SERIAL_PARITY_NONE: port_parity = 0; break;
		case SERIAL_PARITY_EVEN: port_parity = PARENB; break;
		case SERIAL_PARITY_ODD:  port_parity = PARENB | PARODD; break;

		default:
			return PORT_ERR_UNKNOWN;
	}

	switch (stopbit) {
		case SERIAL_STOPBIT_1: port_stop = 0;	   break;
		case SERIAL_STOPBIT_2: port_stop = CSTOPB; break;

		default:
			return PORT_ERR_UNKNOWN;
	}

	/* reset the settings */
#ifndef __sun		/* Used by GNU and BSD. Ignore __SVR4 in test. */
	cfmakeraw(&h->newtio);
#else /* __sun */
	h->newtio.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR
			       | IGNCR | ICRNL | IXON);
	h->newtio.c_oflag &= ~OPOST;
	h->newtio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
	h->newtio.c_cflag &= ~(CSIZE | PARENB);
	h->newtio.c_cflag |= CS8;
#endif /* __sun */
#ifdef __QNXNTO__
	h->newtio.c_cflag &= ~(CSIZE | IHFLOW | OHFLOW);
#else
	h->newtio.c_cflag &= ~(CSIZE | CRTSCTS);
#endif
	h->newtio.c_cflag &= ~(CSIZE | CRTSCTS);
	h->newtio.c_iflag &= ~(IXON | IXOFF | IXANY | IGNPAR);
	h->newtio.c_lflag &= ~(ECHOK | ECHOCTL | ECHOKE);
	h->newtio.c_oflag &= ~(OPOST | ONLCR);

	/* setup the new settings */
	cfsetispeed(&h->newtio, port_baud);
	cfsetospeed(&h->newtio, port_baud);
	h->newtio.c_cflag |=
		port_parity	|
		port_bits	|
		port_stop	|
		CLOCAL		|
		CREAD;
	if ( port_parity != 0 )
		h->newtio.c_iflag |= INPCK;

	h->newtio.c_cc[VMIN] = 0;
	h->newtio.c_cc[VTIME] = TERMIOS_TIMEOUT;	/* in units of 0.1 s */

	/* set the settings */
	serial_flush(h);
	if (tcsetattr(h->fd, TCSANOW, &h->newtio) != 0)
		return PORT_ERR_UNKNOWN;

	/* confirm they were set */
	tcgetattr(h->fd, &settings);
	if (settings.c_iflag != h->newtio.c_iflag ||
	    settings.c_oflag != h->newtio.c_oflag ||
	    settings.c_cflag != h->newtio.c_cflag ||
	    settings.c_lflag != h->newtio.c_lflag)
		return PORT_ERR_UNKNOWN;

	snprintf(h->setup_str, sizeof(h->setup_str), "%u %d%c%d",
		 serial_get_baud_int(baud),
		 serial_get_bits_int(bits),
		 serial_get_parity_str(parity),
		 serial_get_stopbit_int(stopbit));
	return PORT_ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x14(%rbp), %eax
movq %rax, -0x78(%rbp)
subq $0x13, %rax
ja 0x6288
movq -0x78(%rbp), %rax
leaq 0x5814(%rip), %rcx      # 0xb9ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x9, -0x24(%rbp)
jmp 0x6294
movl $0xa, -0x24(%rbp)
jmp 0x6294
movl $0xb, -0x24(%rbp)
jmp 0x6294
movl $0xc, -0x24(%rbp)
jmp 0x6294
movl $0xd, -0x24(%rbp)
jmp 0x6294
movl $0xe, -0x24(%rbp)
jmp 0x6294
movl $0xf, -0x24(%rbp)
jmp 0x6294
movl $0x1001, -0x24(%rbp)    # imm = 0x1001
jmp 0x6294
movl $0x1002, -0x24(%rbp)    # imm = 0x1002
jmp 0x6294
movl $0x1003, -0x24(%rbp)    # imm = 0x1003
jmp 0x6294
movl $0x1004, -0x24(%rbp)    # imm = 0x1004
jmp 0x6294
movl $0x1007, -0x24(%rbp)    # imm = 0x1007
jmp 0x6294
movl $0x1005, -0x24(%rbp)    # imm = 0x1005
jmp 0x6294
movl $0x1006, -0x24(%rbp)    # imm = 0x1006
jmp 0x6294
movl $0x1008, -0x24(%rbp)    # imm = 0x1008
jmp 0x6294
movl $0x100a, -0x24(%rbp)    # imm = 0x100A
jmp 0x6294
movl $0x100b, -0x24(%rbp)    # imm = 0x100B
jmp 0x6294
jmp 0x6288
movl $0x3, -0x4(%rbp)
jmp 0x651e
movl -0x18(%rbp), %eax
movq %rax, -0x80(%rbp)
subq $0x3, %rax
ja 0x62d9
movq -0x80(%rbp), %rax
leaq 0x5790(%rip), %rcx      # 0xba3c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x28(%rbp)
jmp 0x62e5
movl $0x10, -0x28(%rbp)
jmp 0x62e5
movl $0x20, -0x28(%rbp)
jmp 0x62e5
movl $0x30, -0x28(%rbp)
jmp 0x62e5
movl $0x3, -0x4(%rbp)
jmp 0x651e
movl -0x1c(%rbp), %eax
movl %eax, -0x84(%rbp)
testl %eax, %eax
je 0x630e
jmp 0x62f4
movl -0x84(%rbp), %eax
subl $0x1, %eax
je 0x6317
jmp 0x6301
movl -0x84(%rbp), %eax
subl $0x2, %eax
je 0x6320
jmp 0x6329
movl $0x0, -0x2c(%rbp)
jmp 0x6335
movl $0x100, -0x2c(%rbp)     # imm = 0x100
jmp 0x6335
movl $0x300, -0x2c(%rbp)     # imm = 0x300
jmp 0x6335
movl $0x3, -0x4(%rbp)
jmp 0x651e
movl -0x20(%rbp), %eax
movl %eax, -0x88(%rbp)
testl %eax, %eax
je 0x6351
jmp 0x6344
movl -0x88(%rbp), %eax
subl $0x1, %eax
je 0x635a
jmp 0x6363
movl $0x0, -0x30(%rbp)
jmp 0x636f
movl $0x40, -0x30(%rbp)
jmp 0x636f
movl $0x3, -0x4(%rbp)
jmp 0x651e
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
callq 0x21f0
movq -0x10(%rbp), %rax
movl 0x48(%rax), %ecx
andl $0x7fffffcf, %ecx       # imm = 0x7FFFFFCF
movl %ecx, 0x48(%rax)
movq -0x10(%rbp), %rax
movl 0x48(%rax), %ecx
andl $0x7fffffcf, %ecx       # imm = 0x7FFFFFCF
movl %ecx, 0x48(%rax)
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
andl $0xffffe3fb, %ecx       # imm = 0xFFFFE3FB
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %ecx
andl $0xfffff5df, %ecx       # imm = 0xFFFFF5DF
movl %ecx, 0x4c(%rax)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %ecx
andl $-0x6, %ecx
movl %ecx, 0x44(%rax)
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movl -0x24(%rbp), %esi
callq 0x2230
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movl -0x24(%rbp), %esi
callq 0x20a0
movl -0x2c(%rbp), %ecx
orl -0x28(%rbp), %ecx
orl -0x30(%rbp), %ecx
orl $0x800, %ecx            # imm = 0x800
orl $0x80, %ecx
movq -0x10(%rbp), %rax
orl 0x48(%rax), %ecx
movl %ecx, 0x48(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x641b
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x57(%rax)
movq -0x10(%rbp), %rax
movb $0x5, 0x56(%rax)
movq -0x10(%rbp), %rdi
callq 0x6590
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rdx
addq $0x40, %rdx
xorl %esi, %esi
callq 0x2210
cmpl $0x0, %eax
je 0x645a
movl $0x3, -0x4(%rbp)
jmp 0x651e
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x6c(%rbp), %rsi
callq 0x2200
movl -0x6c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jne 0x6499
movl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jne 0x6499
movl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jne 0x6499
movl -0x60(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
je 0x64a2
movl $0x3, -0x4(%rbp)
jmp 0x651e
movq -0x10(%rbp), %rax
addq $0x7c, %rax
movq %rax, -0xa0(%rbp)
movl -0x14(%rbp), %edi
callq 0x5880
movl %eax, -0x94(%rbp)
movl -0x18(%rbp), %edi
callq 0x5a00
movl %eax, -0x90(%rbp)
movl -0x1c(%rbp), %edi
callq 0x5af0
movsbl %al, %eax
movl %eax, -0x8c(%rbp)
movl -0x20(%rbp), %edi
callq 0x5bb0
movq -0xa0(%rbp), %rdi
movl -0x94(%rbp), %ecx
movl -0x90(%rbp), %r8d
movl -0x8c(%rbp), %r9d
movl $0xb, %esi
leaq 0x557f(%rip), %rdx      # 0xba8c
movl %eax, (%rsp)
movb $0x0, %al
callq 0x20e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)