// File: /workspace/github_c_makefile_star2_O3/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 0xc212
leaq -0x5c(%rbp), %rsi
callq 0x8390
cmpl $-0x1, %eax
je 0xc280
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), %rax
cmpq $0x95ff, %rax           # imm = 0x95FF
jg 0xbce5
cmpq $0x12b, %rax            # imm = 0x12B
jle 0xbd28
cmpq $0x95f, %rax            # imm = 0x95F
jg 0xbd9a
cmpq $0x4af, %rax            # imm = 0x4AF
jg 0xbe95
cmpq $0x12c, %rax            # imm = 0x12C
je 0xbf3a
cmpq $0x258, %rax            # imm = 0x258
jne 0xc154
movl $0x8, %r14d
jmp 0xbf95
cmpq $0xf423f, %rax          # imm = 0xF423F
jle 0xbd5f
cmpq $0x26259f, %rax         # imm = 0x26259F
jg 0xbdc9
cmpq $0x16e35f, %rax         # imm = 0x16E35F
jg 0xbeb8
cmpq $0xf4240, %rax          # imm = 0xF4240
je 0xbf42
cmpq $0x119400, %rax         # imm = 0x119400
jne 0xc154
movl $0x1009, %r14d          # imm = 0x1009
jmp 0xbf95
cmpq $0x6d, %rax
jle 0xbdf8
cmpq $0x95, %rax
jg 0xbe4f
cmpq $0x6e, %rax
je 0xbf1a
cmpq $0x86, %rax
jne 0xc154
movl $0x4, %r14d
jmp 0xbf95
cmpq $0x383ff, %rax          # imm = 0x383FF
jle 0xbe20
cmpq $0x8c9ff, %rax          # imm = 0x8C9FF
jg 0xbe72
cmpq $0x38400, %rax          # imm = 0x38400
je 0xbf22
cmpq $0x70800, %rax          # imm = 0x70800
jne 0xc154
movl $0x1004, %r14d          # imm = 0x1004
jmp 0xbf95
cmpq $0x257f, %rax           # imm = 0x257F
jg 0xbedb
cmpq $0x960, %rax            # imm = 0x960
je 0xbf4a
cmpq $0x12c0, %rax           # imm = 0x12C0
jne 0xc154
movl $0xc, %r14d
jmp 0xbf95
cmpq $0x3567df, %rax         # imm = 0x3567DF
jg 0xbefe
cmpq $0x2625a0, %rax         # imm = 0x2625A0
je 0xbf52
cmpq $0x2dc6c0, %rax         # imm = 0x2DC6C0
jne 0xc154
movl $0x100d, %r14d          # imm = 0x100D
jmp 0xbf95
testq %rax, %rax
je 0xbf8a
cmpq $0x32, %rax
je 0xbf7a
cmpq $0x4b, %rax
jne 0xc154
movl $0x2, %r14d
jmp 0xbf95
cmpq $0x9600, %rax           # imm = 0x9600
je 0xbf8f
cmpq $0xe100, %rax           # imm = 0xE100
je 0xbf82
cmpq $0x1c200, %rax          # imm = 0x1C200
jne 0xc154
movl $0x1002, %r14d          # imm = 0x1002
jmp 0xbf95
cmpq $0x96, %rax
je 0xbf2a
cmpq $0xc8, %rax
jne 0xc154
movl $0x6, %r14d
jmp 0xbf95
cmpq $0x8ca00, %rax          # imm = 0x8CA00
je 0xbf32
cmpq $0xe1000, %rax          # imm = 0xE1000
jne 0xc154
movl $0x1007, %r14d          # imm = 0x1007
jmp 0xbf95
cmpq $0x4b0, %rax            # imm = 0x4B0
je 0xbf5a
cmpq $0x708, %rax            # imm = 0x708
jne 0xc154
movl $0xa, %r14d
jmp 0xbf95
cmpq $0x16e360, %rax         # imm = 0x16E360
je 0xbf62
cmpq $0x1e8480, %rax         # imm = 0x1E8480
jne 0xc154
movl $0x100b, %r14d          # imm = 0x100B
jmp 0xbf95
cmpq $0x2580, %rax           # imm = 0x2580
je 0xbf6a
cmpq $0x4b00, %rax           # imm = 0x4B00
jne 0xc154
movl $0xe, %r14d
jmp 0xbf95
cmpq $0x3567e0, %rax         # imm = 0x3567E0
je 0xbf72
cmpq $0x3d0900, %rax         # imm = 0x3D0900
jne 0xc154
movl $0x100f, %r14d          # imm = 0x100F
jmp 0xbf95
movl $0x3, %r14d
jmp 0xbf95
movl $0x1003, %r14d          # imm = 0x1003
jmp 0xbf95
movl $0x5, %r14d
jmp 0xbf95
movl $0x1006, %r14d          # imm = 0x1006
jmp 0xbf95
movl $0x7, %r14d
jmp 0xbf95
movl $0x1008, %r14d          # imm = 0x1008
jmp 0xbf95
movl $0xb, %r14d
jmp 0xbf95
movl $0x100c, %r14d          # imm = 0x100C
jmp 0xbf95
movl $0x9, %r14d
jmp 0xbf95
movl $0x100a, %r14d          # imm = 0x100A
jmp 0xbf95
movl $0xd, %r14d
jmp 0xbf95
movl $0x100e, %r14d          # imm = 0x100E
jmp 0xbf95
movl $0x1, %r14d
jmp 0xbf95
movl $0x1001, %r14d          # imm = 0x1001
jmp 0xbf95
xorl %r14d, %r14d
jmp 0xbf95
movl $0xf, %r14d
leaq -0x5c(%rbp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x81d0
movq %r15, %rdi
movl %r14d, %esi
callq 0x8370
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 0xc30c
leaq 0x141d0(%rip), %rsi     # 0x201a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
orl $0x10, %eax
jmp 0xbfe8
orl $0x20, %eax
jmp 0xbfe8
orl $0x30, %ecx
movl %ecx, %eax
movl %eax, -0x54(%rbp)
movl 0x5c(%rbx), %ecx
cmpl $0x3, %ecx
je 0xc006
cmpl $0x2, %ecx
je 0xc006
cmpl $0x1, %ecx
jne 0xc2ee
andl $-0x41, %eax
jmp 0xc009
orl $0x40, %eax
movl %eax, -0x54(%rbp)
movl -0x5c(%rbp), %ecx
movl %ecx, %edx
andl $-0x31, %edx
movl %edx, -0x5c(%rbp)
movl 0x54(%rbx), %esi
cmpq $0x4, %rsi
ja 0xc32a
leaq 0x14185(%rip), %rdi     # 0x201b0
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
andl $0xfffffcff, %eax       # imm = 0xFFFFFCFF
jmp 0xc05f
andl $0xbffffcff, %eax       # imm = 0xBFFFFCFF
orl $0x40000100, %eax       # imm = 0x40000100
jmp 0xc05f
andl $0xfffffcff, %eax       # imm = 0xFFFFFCFF
orl $0x100, %eax            # imm = 0x100
jmp 0xc05f
orl $0x40000300, %eax       # imm = 0x40000300
jmp 0xc05f
orl $0x300, %eax            # imm = 0x300
movl 0x60(%rbx), %esi
testl %esi, %esi
je 0xc08b
cmpl $0x2, %esi
je 0xc082
cmpl $0x1, %esi
jne 0xc09c
movw $0x1, 0x2d(%rbx)
orl $0x1400, %edx           # imm = 0x1400
xorl %esi, %esi
movl %edx, %ecx
jmp 0xc0b6
movl $0x80000000, %esi       # imm = 0x80000000
movb $0x1, %dl
jmp 0xc08d
xorl %edx, %edx
movb $0x0, 0x2d(%rbx)
movb %dl, 0x2e(%rbx)
andl $0xffffe3cf, %ecx       # imm = 0xFFFFE3CF
jmp 0xc0b6
movzbl 0x2e(%rbx), %esi
shll $0x1f, %esi
andl $0xffffe3cf, %ecx       # imm = 0xFFFFE3CF
orl $0x1400, %edx           # imm = 0x1400
testb $0x1, 0x2d(%rbx)
cmovnel %edx, %ecx
leaq -0x5c(%rbp), %rdx
movl %ecx, (%rdx)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %esi, %eax
movl %eax, 0x8(%rdx)
movw $0x0, 0x16(%rdx)
movl 0x28(%rbx), %edi
xorl %esi, %esi
callq 0x8400
movsd 0x48(%rbx), %xmm0
unpcklps 0x1409e(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x140a6(%rip), %xmm0    # 0x20190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x14072(%rip), %xmm0    # 0x20170
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 0xc141
movl %ecx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x14040(%rip), %xmm0    # 0x20178
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 0x28(%rbx), %edi
leaq -0x128(%rbp), %rdx
movl $0x541e, %esi           # imm = 0x541E
xorl %eax, %eax
callq 0x8470
cmpl $-0x1, %eax
je 0xc35c
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 0x8470
cmpl $-0x1, %eax
jne 0xbfaf
movl $0x58, %edi
callq 0x8190
movq %rax, %r14
leaq -0x70(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x14049(%rip), %rsi     # 0x20212
leaq 0x14058(%rip), %rdx     # 0x20228
leaq -0x80(%rbp), %rdi
callq 0x9f1e
callq 0x8060
movl (%rax), %ecx
movb $0x1, %r12b
leaq -0x80(%rbp), %rsi
movq %r14, %rdi
movl $0x14a, %edx            # imm = 0x14A
callq 0xe4d8
xorl %r12d, %r12d
leaq 0x1aaa2(%rip), %rsi     # 0x26ca0
leaq 0x2281(%rip), %rdx      # 0xe486
movq %r14, %rdi
callq 0x85b0
jmp 0xc3c5
movl $0x58, %edi
callq 0x8190
movq %rax, %r14
leaq -0xd0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x13fe1(%rip), %rsi     # 0x20212
leaq 0x13ff0(%rip), %rdx     # 0x20228
leaq -0xe0(%rbp), %rdi
callq 0x9f1e
movb $0x1, %r12b
leaq 0x13ff7(%rip), %rcx     # 0x20245
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
movl $0xa5, %edx
callq 0xe284
xorl %r12d, %r12d
leaq 0x1aa34(%rip), %rsi     # 0x26ca0
leaq 0x2213(%rip), %rdx      # 0xe486
movq %r14, %rdi
callq 0x85b0
jmp 0xc3c5
movl $0x58, %edi
callq 0x8190
movq %rax, %r14
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x13f73(%rip), %rsi     # 0x20212
leaq 0x13f82(%rip), %rdx     # 0x20228
leaq -0xc0(%rbp), %rdi
callq 0x9f1e
movb $0x1, %r12b
leaq 0x13fbb(%rip), %rcx     # 0x20277
leaq -0xc0(%rbp), %rsi
movq %r14, %rdi
movl $0xab, %edx
callq 0xe284
xorl %r12d, %r12d
leaq 0x1a9c6(%rip), %rsi     # 0x26ca0
leaq 0x21a5(%rip), %rdx      # 0xe486
movq %r14, %rdi
callq 0x85b0
jmp 0xc3c5
movl $0x10, %edi
callq 0x8190
movq %rax, %r14
leaq 0x13f92(%rip), %rsi     # 0x20294
movq %rax, %rdi
callq 0x8660
jmp 0xc346
movl $0x10, %edi
callq 0x8190
movq %rax, %r14
leaq 0x13f63(%rip), %rsi     # 0x20283
movq %rax, %rdi
callq 0x8660
jmp 0xc346
movl $0x10, %edi
callq 0x8190
movq %rax, %r14
leaq 0x13f67(%rip), %rsi     # 0x202a5
movq %rax, %rdi
callq 0x8660
movq 0x1ac8b(%rip), %rsi     # 0x26fd8
movq 0x1ac74(%rip), %rdx     # 0x26fc8
movq %r14, %rdi
callq 0x85b0
movl $0x58, %edi
callq 0x8190
movq %rax, %r14
leaq -0x90(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x13e97(%rip), %rsi     # 0x20212
leaq 0x13ea6(%rip), %rdx     # 0x20228
leaq -0xa0(%rbp), %rdi
callq 0x9f1e
callq 0x8060
movl (%rax), %ecx
movb $0x1, %r12b
leaq -0xa0(%rbp), %rsi
movq %r14, %rdi
movl $0x140, %edx            # imm = 0x140
callq 0xe4d8
xorl %r12d, %r12d
leaq 0x1a8ea(%rip), %rsi     # 0x26ca0
leaq 0x20c9(%rip), %rdx      # 0xe486
movq %r14, %rdi
callq 0x85b0
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0xc431
movq -0x70(%rbp), %rsi
jmp 0xc429
jmp 0xc438
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0xc431
movq -0x90(%rbp), %rsi
jmp 0xc429
jmp 0xc438
jmp 0xc438
jmp 0xc438
jmp 0xc438
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0xc431
movq -0xb0(%rbp), %rsi
jmp 0xc429
jmp 0xc438
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0xc431
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x8310
testb %r12b, %r12b
jne 0xc43b
jmp 0xc443
movq %rax, %rbx
movq %r14, %rdi
callq 0x8240
movq %rbx, %rdi
callq 0x85f0
nop