#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct termios {
  int c_cflag;
  int c_iflag;
  int *c_cc;
};
typedef int /*<<< orphan*/ newtio;

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B300;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B600;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS7;
int CS8;
int CSIZE;
int CSTOPB;
int INPCK;
int ISTRIP;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int Set_Opt(int fd, int nSpeed, int nBits, char nEvent, int nStop) {
  struct termios newtio, oldtio;
  if (tcgetattr(fd, &oldtio) != 0) {
    perror("Setup serial");
    return -1;
  }
  memset(&newtio, 0, sizeof(newtio));
  newtio.c_cflag |= CLOCAL | CREAD;
  newtio.c_cflag &= ~CSIZE;
  switch (nSpeed) {
  case 300:
    cfsetispeed(&newtio, B300);
    cfsetospeed(&newtio, B300);
    break;
  case 600:
    cfsetispeed(&newtio, B600);
    cfsetospeed(&newtio, B600);
    break;
  case 1200:
    cfsetispeed(&newtio, B1200);
    cfsetospeed(&newtio, B1200);
    break;
  case 2400:
    cfsetispeed(&newtio, B2400);
    cfsetospeed(&newtio, B2400);
    break;
  case 4800:
    cfsetispeed(&newtio, B4800);
    cfsetospeed(&newtio, B4800);
    break;
  case 9600:
    cfsetispeed(&newtio, B9600);
    cfsetospeed(&newtio, B9600);
    break;
  case 19200:
    cfsetispeed(&newtio, B19200);
    cfsetospeed(&newtio, B19200);
    break;
  case 38400:
    cfsetispeed(&newtio, B38400);
    cfsetospeed(&newtio, B38400);
    break;
  case 57600:
    cfsetispeed(&newtio, B57600);
    cfsetospeed(&newtio, B57600);
    break;
  case 115200:
    cfsetispeed(&newtio, B115200);
    cfsetospeed(&newtio, B115200);
    break;
  default:
    cfsetispeed(&newtio, B9600);
    cfsetospeed(&newtio, B9600);
    break;
  }
  switch (nBits) {
  case 7:
    newtio.c_cflag |= CS7;
    break;
  case 8:
    newtio.c_cflag |= CS8;
    break;
  default:
    newtio.c_cflag |= CS8;
    break;
  }
  switch (nEvent) {
  case 'O':
  case 'o':
    newtio.c_cflag |= PARENB;
    newtio.c_cflag |= PARODD;
    newtio.c_iflag |= (INPCK | ISTRIP);
    break;
  case 'E':
  case 'e':
    newtio.c_iflag |= (INPCK | ISTRIP);
    newtio.c_cflag |= PARENB;
    newtio.c_cflag &= ~PARODD;
    break;
  case 'N':
  case 'n':
    newtio.c_cflag &= ~PARENB;
    break;
  default:
    newtio.c_cflag &= ~PARENB;
    break;
  }
  switch (nStop) {
  case 1:
    newtio.c_cflag &= ~CSTOPB;
    break;
  case 2:
    newtio.c_cflag |= CSTOPB;
    break;
  default:
    newtio.c_cflag &= ~CSTOPB;
    break;
  }
  newtio.c_cc[VTIME] = 2;
  newtio.c_cc[VMIN] = 0;
  tcflush(fd, TCIFLUSH);
  if ((tcsetattr(fd, TCSANOW, &newtio)) != 0) {
    perror("Com set error");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<Set_Opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
je     11b8 <Set_Opt+0x48>
lea    0xe59(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b9 <Set_Opt+0x549>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%ecx
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x28(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x12c,%eax
je     12b8 <Set_Opt+0x148>
jmp    120d <Set_Opt+0x9d>
mov    -0x3c(%rbp),%eax
sub    $0x258,%eax
je     12e1 <Set_Opt+0x171>
jmp    1220 <Set_Opt+0xb0>
mov    -0x3c(%rbp),%eax
sub    $0x4b0,%eax
je     130a <Set_Opt+0x19a>
jmp    1233 <Set_Opt+0xc3>
mov    -0x3c(%rbp),%eax
sub    $0x960,%eax
je     1333 <Set_Opt+0x1c3>
jmp    1246 <Set_Opt+0xd6>
mov    -0x3c(%rbp),%eax
sub    $0x12c0,%eax
je     135c <Set_Opt+0x1ec>
jmp    1259 <Set_Opt+0xe9>
mov    -0x3c(%rbp),%eax
sub    $0x2580,%eax
je     1385 <Set_Opt+0x215>
jmp    126c <Set_Opt+0xfc>
mov    -0x3c(%rbp),%eax
sub    $0x4b00,%eax
je     13ae <Set_Opt+0x23e>
jmp    127f <Set_Opt+0x10f>
mov    -0x3c(%rbp),%eax
sub    $0x9600,%eax
je     13d7 <Set_Opt+0x267>
jmp    1292 <Set_Opt+0x122>
mov    -0x3c(%rbp),%eax
sub    $0xe100,%eax
je     1400 <Set_Opt+0x290>
jmp    12a5 <Set_Opt+0x135>
mov    -0x3c(%rbp),%eax
sub    $0x1c200,%eax
je     1429 <Set_Opt+0x2b9>
jmp    1452 <Set_Opt+0x2e2>
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2c47(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2c36(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2c5d(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c4b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2c2c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2c3b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2b42(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b30(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2b81(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b6f(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2b20(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b0e(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1476 <Set_Opt+0x306>
mov    0x2b5f(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x7,%eax
je     149b <Set_Opt+0x32b>
jmp    148a <Set_Opt+0x31a>
mov    -0x40(%rbp),%eax
sub    $0x8,%eax
je     14af <Set_Opt+0x33f>
jmp    14c3 <Set_Opt+0x353>
mov    0x2a8e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    14d2 <Set_Opt+0x362>
mov    0x2aea(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    14d2 <Set_Opt+0x362>
mov    0x2ad6(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x45,%eax
je     1577 <Set_Opt+0x407>
jmp    14e7 <Set_Opt+0x377>
mov    -0x44(%rbp),%eax
sub    $0x4e,%eax
je     15b5 <Set_Opt+0x445>
jmp    14f8 <Set_Opt+0x388>
mov    -0x44(%rbp),%eax
sub    $0x4f,%eax
je     153c <Set_Opt+0x3cc>
jmp    1509 <Set_Opt+0x399>
mov    -0x44(%rbp),%eax
sub    $0x65,%eax
je     1577 <Set_Opt+0x407>
jmp    151a <Set_Opt+0x3aa>
mov    -0x44(%rbp),%eax
sub    $0x6e,%eax
je     15b5 <Set_Opt+0x445>
jmp    152b <Set_Opt+0x3bb>
mov    -0x44(%rbp),%eax
sub    $0x6f,%eax
jne    15cc <Set_Opt+0x45c>
jmp    153c <Set_Opt+0x3cc>
mov    0x2a9d(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2a76(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2a07(%rip),%rax
mov    (%rax),%eax
mov    0x29f6(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    15de <Set_Opt+0x46e>
mov    0x29ea(%rip),%rax
mov    (%rax),%eax
mov    0x29d9(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2a4a(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2a23(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    15de <Set_Opt+0x46e>
mov    0x2a24(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    15de <Set_Opt+0x46e>
mov    0x2a0d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x48(%rbp)
sub    $0x1,%eax
je     1603 <Set_Opt+0x493>
jmp    15f2 <Set_Opt+0x482>
mov    -0x48(%rbp),%eax
sub    $0x2,%eax
je     161a <Set_Opt+0x4aa>
jmp    162e <Set_Opt+0x4be>
mov    0x292e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1640 <Set_Opt+0x4d0>
mov    0x2917(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1640 <Set_Opt+0x4d0>
mov    0x2903(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x28fd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x2,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2938(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2904(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2953(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     16b2 <Set_Opt+0x542>
lea    0x96c(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b9 <Set_Opt+0x549>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Set_Opt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %esi,%ebx
mov    %edi,%r12d
lea    0x18(%rsp),%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
jne    140b <Set_Opt+0x29b>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2d71(%rip),%rax
mov    0x2dea(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,0x8(%rsp)
cmp    $0x257f,%ebx
jg     1213 <Set_Opt+0xa3>
cmp    $0x4af,%ebx
jle    123c <Set_Opt+0xcc>
cmp    $0x4b0,%ebx
je     1277 <Set_Opt+0x107>
cmp    $0x960,%ebx
je     1280 <Set_Opt+0x110>
cmp    $0x12c0,%ebx
jne    126e <Set_Opt+0xfe>
mov    0x2db2(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
cmp    $0x95ff,%ebx
jle    1255 <Set_Opt+0xe5>
cmp    $0x9600,%ebx
je     1289 <Set_Opt+0x119>
cmp    $0xe100,%ebx
je     1292 <Set_Opt+0x122>
cmp    $0x1c200,%ebx
jne    126e <Set_Opt+0xfe>
mov    0x2d16(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
cmp    $0x12c,%ebx
je     129b <Set_Opt+0x12b>
cmp    $0x258,%ebx
jne    126e <Set_Opt+0xfe>
mov    0x2d7d(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
cmp    $0x2580,%ebx
je     126e <Set_Opt+0xfe>
cmp    $0x4b00,%ebx
jne    126e <Set_Opt+0xfe>
mov    0x2d84(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
mov    0x2d43(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
mov    0x2cda(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
mov    0x2ce9(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
mov    0x2c90(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
mov    0x2cef(%rip),%rbp
jmp    12a2 <Set_Opt+0x132>
mov    0x2d0e(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
cmp    $0x8,%r13d
je     12d2 <Set_Opt+0x162>
cmp    $0x7,%r13d
jne    12d2 <Set_Opt+0x162>
mov    0x2c60(%rip),%rcx
jmp    12d9 <Set_Opt+0x169>
mov    0x2cc7(%rip),%rcx
mov    0x8(%rsp),%eax
or     (%rcx),%eax
movsbl %r15b,%ecx
add    $0xffffffbb,%ecx
cmp    $0x2a,%ecx
ja     1354 <Set_Opt+0x1e4>
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     135d <Set_Opt+0x1ed>
movabs $0x20000000200,%rdx
bt     %rcx,%rdx
jb     1354 <Set_Opt+0x1e4>
movabs $0x40000000400,%rdx
bt     %rcx,%rdx
jae    1354 <Set_Opt+0x1e4>
mov    0x2cbe(%rip),%rcx
or     (%rcx),%eax
mov    0x2c9d(%rip),%rcx
or     (%rcx),%eax
mov    0x2c34(%rip),%rcx
mov    0x2c25(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     %edx,0xc(%rsp)
cmp    $0x2,%r14d
jne    138f <Set_Opt+0x21f>
mov    0x2be8(%rip),%rcx
or     (%rcx),%eax
jmp    13a0 <Set_Opt+0x230>
mov    0x2c85(%rip),%rcx
jmp    1383 <Set_Opt+0x213>
mov    0x2c04(%rip),%rcx
mov    0x2bf5(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     %edx,0xc(%rsp)
mov    0x2c66(%rip),%rcx
or     (%rcx),%eax
mov    0x2c45(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
cmp    $0x2,%r14d
je     1349 <Set_Opt+0x1d9>
cmp    $0x1,%r14d
mov    0x2b9e(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2b98(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x2,(%rax,%rcx,4)
mov    0x2bd7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2ba6(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1040 <tcflush@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
call   1070 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1414 <Set_Opt+0x2a4>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbee(%rip),%rdi
jmp    141b <Set_Opt+0x2ab>
lea    0xbf2(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    13fc <Set_Opt+0x28c>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32* }
@.str = [13 x i8] c"Setup serial\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"Com set error\00"
define i32 @Set_Opt(i32 %0, i32 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca %struct.termios
%13 = alloca %struct.termios
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8 %3, i8* %10
store i32 %4, i32* %11
%14 = load i32, i32* %7
%15 = call i64 @tcgetattr(i32 %14, %struct.termios* %13)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %189
19: ; preds = %5
%20 = call i32 @memset(%struct.termios* %12, i32 0, i32 16)
%21 = load i32, i32* @CLOCAL
%22 = load i32, i32* @CREAD
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @CSIZE
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* %8
switch i32 %32, label %83 [
i32 300, label %33
i32 600, label %38
i32 1200, label %43
i32 2400, label %48
i32 4800, label %53
i32 9600, label %58
i32 19200, label %63
i32 38400, label %68
i32 57600, label %73
i32 115200, label %78
]
33: ; preds = %19
%34 = load i32, i32* @B300
%35 = call i32 @cfsetispeed(%struct.termios* %12, i32 %34)
%36 = load i32, i32* @B300
%37 = call i32 @cfsetospeed(%struct.termios* %12, i32 %36)
br label %88
38: ; preds = %19
%39 = load i32, i32* @B600
%40 = call i32 @cfsetispeed(%struct.termios* %12, i32 %39)
%41 = load i32, i32* @B600
%42 = call i32 @cfsetospeed(%struct.termios* %12, i32 %41)
br label %88
43: ; preds = %19
%44 = load i32, i32* @B1200
%45 = call i32 @cfsetispeed(%struct.termios* %12, i32 %44)
%46 = load i32, i32* @B1200
%47 = call i32 @cfsetospeed(%struct.termios* %12, i32 %46)
br label %88
48: ; preds = %19
%49 = load i32, i32* @B2400
%50 = call i32 @cfsetispeed(%struct.termios* %12, i32 %49)
%51 = load i32, i32* @B2400
%52 = call i32 @cfsetospeed(%struct.termios* %12, i32 %51)
br label %88
53: ; preds = %19
%54 = load i32, i32* @B4800
%55 = call i32 @cfsetispeed(%struct.termios* %12, i32 %54)
%56 = load i32, i32* @B4800
%57 = call i32 @cfsetospeed(%struct.termios* %12, i32 %56)
br label %88
58: ; preds = %19
%59 = load i32, i32* @B9600
%60 = call i32 @cfsetispeed(%struct.termios* %12, i32 %59)
%61 = load i32, i32* @B9600
%62 = call i32 @cfsetospeed(%struct.termios* %12, i32 %61)
br label %88
63: ; preds = %19
%64 = load i32, i32* @B19200
%65 = call i32 @cfsetispeed(%struct.termios* %12, i32 %64)
%66 = load i32, i32* @B19200
%67 = call i32 @cfsetospeed(%struct.termios* %12, i32 %66)
br label %88
68: ; preds = %19
%69 = load i32, i32* @B38400
%70 = call i32 @cfsetispeed(%struct.termios* %12, i32 %69)
%71 = load i32, i32* @B38400
%72 = call i32 @cfsetospeed(%struct.termios* %12, i32 %71)
br label %88
73: ; preds = %19
%74 = load i32, i32* @B57600
%75 = call i32 @cfsetispeed(%struct.termios* %12, i32 %74)
%76 = load i32, i32* @B57600
%77 = call i32 @cfsetospeed(%struct.termios* %12, i32 %76)
br label %88
78: ; preds = %19
%79 = load i32, i32* @B115200
%80 = call i32 @cfsetispeed(%struct.termios* %12, i32 %79)
%81 = load i32, i32* @B115200
%82 = call i32 @cfsetospeed(%struct.termios* %12, i32 %81)
br label %88
83: ; preds = %19
%84 = load i32, i32* @B9600
%85 = call i32 @cfsetispeed(%struct.termios* %12, i32 %84)
%86 = load i32, i32* @B9600
%87 = call i32 @cfsetospeed(%struct.termios* %12, i32 %86)
br label %88
88: ; preds = %83, %78, %73, %68, %63, %58, %53, %48, %43, %38, %33
%89 = load i32, i32* %9
switch i32 %89, label %100 [
i32 7, label %90
i32 8, label %95
]
90: ; preds = %88
%91 = load i32, i32* @CS7
%92 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%93 = load i32, i32* %92
%94 = or i32 %93, %91
store i32 %94, i32* %92
br label %105
95: ; preds = %88
%96 = load i32, i32* @CS8
%97 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%98 = load i32, i32* %97
%99 = or i32 %98, %96
store i32 %99, i32* %97
br label %105
100: ; preds = %88
%101 = load i32, i32* @CS8
%102 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%103 = load i32, i32* %102
%104 = or i32 %103, %101
store i32 %104, i32* %102
br label %105
105: ; preds = %100, %95, %90
%106 = load i8, i8* %10
%107 = sext i8 %106 to i32
switch i32 %107, label %145 [
i32 79, label %108
i32 111, label %108
i32 69, label %123
i32 101, label %123
i32 78, label %139
i32 110, label %139
]
108: ; preds = %105, %105
%109 = load i32, i32* @PARENB
%110 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%111 = load i32, i32* %110
%112 = or i32 %111, %109
store i32 %112, i32* %110
%113 = load i32, i32* @PARODD
%114 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%115 = load i32, i32* %114
%116 = or i32 %115, %113
store i32 %116, i32* %114
%117 = load i32, i32* @INPCK
%118 = load i32, i32* @ISTRIP
%119 = or i32 %117, %118
%120 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%121 = load i32, i32* %120
%122 = or i32 %121, %119
store i32 %122, i32* %120
br label %151
123: ; preds = %105, %105
%124 = load i32, i32* @INPCK
%125 = load i32, i32* @ISTRIP
%126 = or i32 %124, %125
%127 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%128 = load i32, i32* %127
%129 = or i32 %128, %126
store i32 %129, i32* %127
%130 = load i32, i32* @PARENB
%131 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%132 = load i32, i32* %131
%133 = or i32 %132, %130
store i32 %133, i32* %131
%134 = load i32, i32* @PARODD
%135 = xor i32 %134, -1
%136 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%137 = load i32, i32* %136
%138 = and i32 %137, %135
store i32 %138, i32* %136
br label %151
139: ; preds = %105, %105
%140 = load i32, i32* @PARENB
%141 = xor i32 %140, -1
%142 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%143 = load i32, i32* %142
%144 = and i32 %143, %141
store i32 %144, i32* %142
br label %151
145: ; preds = %105
%146 = load i32, i32* @PARENB
%147 = xor i32 %146, -1
%148 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%149 = load i32, i32* %148
%150 = and i32 %149, %147
store i32 %150, i32* %148
br label %151
151: ; preds = %145, %139, %123, %108
%152 = load i32, i32* %11
switch i32 %152, label %164 [
i32 1, label %153
i32 2, label %159
]
153: ; preds = %151
%154 = load i32, i32* @CSTOPB
%155 = xor i32 %154, -1
%156 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%157 = load i32, i32* %156
%158 = and i32 %157, %155
store i32 %158, i32* %156
br label %170
159: ; preds = %151
%160 = load i32, i32* @CSTOPB
%161 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%162 = load i32, i32* %161
%163 = or i32 %162, %160
store i32 %163, i32* %161
br label %170
164: ; preds = %151
%165 = load i32, i32* @CSTOPB
%166 = xor i32 %165, -1
%167 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%168 = load i32, i32* %167
%169 = and i32 %168, %166
store i32 %169, i32* %167
br label %170
170: ; preds = %164, %159, %153
%171 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%172 = load i32*, i32** %171
%173 = load i64, i64* @VTIME
%174 = getelementptr inbounds i32, i32* %172, i64 %173
store i32 2, i32* %174
%175 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%176 = load i32*, i32** %175
%177 = load i64, i64* @VMIN
%178 = getelementptr inbounds i32, i32* %176, i64 %177
store i32 0, i32* %178
%179 = load i32, i32* %7
%180 = load i32, i32* @TCIFLUSH
%181 = call i32 @tcflush(i32 %179, i32 %180)
%182 = load i32, i32* %7
%183 = load i32, i32* @TCSANOW
%184 = call i64 @tcsetattr(i32 %182, i32 %183, %struct.termios* %12)
%185 = icmp ne i64 %184, 0
br i1 %185, label %186, label %188
186: ; preds = %170
%187 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %189
188: ; preds = %170
store i32 0, i32* %6
br label %189
189: ; preds = %188, %186, %17
%190 = load i32, i32* %6
ret i32 %190
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32* }
@.str = [13 x i8] c"Setup serial\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"Com set error\00"
define i32 @Set_Opt(i32 %0, i32 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = bitcast %struct.termios* %6 to i8*
%9 = bitcast %struct.termios* %7 to i8*
%10 = call i64 @tcgetattr(i32 %0, %struct.termios* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %110
12: ; preds = %5
%13 = call i32 @memset(%struct.termios* %6, i32 0, i32 16)
%14 = load i32, i32* @CLOCAL
%15 = load i32, i32* @CREAD
%16 = or i32 %15, %14
%17 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 0
%18 = load i32, i32* %17
%19 = or i32 %16, %18
%20 = load i32, i32* @CSIZE
%21 = xor i32 %20, -1
%22 = and i32 %19, %21
store i32 %22, i32* %17
switch i32 %1, label %32 [
i32 300, label %33
i32 600, label %23
i32 1200, label %24
i32 2400, label %25
i32 4800, label %26
i32 9600, label %27
i32 19200, label %28
i32 38400, label %29
i32 57600, label %30
i32 115200, label %31
]
23: ; preds = %12
br label %33
24: ; preds = %12
br label %33
25: ; preds = %12
br label %33
26: ; preds = %12
br label %33
27: ; preds = %12
br label %33
28: ; preds = %12
br label %33
29: ; preds = %12
br label %33
30: ; preds = %12
br label %33
31: ; preds = %12
br label %33
32: ; preds = %12
br label %33
33: ; preds = %12, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23
%34 = phi i32* [ @B9600, %32 ], [ @B115200, %31 ], [ @B57600, %30 ], [ @B38400, %29 ], [ @B19200, %28 ], [ @B9600, %27 ], [ @B4800, %26 ], [ @B2400, %25 ], [ @B1200, %24 ], [ @B600, %23 ], [ @B300, %12 ]
%35 = load i32, i32* %34
%36 = call i32 @cfsetispeed(%struct.termios* %6, i32 %35)
%37 = load i32, i32* %34
%38 = call i32 @cfsetospeed(%struct.termios* %6, i32 %37)
switch i32 %2, label %47 [
i32 7, label %39
i32 8, label %43
]
39: ; preds = %33
%40 = load i32, i32* @CS7
%41 = load i32, i32* %17
%42 = or i32 %41, %40
br label %51
43: ; preds = %33
%44 = load i32, i32* @CS8
%45 = load i32, i32* %17
%46 = or i32 %45, %44
br label %51
47: ; preds = %33
%48 = load i32, i32* @CS8
%49 = load i32, i32* %17
%50 = or i32 %49, %48
br label %51
51: ; preds = %47, %43, %39
%52 = phi i32 [ %50, %47 ], [ %46, %43 ], [ %42, %39 ]
%53 = sext i8 %3 to i32
switch i32 %53, label %81 [
i32 79, label %54
i32 111, label %54
i32 69, label %65
i32 101, label %65
i32 78, label %77
i32 110, label %77
]
54: ; preds = %51, %51
%55 = load i32, i32* @PARENB
%56 = or i32 %52, %55
%57 = load i32, i32* @PARODD
%58 = or i32 %57, %56
%59 = load i32, i32* @INPCK
%60 = load i32, i32* @ISTRIP
%61 = or i32 %60, %59
%62 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 1
%63 = load i32, i32* %62
%64 = or i32 %61, %63
store i32 %64, i32* %62
br label %85
65: ; preds = %51, %51
%66 = load i32, i32* @INPCK
%67 = load i32, i32* @ISTRIP
%68 = or i32 %67, %66
%69 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 1
%70 = load i32, i32* %69
%71 = or i32 %68, %70
store i32 %71, i32* %69
%72 = load i32, i32* @PARENB
%73 = or i32 %52, %72
%74 = load i32, i32* @PARODD
%75 = xor i32 %74, -1
%76 = and i32 %73, %75
br label %85
77: ; preds = %51, %51
%78 = load i32, i32* @PARENB
%79 = xor i32 %78, -1
%80 = and i32 %52, %79
br label %85
81: ; preds = %51
%82 = load i32, i32* @PARENB
%83 = xor i32 %82, -1
%84 = and i32 %52, %83
br label %85
85: ; preds = %81, %77, %65, %54
%86 = phi i32 [ %84, %81 ], [ %80, %77 ], [ %76, %65 ], [ %58, %54 ]
switch i32 %4, label %94 [
i32 1, label %87
i32 2, label %91
]
87: ; preds = %85
%88 = load i32, i32* @CSTOPB
%89 = xor i32 %88, -1
%90 = and i32 %86, %89
store i32 %90, i32* %17
br label %98
91: ; preds = %85
%92 = load i32, i32* @CSTOPB
%93 = or i32 %86, %92
store i32 %93, i32* %17
br label %98
94: ; preds = %85
%95 = load i32, i32* @CSTOPB
%96 = xor i32 %95, -1
%97 = and i32 %86, %96
store i32 %97, i32* %17
br label %98
98: ; preds = %94, %91, %87
%99 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 2
%100 = load i32*, i32** %99
%101 = load i64, i64* @VTIME
%102 = getelementptr inbounds i32, i32* %100, i64 %101
store i32 2, i32* %102
%103 = load i64, i64* @VMIN
%104 = getelementptr inbounds i32, i32* %100, i64 %103
store i32 0, i32* %104
%105 = load i32, i32* @TCIFLUSH
%106 = call i32 @tcflush(i32 %0, i32 %105)
%107 = load i32, i32* @TCSANOW
%108 = call i64 @tcsetattr(i32 %0, i32 %107, %struct.termios* %6)
%109 = icmp eq i64 %108, 0
br i1 %109, label %113, label %110
110: ; preds = %98, %5
%111 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %98 ]
%112 = call i32 @perror(i8* %111)
br label %113
113: ; preds = %110, %98
%114 = phi i32 [ 0, %98 ], [ -1, %110 ]
ret i32 %114
}