// File: /workspace/github_c_makefile_star2_O1/patriciogonzalezvivo[P]tprint/include/serial/unix.cc
// Function: serial::Serial::SerialImpl::reconfigurePort()
void
Serial::SerialImpl::reconfigurePort ()
{
  if (fd_ == -1) {
    // Can only operate on a valid file descriptor
    THROW (IOException, "Invalid file descriptor, is the serial port open?");
  }

  struct termios options; // The options for the file descriptor

  if (tcgetattr(fd_, &options) == -1) {
    THROW (IOException, "::tcgetattr");
  }

  // set up raw mode / no echo / binary
  options.c_cflag |= (tcflag_t)  (CLOCAL | CREAD);
  options.c_lflag &= (tcflag_t) ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL |
                                       ISIG | IEXTEN); //|ECHOPRT

  options.c_oflag &= (tcflag_t) ~(OPOST);
  options.c_iflag &= (tcflag_t) ~(INLCR | IGNCR | ICRNL | IGNBRK);
#ifdef IUCLC
  options.c_iflag &= (tcflag_t) ~IUCLC;
#endif
#ifdef PARMRK
  options.c_iflag &= (tcflag_t) ~PARMRK;
#endif

  // setup baud rate
  bool custom_baud = false;
  speed_t baud;
  switch (baudrate_) {
#ifdef B0
  case 0: baud = B0; break;
#endif
#ifdef B50
  case 50: baud = B50; break;
#endif
#ifdef B75
  case 75: baud = B75; break;
#endif
#ifdef B110
  case 110: baud = B110; break;
#endif
#ifdef B134
  case 134: baud = B134; break;
#endif
#ifdef B150
  case 150: baud = B150; break;
#endif
#ifdef B200
  case 200: baud = B200; break;
#endif
#ifdef B300
  case 300: baud = B300; break;
#endif
#ifdef B600
  case 600: baud = B600; break;
#endif
#ifdef B1200
  case 1200: baud = B1200; break;
#endif
#ifdef B1800
  case 1800: baud = B1800; break;
#endif
#ifdef B2400
  case 2400: baud = B2400; break;
#endif
#ifdef B4800
  case 4800: baud = B4800; break;
#endif
#ifdef B7200
  case 7200: baud = B7200; break;
#endif
#ifdef B9600
  case 9600: baud = B9600; break;
#endif
#ifdef B14400
  case 14400: baud = B14400; break;
#endif
#ifdef B19200
  case 19200: baud = B19200; break;
#endif
#ifdef B28800
  case 28800: baud = B28800; break;
#endif
#ifdef B57600
  case 57600: baud = B57600; break;
#endif
#ifdef B76800
  case 76800: baud = B76800; break;
#endif
#ifdef B38400
  case 38400: baud = B38400; break;
#endif
#ifdef B115200
  case 115200: baud = B115200; break;
#endif
#ifdef B128000
  case 128000: baud = B128000; break;
#endif
#ifdef B153600
  case 153600: baud = B153600; break;
#endif
#ifdef B230400
  case 230400: baud = B230400; break;
#endif
#ifdef B256000
  case 256000: baud = B256000; break;
#endif
#ifdef B460800
  case 460800: baud = B460800; break;
#endif
#ifdef B576000
  case 576000: baud = B576000; break;
#endif
#ifdef B921600
  case 921600: baud = B921600; break;
#endif
#ifdef B1000000
  case 1000000: baud = B1000000; break;
#endif
#ifdef B1152000
  case 1152000: baud = B1152000; break;
#endif
#ifdef B1500000
  case 1500000: baud = B1500000; break;
#endif
#ifdef B2000000
  case 2000000: baud = B2000000; break;
#endif
#ifdef B2500000
  case 2500000: baud = B2500000; break;
#endif
#ifdef B3000000
  case 3000000: baud = B3000000; break;
#endif
#ifdef B3500000
  case 3500000: baud = B3500000; break;
#endif
#ifdef B4000000
  case 4000000: baud = B4000000; break;
#endif
  default:
    custom_baud = true;
    // OS X support
#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
    // Starting with Tiger, the IOSSIOSPEED ioctl can be used to set arbitrary baud rates
    // other than those specified by POSIX. The driver for the underlying serial hardware
    // ultimately determines which baud rates can be used. This ioctl sets both the input
    // and output speed.
    speed_t new_baud = static_cast<speed_t> (baudrate_);
    if (-1 == ioctl (fd_, IOSSIOSPEED, &new_baud, 1)) {
      THROW (IOException, errno);
    }
    // Linux Support
#elif defined(__linux__) && defined (TIOCSSERIAL)
    struct serial_struct ser;

    if (-1 == ioctl (fd_, TIOCGSERIAL, &ser)) {
      THROW (IOException, errno);
    }

    // set custom divisor
    ser.custom_divisor = ser.baud_base / static_cast<int> (baudrate_);
    // update flags
    ser.flags &= ~ASYNC_SPD_MASK;
    ser.flags |= ASYNC_SPD_CUST;

    if (-1 == ioctl (fd_, TIOCSSERIAL, &ser)) {
      THROW (IOException, errno);
    }
#else
    throw invalid_argument ("OS does not currently support custom bauds");
#endif
  }
  if (custom_baud == false) {
#ifdef _BSD_SOURCE
    ::cfsetspeed(&options, baud);
#else
    ::cfsetispeed(&options, baud);
    ::cfsetospeed(&options, baud);
#endif
  }

  // setup char len
  options.c_cflag &= (tcflag_t) ~CSIZE;
  if (bytesize_ == eightbits)
    options.c_cflag |= CS8;
  else if (bytesize_ == sevenbits)
    options.c_cflag |= CS7;
  else if (bytesize_ == sixbits)
    options.c_cflag |= CS6;
  else if (bytesize_ == fivebits)
    options.c_cflag |= CS5;
  else
    throw invalid_argument ("invalid char len");
  // setup stopbits
  if (stopbits_ == stopbits_one)
    options.c_cflag &= (tcflag_t) ~(CSTOPB);
  else if (stopbits_ == stopbits_one_point_five)
    // ONE POINT FIVE same as TWO.. there is no POSIX support for 1.5
    options.c_cflag |=  (CSTOPB);
  else if (stopbits_ == stopbits_two)
    options.c_cflag |=  (CSTOPB);
  else
    throw invalid_argument ("invalid stop bit");
  // setup parity
  options.c_iflag &= (tcflag_t) ~(INPCK | ISTRIP);
  if (parity_ == parity_none) {
    options.c_cflag &= (tcflag_t) ~(PARENB | PARODD);
  } else if (parity_ == parity_even) {
    options.c_cflag &= (tcflag_t) ~(PARODD);
    options.c_cflag |=  (PARENB);
  } else if (parity_ == parity_odd) {
    options.c_cflag |=  (PARENB | PARODD);
  }
