// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
movl 0x28(%rdi), %edi
cmpl $-0x1, %edi
je 0xb4df
leaq -0x58(%rbp), %rsi
callq 0x8390
cmpl $-0x1, %eax
je 0xb540
orl $0x880, -0x50(%rbp)     # imm = 0x880
andl $0xffff7f84, -0x4c(%rbp) # imm = 0xFFFF7F84
andb $-0x2, -0x54(%rbp)
andl $0xfffffc36, -0x58(%rbp) # imm = 0xFFFFFC36
movq 0x48(%rbx), %rax
testq %rax, %rax
je 0xb308
cmpq $0x3d0900, %rax         # imm = 0x3D0900
je 0xb31d
cmpq $0x4b, %rax
je 0xb319
cmpq $0x6e, %rax
je 0xb1a4
cmpq $0x86, %rax
je 0xb325
cmpq $0x96, %rax
je 0xb1e9
cmpq $0xc8, %rax
je 0xb1f0
cmpq $0x12c, %rax            # imm = 0x12C
je 0xb315
cmpq $0x258, %rax            # imm = 0x258
je 0xb30d
cmpq $0x4b0, %rax            # imm = 0x4B0
je 0xb2e0
cmpq $0x708, %rax            # imm = 0x708
je 0xb2d4
cmpq $0x960, %rax            # imm = 0x960
je 0xb311
cmpq $0x12c0, %rax           # imm = 0x12C0
je 0xb2f4
cmpq $0x2580, %rax           # imm = 0x2580
je 0xb2d0
cmpq $0x4b00, %rax           # imm = 0x4B00
je 0xb1ab
cmpq $0x9600, %rax           # imm = 0x9600
je 0xb202
cmpq $0xe100, %rax           # imm = 0xE100
je 0xb1b2
cmpq $0x1c200, %rax          # imm = 0x1C200
je 0xb2e4
cmpq $0x38400, %rax          # imm = 0x38400
je 0xb1d3
cmpq $0x70800, %rax          # imm = 0x70800
je 0xb1bd
cmpq $0x8ca00, %rax          # imm = 0x8CA00
je 0xb2f8
cmpq $0xe1000, %rax          # imm = 0xE1000
je 0xb1de
cmpq $0xf4240, %rax          # imm = 0xF4240
je 0xb300
cmpq $0x119400, %rax         # imm = 0x119400
je 0xb214
cmpq $0x16e360, %rax         # imm = 0x16E360
je 0xb2ec
cmpq $0x1e8480, %rax         # imm = 0x1E8480
je 0xb2d8
cmpq $0x2625a0, %rax         # imm = 0x2625A0
je 0xb1c8
cmpq $0x2dc6c0, %rax         # imm = 0x2DC6C0
je 0xb209
cmpq $0x3567e0, %rax         # imm = 0x3567E0
je 0xb1f7
cmpq $0x32, %rax
jne 0xb21f
pushq $0x1
jmp 0xb327
pushq $0x3
jmp 0xb327
pushq $0xe
jmp 0xb327
movl $0x1001, %r14d          # imm = 0x1001
jmp 0xb329
movl $0x1004, %r14d          # imm = 0x1004
jmp 0xb329
movl $0x100c, %r14d          # imm = 0x100C
jmp 0xb329
movl $0x1003, %r14d          # imm = 0x1003
jmp 0xb329
movl $0x1007, %r14d          # imm = 0x1007
jmp 0xb329
pushq $0x5
jmp 0xb327
pushq $0x6
jmp 0xb327
movl $0x100e, %r14d          # imm = 0x100E
jmp 0xb329
pushq $0xf
jmp 0xb327
movl $0x100d, %r14d          # imm = 0x100D
jmp 0xb329
movl $0x1009, %r14d          # imm = 0x1009
jmp 0xb329
movl 0x28(%rbx), %edi
leaq -0x120(%rbp), %rdx
movl $0x541e, %esi           # imm = 0x541E
xorl %eax, %eax
callq 0x8470
cmpl $-0x1, %eax
je 0xb609
leaq -0x120(%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 0xb343
pushq $0x58
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xcf88(%rip), %rsi      # 0x18212
leaq -0x78(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x95bc
callq 0x8050
movl (%rax), %ecx
movb $0x1, %r15b
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
movl $0x14a, %edx            # imm = 0x14A
callq 0xd164
xorl %r15d, %r15d
leaq 0x14a0c(%rip), %rsi     # 0x1fcc8
leaq 0x1e6d(%rip), %rdx      # 0xd130
movq %rbx, %rdi
callq 0x8590
jmp 0xb662
pushq $0xd
jmp 0xb327
pushq $0xa
jmp 0xb327
movl $0x100b, %r14d          # imm = 0x100B
jmp 0xb329
pushq $0x9
jmp 0xb327
movl $0x1002, %r14d          # imm = 0x1002
jmp 0xb329
movl $0x100a, %r14d          # imm = 0x100A
jmp 0xb329
pushq $0xc
jmp 0xb327
movl $0x1006, %r14d          # imm = 0x1006
jmp 0xb329
movl $0x1008, %r14d          # imm = 0x1008
jmp 0xb329
xorl %r14d, %r14d
jmp 0xb329
pushq $0x8
jmp 0xb327
pushq $0xb
jmp 0xb327
pushq $0x7
jmp 0xb327
pushq $0x2
jmp 0xb327
movl $0x100f, %r14d          # imm = 0x100F
jmp 0xb329
pushq $0x4
popq %r14
leaq -0x58(%rbp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x81e0
movq %r15, %rdi
movl %r14d, %esi
callq 0x8370
movl -0x50(%rbp), %ecx
movl %ecx, %eax
andl $-0x31, %eax
movl %eax, -0x50(%rbp)
movl 0x58(%rbx), %edx
addl $-0x5, %edx
cmpl $0x3, %edx
ja 0xb5bd
leaq 0xce3c(%rip), %rsi      # 0x181a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
orl $0x10, %eax
jmp 0xb37c
orl $0x20, %eax
jmp 0xb37c
orl $0x30, %ecx
movl %ecx, %eax
movl %eax, -0x50(%rbp)
movl 0x5c(%rbx), %ecx
cmpl $0x3, %ecx
je 0xb39a
cmpl $0x2, %ecx
je 0xb39a
cmpl $0x1, %ecx
jne 0xb5a1
andl $-0x41, %eax
jmp 0xb39d
orl $0x40, %eax
movl %eax, -0x50(%rbp)
movl -0x58(%rbp), %ecx
movl %ecx, %edx
andl $-0x31, %edx
movl %edx, -0x58(%rbp)
movl 0x54(%rbx), %esi
cmpq $0x4, %rsi
ja 0xb5d9
leaq 0xcdf1(%rip), %rdi      # 0x181b0
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
andl $0xfffffcff, %eax       # imm = 0xFFFFFCFF
jmp 0xb3f3
andl $0xbffffcff, %eax       # imm = 0xBFFFFCFF
orl $0x40000100, %eax       # imm = 0x40000100
jmp 0xb3f3
andl $0xfffffcff, %eax       # imm = 0xFFFFFCFF
orl $0x100, %eax            # imm = 0x100
jmp 0xb3f3
orl $0x40000300, %eax       # imm = 0x40000300
jmp 0xb3f3
orl $0x300, %eax            # imm = 0x300
movl 0x60(%rbx), %esi
testl %esi, %esi
je 0xb41f
cmpl $0x2, %esi
je 0xb416
cmpl $0x1, %esi
jne 0xb430
movw $0x1, 0x2d(%rbx)
orl $0x1400, %edx           # imm = 0x1400
xorl %esi, %esi
movl %edx, %ecx
jmp 0xb44a
movl $0x80000000, %esi       # imm = 0x80000000
movb $0x1, %dl
jmp 0xb421
xorl %edx, %edx
movb $0x0, 0x2d(%rbx)
movb %dl, 0x2e(%rbx)
andl $0xffffe3cf, %ecx       # imm = 0xFFFFE3CF
jmp 0xb44a
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 -0x58(%rbp), %rdx
movl %ecx, (%rdx)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %esi, %eax
movl %eax, 0x8(%rdx)
andw $0x0, 0x16(%rdx)
movl 0x28(%rbx), %edi
xorl %esi, %esi
callq 0x83f0
movsd 0x48(%rbx), %xmm0
unpcklps 0xcd0b(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xcd13(%rip), %xmm0     # 0x18190
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0xccdf(%rip), %xmm0     # 0x18170
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 0xb4ce
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
mulsd 0xccb3(%rip), %xmm0     # 0x18178
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x50(%rbx)
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x58
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xcd21(%rip), %rsi      # 0x18212
leaq -0xd8(%rbp), %rdi
leaq -0x120(%rbp), %rdx
callq 0x95bc
movb $0x1, %r15b
leaq 0xcd37(%rip), %rcx      # 0x18245
leaq -0xd8(%rbp), %rsi
movq %rbx, %rdi
movl $0xa5, %edx
callq 0xcff0
xorl %r15d, %r15d
leaq 0x1479c(%rip), %rsi     # 0x1fcc8
leaq 0x1bfd(%rip), %rdx      # 0xd130
movq %rbx, %rdi
callq 0x8590
jmp 0xb662
pushq $0x58
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xccc0(%rip), %rsi      # 0x18212
leaq -0xb8(%rbp), %rdi
leaq -0x120(%rbp), %rdx
callq 0x95bc
movb $0x1, %r15b
leaq 0xcd08(%rip), %rcx      # 0x18277
leaq -0xb8(%rbp), %rsi
movq %rbx, %rdi
movl $0xab, %edx
callq 0xcff0
xorl %r15d, %r15d
leaq 0x1473b(%rip), %rsi     # 0x1fcc8
leaq 0x1b9c(%rip), %rdx      # 0xd130
movq %rbx, %rdi
callq 0x8590
jmp 0xb662
pushq $0x10
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xcce1(%rip), %rsi      # 0x18294
movq %rax, %rdi
callq 0x8620
jmp 0xb5f3
pushq $0x10
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xccb4(%rip), %rsi      # 0x18283
movq %rax, %rdi
callq 0x8620
jmp 0xb5f3
pushq $0x10
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xccba(%rip), %rsi      # 0x182a5
movq %rax, %rdi
callq 0x8620
movq 0x149de(%rip), %rsi     # 0x1ffd8
movq 0x149c7(%rip), %rdx     # 0x1ffc8
movq %rbx, %rdi
callq 0x8590
pushq $0x58
popq %rdi
callq 0x81a0
movq %rax, %rbx
leaq 0xcbf7(%rip), %rsi      # 0x18212
leaq -0x98(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x95bc
callq 0x8050
movl (%rax), %ecx
movb $0x1, %r15b
leaq -0x98(%rbp), %rsi
movq %rbx, %rdi
movl $0x140, %edx            # imm = 0x140
callq 0xd164
xorl %r15d, %r15d
leaq 0x14675(%rip), %rsi     # 0x1fcc8
leaq 0x1ad6(%rip), %rdx      # 0xd130
movq %rbx, %rdi
callq 0x8590
movq %rax, %r14
leaq -0x78(%rbp), %rdi
jmp 0xb699
jmp 0xb6a5
movq %rax, %r14
leaq -0x98(%rbp), %rdi
jmp 0xb699
jmp 0xb6a5
jmp 0xb6a5
jmp 0xb6a5
jmp 0xb6a5
movq %rax, %r14
leaq -0xb8(%rbp), %rdi
jmp 0xb699
jmp 0xb6a5
movq %rax, %r14
leaq -0xd8(%rbp), %rdi
callq 0x8170
testb %r15b, %r15b
jne 0xb6a8
jmp 0xb6b0
movq %rax, %r14
movq %rbx, %rdi
callq 0x8240
movq %r14, %rdi
callq 0x85c0