#ifdef CMSPAR
  else if (parity_ == parity_mark) {
    options.c_cflag |=  (PARENB | CMSPAR | PARODD);
  }
  else if (parity_ == parity_space) {
    options.c_cflag |=  (PARENB | CMSPAR);
    options.c_cflag &= (tcflag_t) ~(PARODD);
  }
#else
  // CMSPAR is not defined on OSX. So do not support mark or space parity.
  else if (parity_ == parity_mark || parity_ == parity_space) {
    throw invalid_argument ("OS does not support mark or space parity");
  }
#endif  // ifdef CMSPAR
  else {
    throw invalid_argument ("invalid parity");
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rdi, %rbx
movl 0x28(%rdi), %edi
cmpl $-0x1, %edi
je 0xc264
leaq -0x5c(%rbp), %rsi
callq 0x83a0
cmpl $-0x1, %eax
je 0xc2d3
orl $0x880, -0x54(%rbp)     # imm = 0x880
andl $0xffff7f84, -0x50(%rbp) # imm = 0xFFFF7F84
andb $-0x2, -0x58(%rbp)
andl $0xfffffc36, -0x5c(%rbp) # imm = 0xFFFFFC36
movq 0x48(%rbx), %rcx
movb $0x1, %al
cmpq $0x95ff, %rcx           # imm = 0x95FF
jg 0xbd4f
cmpq $0x12b, %rcx            # imm = 0x12B
jle 0xbd97
cmpq $0x95f, %rcx            # imm = 0x95F
jg 0xbe0f
cmpq $0x4af, %rcx            # imm = 0x4AF
jg 0xbf17
cmpq $0x12c, %rcx            # imm = 0x12C
je 0xbfd7
cmpq $0x258, %rcx            # imm = 0x258
jne 0xc049
movl $0x8, %r14d
jmp 0xc0a4
cmpq $0xf423f, %rcx          # imm = 0xF423F
jle 0xbdd0
cmpq $0x26259f, %rcx         # imm = 0x26259F
jg 0xbe41
cmpq $0x16e35f, %rcx         # imm = 0x16E35F
jg 0xbf3c
cmpq $0xf4240, %rcx          # imm = 0xF4240
je 0xbfe2
cmpq $0x119400, %rcx         # imm = 0x119400
jne 0xc049
movl $0x1009, %r14d          # imm = 0x1009
jmp 0xc0a4
cmpq $0x6d, %rcx
jle 0xbe73
cmpq $0x95, %rcx
jg 0xbecd
cmpq $0x6e, %rcx
je 0xbfab
cmpq $0x86, %rcx
jne 0xc049
movl $0x4, %r14d
jmp 0xc0a4
cmpq $0x383ff, %rcx          # imm = 0x383FF
jle 0xbe9b
cmpq $0x8c9ff, %rcx          # imm = 0x8C9FF
jg 0xbef2
cmpq $0x38400, %rcx          # imm = 0x38400
je 0xbfb6
cmpq $0x70800, %rcx          # imm = 0x70800
jne 0xc049
movl $0x1004, %r14d          # imm = 0x1004
jmp 0xc0a4
cmpq $0x257f, %rcx           # imm = 0x257F
jg 0xbf61
cmpq $0x960, %rcx            # imm = 0x960
je 0xbfed
cmpq $0x12c0, %rcx           # imm = 0x12C0
jne 0xc049
movl $0xc, %r14d
jmp 0xc0a4
cmpq $0x3567df, %rcx         # imm = 0x3567DF
jg 0xbf86
cmpq $0x2625a0, %rcx         # imm = 0x2625A0
je 0xbff8
cmpq $0x2dc6c0, %rcx         # imm = 0x2DC6C0
jne 0xc049
movl $0x100d, %r14d          # imm = 0x100D
jmp 0xc0a4
testq %rcx, %rcx
je 0xc03c
cmpq $0x32, %rcx
je 0xc02c
cmpq $0x4b, %rcx
jne 0xc049
movl $0x2, %r14d
jmp 0xc0a4
cmpq $0x9600, %rcx           # imm = 0x9600
je 0xc041
cmpq $0xe100, %rcx           # imm = 0xE100
je 0xc034
cmpq $0x1c200, %rcx          # imm = 0x1C200
jne 0xc049
movl $0x1002, %r14d          # imm = 0x1002
jmp 0xc0a4
cmpq $0x96, %rcx
je 0xbfc1
cmpq $0xc8, %rcx
jne 0xc049
movl $0x6, %r14d
jmp 0xc0a4
cmpq $0x8ca00, %rcx          # imm = 0x8CA00
je 0xbfcc
cmpq $0xe1000, %rcx          # imm = 0xE1000
jne 0xc049
movl $0x1007, %r14d          # imm = 0x1007
jmp 0xc0a4
cmpq $0x4b0, %rcx            # imm = 0x4B0
je 0xc003
cmpq $0x708, %rcx            # imm = 0x708
jne 0xc049
movl $0xa, %r14d
jmp 0xc0a4
cmpq $0x16e360, %rcx         # imm = 0x16E360
je 0xc00e
cmpq $0x1e8480, %rcx         # imm = 0x1E8480
jne 0xc049
movl $0x100b, %r14d          # imm = 0x100B
jmp 0xc0a4
cmpq $0x2580, %rcx           # imm = 0x2580
je 0xc019
cmpq $0x4b00, %rcx           # imm = 0x4B00
jne 0xc049
movl $0xe, %r14d
jmp 0xc0a4
cmpq $0x3567e0, %rcx         # imm = 0x3567E0
je 0xc024
cmpq $0x3d0900, %rcx         # imm = 0x3D0900
jne 0xc049
movl $0x100f, %r14d          # imm = 0x100F
jmp 0xc0a4
movl $0x3, %r14d
jmp 0xc0a4
movl $0x1003, %r14d          # imm = 0x1003
jmp 0xc0a4
movl $0x5, %r14d
jmp 0xc0a4
movl $0x1006, %r14d          # imm = 0x1006
jmp 0xc0a4
movl $0x7, %r14d
jmp 0xc0a4
movl $0x1008, %r14d          # imm = 0x1008
jmp 0xc0a4
movl $0xb, %r14d
jmp 0xc0a4
movl $0x100c, %r14d          # imm = 0x100C
jmp 0xc0a4
movl $0x9, %r14d
jmp 0xc0a4
movl $0x100a, %r14d          # imm = 0x100A
jmp 0xc0a4
movl $0xd, %r14d
jmp 0xc0a4
movl $0x100e, %r14d          # imm = 0x100E
jmp 0xc0a4
movl $0x1, %r14d
jmp 0xc0a4
movl $0x1001, %r14d          # imm = 0x1001
jmp 0xc0a4
xorl %r14d, %r14d
jmp 0xc0a4
movl $0xf, %r14d
jmp 0xc0a4
movl 0x28(%rbx), %edi
leaq -0x128(%rbp), %rdx
movl $0x541e, %esi           # imm = 0x541E
xorl %eax, %eax
callq 0x8480
cmpl $-0x1, %eax
je 0xc3b0
leaq -0x128(%rbp), %rcx
movl 0x1c(%rcx), %eax
cltd
idivl 0x48(%rbx)
movl %eax, 0x18(%rcx)
movl $0xffffefcf, %eax       # imm = 0xFFFFEFCF
andl 0x10(%rcx), %eax
orl $0x30, %eax
movl %eax, 0x10(%rcx)
movl 0x28(%rbx), %edi
movl $0x541f, %esi           # imm = 0x541F
movq %rcx, %rdx
xorl %eax, %eax
callq 0x8480
cmpl $-0x1, %eax
je 0xc41c
xorl %eax, %eax
testb %al, %al
je 0xc0c2
leaq -0x5c(%rbp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x81e0
movq %r15, %rdi
movl %r14d, %esi
callq 0x8380
movl -0x54(%rbp), %ecx
movl %ecx, %eax
andl $-0x31, %eax
movl %eax, -0x54(%rbp)
movl 0x58(%rbx), %edx
addl $-0x5, %edx
cmpl $0x3, %edx
ja 0xc360
leaq 0x150bd(%rip), %rsi     # 0x211a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
orl $0x10, %eax
jmp 0xc0fb
orl $0x20, %eax
jmp 0xc0fb
orl $0x30, %ecx
movl %ecx, %eax
movl %eax, -0x54(%rbp)
movl 0x5c(%rbx), %eax
cmpl $0x3, %eax
je 0xc11c
cmpl $0x2, %eax
je 0xc11c
cmpl $0x1, %eax
jne 0xc342
movl -0x54(%rbp), %eax
andl $-0x41, %eax
jmp 0xc122
movl -0x54(%rbp), %eax
orl $0x40, %eax
movl %eax, -0x54(%rbp)
movl -0x5c(%rbp), %edx
movl %edx, %eax
andl $-0x31, %eax
movl %eax, -0x5c(%rbp)
movl 0x54(%rbx), %ecx
cmpq $0x4, %rcx
ja 0xc37e
leaq 0x1506c(%rip), %rsi     # 0x211b0
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl $0xfffffcff, %ecx       # imm = 0xFFFFFCFF
andl -0x54(%rbp), %ecx
jmp 0xc186
movl $0xbffffcff, %ecx       # imm = 0xBFFFFCFF
andl -0x54(%rbp), %ecx
orl $0x40000100, %ecx       # imm = 0x40000100
jmp 0xc186
movl $0xfffffcff, %ecx       # imm = 0xFFFFFCFF
andl -0x54(%rbp), %ecx
orl $0x100, %ecx            # imm = 0x100
jmp 0xc186
movl $0x40000300, %ecx       # imm = 0x40000300
jmp 0xc183
movl $0x300, %ecx            # imm = 0x300
orl -0x54(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movl 0x60(%rbx), %ecx
cmpl $0x2, %ecx
ja 0xc1aa
shll $0x3, %ecx
movl $0x100, %esi            # imm = 0x100
shrl %cl, %esi
movl $0x10000, %edi          # imm = 0x10000
shrl %cl, %edi
movb %sil, 0x2d(%rbx)
movb %dil, 0x2e(%rbx)
andl $0xffffe3cf, %edx       # imm = 0xFFFFE3CF
orl $0x1400, %eax           # imm = 0x1400
cmpb $0x0, 0x2d(%rbx)
cmovel %edx, %eax
leaq -0x5c(%rbp), %rdx
movl %eax, (%rdx)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x8(%rdx), %eax
movzbl 0x2e(%rbx), %ecx
shll $0x1f, %ecx
orl %eax, %ecx
movl %ecx, 0x8(%rdx)
movw $0x0, 0x16(%rdx)
movl 0x28(%rbx), %edi
xorl %esi, %esi
callq 0x8410
movsd 0x48(%rbx), %xmm0
unpcklps 0x14f8e(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x14f96(%rip), %xmm0    # 0x21190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x14f62(%rip), %xmm0    # 0x21170
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movl 0x58(%rbx), %eax
addl 0x54(%rbx), %eax
movl 0x5c(%rbx), %edx
addl %edx, %eax
incl %eax
imull %ecx, %eax
cmpl $0x3, %edx
jne 0xc251
movl %ecx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x14f30(%rip), %xmm0    # 0x21178
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x50(%rbx)
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x58, %edi
callq 0x81a0
movq %rax, %r14
leaq -0xd0(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x14f8e(%rip), %rsi     # 0x21212
leaq 0x14f9d(%rip), %rdx     # 0x21228
leaq -0xe0(%rbp), %rdi
callq 0x9f82
movb $0x1, %r15b
leaq 0x14fa4(%rip), %rcx     # 0x21245
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
movl $0xa5, %edx
callq 0xe3c0
xorl %r15d, %r15d
leaq 0x1b9f9(%rip), %rsi     # 0x27cb8
leaq 0x22fc(%rip), %rdx      # 0xe5c2
movq %r14, %rdi
callq 0x85c0
jmp 0xc47d
movl $0x58, %edi
callq 0x81a0
movq %rax, %r14
leaq -0xb0(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x14f1f(%rip), %rsi     # 0x21212
leaq 0x14f2e(%rip), %rdx     # 0x21228
leaq -0xc0(%rbp), %rdi
callq 0x9f82
movb $0x1, %r15b
leaq 0x14f67(%rip), %rcx     # 0x21277
leaq -0xc0(%rbp), %rsi
movq %r14, %rdi
movl $0xab, %edx
callq 0xe3c0
xorl %r15d, %r15d
leaq 0x1b98a(%rip), %rsi     # 0x27cb8
leaq 0x228d(%rip), %rdx      # 0xe5c2
movq %r14, %rdi
callq 0x85c0
jmp 0xc47d
movl $0x10, %edi
callq 0x81a0
movq %rax, %r14
leaq 0x14f3e(%rip), %rsi     # 0x21294
movq %rax, %rdi
callq 0x8670
jmp 0xc39a
movl $0x10, %edi
callq 0x81a0
movq %rax, %r14
leaq 0x14f0f(%rip), %rsi     # 0x21283
movq %rax, %rdi
callq 0x8670
jmp 0xc39a
movl $0x10, %edi
callq 0x81a0
movq %rax, %r14
leaq 0x14f13(%rip), %rsi     # 0x212a5
movq %rax, %rdi
callq 0x8670
movq 0x1bc37(%rip), %rsi     # 0x27fd8
movq 0x1bc20(%rip), %rdx     # 0x27fc8
movq %r14, %rdi
callq 0x85c0
movl $0x58, %edi
callq 0x81a0
movq %rax, %r14
leaq -0x90(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x14e42(%rip), %rsi     # 0x21212
leaq 0x14e51(%rip), %rdx     # 0x21228
leaq -0xa0(%rbp), %rdi
callq 0x9f82
callq 0x8060
movl (%rax), %ecx
movb $0x1, %r15b
leaq -0xa0(%rbp), %rsi
movq %r14, %rdi
movl $0x140, %edx            # imm = 0x140
callq 0xe614
xorl %r15d, %r15d
leaq 0x1b8ad(%rip), %rsi     # 0x27cb8
leaq 0x21b0(%rip), %rdx      # 0xe5c2
movq %r14, %rdi
callq 0x85c0
jmp 0xc47d
movl $0x58, %edi
callq 0x81a0
movq %rax, %r14
leaq -0x70(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x14dd9(%rip), %rsi     # 0x21212
leaq 0x14de8(%rip), %rdx     # 0x21228
leaq -0x80(%rbp), %rdi
callq 0x9f82
callq 0x8060
movl (%rax), %ecx
movb $0x1, %r15b
leaq -0x80(%rbp), %rsi
movq %r14, %rdi
movl $0x14a, %edx            # imm = 0x14A
callq 0xe614
xorl %r15d, %r15d
leaq 0x1b84a(%rip), %rsi     # 0x27cb8
leaq 0x214d(%rip), %rdx      # 0xe5c2
movq %r14, %rdi
callq 0x85c0
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0xc4f4
movq -0x70(%rbp), %rsi
jmp 0xc4e4
jmp 0xc4ee
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0xc4f4
movq -0x90(%rbp), %rsi
jmp 0xc4e4
jmp 0xc4ee
jmp 0xc4af
jmp 0xc4af
movq %rax, %rbx
jmp 0xc4f9
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r12, %rdi
je 0xc4f4
movq -0xb0(%rbp), %rsi
jmp 0xc4e4
jmp 0xc4ee
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r12, %rdi
je 0xc4f4
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x8320
jmp 0xc4f4
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xc501
movq %r14, %rdi
callq 0x8250
movq %rbx, %rdi
callq 0x8600
nop