#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_lflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
int /*<<< orphan*/ B110;
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B134;
int /*<<< orphan*/ B150;
int /*<<< orphan*/ B1800;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B200;
int /*<<< orphan*/ B230400;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B300;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B50;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B600;
int /*<<< orphan*/ B75;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ISIG;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int TCSAFLUSH;
int TCSANOW;
int /*<<< orphan*/ TIOCMGET;
int /*<<< orphan*/ TIOCMSET;
int TIOCM_DTR;
int TIOCM_RTS;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int, struct termios *);
int /*<<< orphan*/ usleep(int);
int serialOpen(char *device, int baud) {
  struct termios options;
  speed_t myBaud;
  int status, fd;
  switch (baud) {
  case 50:
    myBaud = B50;
    break;
  case 75:
    myBaud = B75;
    break;
  case 110:
    myBaud = B110;
    break;
  case 134:
    myBaud = B134;
    break;
  case 150:
    myBaud = B150;
    break;
  case 200:
    myBaud = B200;
    break;
  case 300:
    myBaud = B300;
    break;
  case 600:
    myBaud = B600;
    break;
  case 1200:
    myBaud = B1200;
    break;
  case 1800:
    myBaud = B1800;
    break;
  case 2400:
    myBaud = B2400;
    break;
  case 9600:
    myBaud = B9600;
    break;
  case 19200:
    myBaud = B19200;
    break;
  case 38400:
    myBaud = B38400;
    break;
  case 57600:
    myBaud = B57600;
    break;
  case 115200:
    myBaud = B115200;
    break;
  case 230400:
    myBaud = B230400;
    break;
  default:
    return -2;
  }
  if ((fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY)) == -1) {
    return -1;
  }
  fcntl(fd, F_SETFL, O_RDWR);
  tcgetattr(fd, &options);
  cfmakeraw(&options);
  cfsetispeed(&options, myBaud);
  cfsetospeed(&options, myBaud);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  options.c_cc[VMIN] = 0;
  options.c_cc[VTIME] = 100;
  tcsetattr(fd, TCSANOW | TCSAFLUSH, &options);
  ioctl(fd, TIOCMGET, &status);
  status |= TIOCM_DTR;
  status |= TIOCM_RTS;
  ioctl(fd, TIOCMSET, &status);
  usleep(10000);
  return fd;
}


x86 assembly (clang, -O0):
<serialOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x32,%eax
je     22df <serialOpen+0x14f>
jmp    21b3 <serialOpen+0x23>
mov    -0x40(%rbp),%eax
sub    $0x4b,%eax
je     22f0 <serialOpen+0x160>
jmp    21c4 <serialOpen+0x34>
mov    -0x40(%rbp),%eax
sub    $0x6e,%eax
je     2301 <serialOpen+0x171>
jmp    21d5 <serialOpen+0x45>
mov    -0x40(%rbp),%eax
sub    $0x86,%eax
je     2312 <serialOpen+0x182>
jmp    21e8 <serialOpen+0x58>
mov    -0x40(%rbp),%eax
sub    $0x96,%eax
je     2323 <serialOpen+0x193>
jmp    21fb <serialOpen+0x6b>
mov    -0x40(%rbp),%eax
sub    $0xc8,%eax
je     2334 <serialOpen+0x1a4>
jmp    220e <serialOpen+0x7e>
mov    -0x40(%rbp),%eax
sub    $0x12c,%eax
je     2345 <serialOpen+0x1b5>
jmp    2221 <serialOpen+0x91>
mov    -0x40(%rbp),%eax
sub    $0x258,%eax
je     2356 <serialOpen+0x1c6>
jmp    2234 <serialOpen+0xa4>
mov    -0x40(%rbp),%eax
sub    $0x4b0,%eax
je     2367 <serialOpen+0x1d7>
jmp    2247 <serialOpen+0xb7>
mov    -0x40(%rbp),%eax
sub    $0x708,%eax
je     2378 <serialOpen+0x1e8>
jmp    225a <serialOpen+0xca>
mov    -0x40(%rbp),%eax
sub    $0x960,%eax
je     2389 <serialOpen+0x1f9>
jmp    226d <serialOpen+0xdd>
mov    -0x40(%rbp),%eax
sub    $0x2580,%eax
je     239a <serialOpen+0x20a>
jmp    2280 <serialOpen+0xf0>
mov    -0x40(%rbp),%eax
sub    $0x4b00,%eax
je     23ab <serialOpen+0x21b>
jmp    2293 <serialOpen+0x103>
mov    -0x40(%rbp),%eax
sub    $0x9600,%eax
je     23bc <serialOpen+0x22c>
jmp    22a6 <serialOpen+0x116>
mov    -0x40(%rbp),%eax
sub    $0xe100,%eax
je     23cd <serialOpen+0x23d>
jmp    22b9 <serialOpen+0x129>
mov    -0x40(%rbp),%eax
sub    $0x1c200,%eax
je     23de <serialOpen+0x24e>
jmp    22cc <serialOpen+0x13c>
mov    -0x40(%rbp),%eax
sub    $0x38400,%eax
je     23ef <serialOpen+0x25f>
jmp    2400 <serialOpen+0x270>
mov    0x2c72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2c5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2bc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2c05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2c14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2b72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2b91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2b70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2bc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2add(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2b54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2af3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
mov    0x2ac2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    240c <serialOpen+0x27c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    25cb <serialOpen+0x43b>
mov    -0x10(%rbp),%rdi
mov    0x2bc9(%rip),%rax
mov    (%rax),%esi
mov    0x2ae8(%rip),%rax
or     (%rax),%esi
mov    0x2abf(%rip),%rax
or     (%rax),%esi
call   2090 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    2448 <serialOpen+0x2b8>
movl   $0xffffffff,-0x4(%rbp)
jmp    25cb <serialOpen+0x43b>
mov    -0x3c(%rbp),%edi
mov    0x2aa6(%rip),%rax
mov    (%rax),%esi
mov    0x2b85(%rip),%rax
mov    (%rax),%edx
call   2030 <fcntl@plt>
mov    -0x3c(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   2070 <tcgetattr@plt>
lea    -0x30(%rbp),%rdi
call   2060 <cfmakeraw@plt>
mov    -0x34(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   20a0 <cfsetispeed@plt>
mov    -0x34(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   2040 <cfsetospeed@plt>
mov    0x2a12(%rip),%rax
mov    (%rax),%eax
mov    0x2ab1(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2b02(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x29f0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2a5e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2a64(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x29d5(%rip),%rax
mov    (%rax),%eax
mov    0x2a94(%rip),%rcx
or     (%rcx),%eax
mov    0x2a83(%rip),%rcx
or     (%rcx),%eax
mov    0x2a72(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2a98(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2a02(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2985(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x64,(%rax,%rcx,4)
mov    -0x3c(%rbp),%edi
mov    0x2a49(%rip),%rax
mov    (%rax),%esi
mov    0x2a68(%rip),%rax
or     (%rax),%esi
lea    -0x30(%rbp),%rdx
call   2080 <tcsetattr@plt>
mov    -0x3c(%rbp),%edi
mov    0x29a3(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   2050 <ioctl@plt>
mov    0x29e1(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2a02(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2a10(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   2050 <ioctl@plt>
mov    $0x2710,%edi
call   20b0 <usleep@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialOpen>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0xfffffffe,%ebx
cmp    $0x4af,%esi
jle    21e9 <serialOpen+0x59>
cmp    $0x4aff,%esi
jle    2218 <serialOpen+0x88>
cmp    $0xe0ff,%esi
jle    2278 <serialOpen+0xe8>
cmp    $0xe100,%esi
je     22f7 <serialOpen+0x167>
cmp    $0x1c200,%esi
je     2300 <serialOpen+0x170>
cmp    $0x38400,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2cd4(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x95,%esi
jg     2248 <serialOpen+0xb8>
cmp    $0x6d,%esi
jg     229c <serialOpen+0x10c>
cmp    $0x32,%esi
je     2309 <serialOpen+0x179>
cmp    $0x4b,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2db5(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x95f,%esi
jg     22bd <serialOpen+0x12d>
cmp    $0x4b0,%esi
je     2312 <serialOpen+0x182>
cmp    $0x708,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2ccd(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x12b,%esi
jg     22da <serialOpen+0x14a>
cmp    $0x96,%esi
je     231b <serialOpen+0x18b>
cmp    $0xc8,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2ccd(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x4b00,%esi
je     2324 <serialOpen+0x194>
cmp    $0x9600,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2c09(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x6e,%esi
je     232d <serialOpen+0x19d>
cmp    $0x86,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2cc0(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x960,%esi
je     2336 <serialOpen+0x1a6>
cmp    $0x2580,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2c90(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
cmp    $0x12c,%esi
je     233f <serialOpen+0x1af>
cmp    $0x258,%esi
jne    24c6 <serialOpen+0x336>
mov    0x2ca3(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2c2a(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2bd1(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2c48(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2bc7(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2bce(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2cc5(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2ca4(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2bc3(%rip),%rax
jmp    2346 <serialOpen+0x1b6>
mov    0x2c1a(%rip),%rax
mov    0x2c93(%rip),%r14
mov    0x2bb4(%rip),%rcx
mov    (%rcx),%esi
or     (%r14),%esi
mov    (%rax),%ebp
mov    0x2b86(%rip),%rax
or     (%rax),%esi
call   2090 <open@plt>
cmp    $0xffffffff,%eax
je     24c1 <serialOpen+0x331>
mov    %eax,%ebx
mov    0x2b7d(%rip),%rax
mov    (%rax),%esi
mov    (%r14),%edx
mov    %ebx,%edi
call   2030 <fcntl@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   2070 <tcgetattr@plt>
mov    %r14,%rdi
call   2060 <cfmakeraw@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   20a0 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   2040 <cfsetospeed@plt>
mov    0x2aef(%rip),%rax
mov    0x2b90(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2be1(%rip),%rax
mov    (%rax),%eax
mov    0x2ad8(%rip),%rdx
or     (%rdx),%eax
mov    0x2b4f(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2b5a(%rip),%rcx
or     (%rcx),%eax
mov    0x2ad1(%rip),%rcx
mov    0x2b92(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2b7f(%rip),%rcx
or     (%rcx),%edx
mov    %eax,0x8(%rsp)
mov    0x2b6a(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0xc(%rsp)
mov    0x2b93(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2aff(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2a86(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x64,(%rax,%rcx,4)
mov    0x2b4d(%rip),%rax
mov    0x2b6e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   2080 <tcsetattr@plt>
mov    0x2aa9(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rdx
call   2050 <ioctl@plt>
mov    0x2ae1(%rip),%rax
mov    0x4(%rsp),%ecx
or     (%rax),%ecx
mov    0x2b04(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x4(%rsp)
mov    0x2b17(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   2050 <ioctl@plt>
mov    $0x2710,%edi
call   20b0 <usleep@plt>
jmp    24c6 <serialOpen+0x336>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32 }
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B134 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = global i32 0
@B2400 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@TCSAFLUSH = global i32 0
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define i32 @serialOpen(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
switch i32 %10, label %45 [
i32 50, label %11
i32 75, label %13
i32 110, label %15
i32 134, label %17
i32 150, label %19
i32 200, label %21
i32 300, label %23
i32 600, label %25
i32 1200, label %27
i32 1800, label %29
i32 2400, label %31
i32 9600, label %33
i32 19200, label %35
i32 38400, label %37
i32 57600, label %39
i32 115200, label %41
i32 230400, label %43
]
11: ; preds = %2
%12 = load i32, i32* @B50
store i32 %12, i32* %7
br label %46
13: ; preds = %2
%14 = load i32, i32* @B75
store i32 %14, i32* %7
br label %46
15: ; preds = %2
%16 = load i32, i32* @B110
store i32 %16, i32* %7
br label %46
17: ; preds = %2
%18 = load i32, i32* @B134
store i32 %18, i32* %7
br label %46
19: ; preds = %2
%20 = load i32, i32* @B150
store i32 %20, i32* %7
br label %46
21: ; preds = %2
%22 = load i32, i32* @B200
store i32 %22, i32* %7
br label %46
23: ; preds = %2
%24 = load i32, i32* @B300
store i32 %24, i32* %7
br label %46
25: ; preds = %2
%26 = load i32, i32* @B600
store i32 %26, i32* %7
br label %46
27: ; preds = %2
%28 = load i32, i32* @B1200
store i32 %28, i32* %7
br label %46
29: ; preds = %2
%30 = load i32, i32* @B1800
store i32 %30, i32* %7
br label %46
31: ; preds = %2
%32 = load i32, i32* @B2400
store i32 %32, i32* %7
br label %46
33: ; preds = %2
%34 = load i32, i32* @B9600
store i32 %34, i32* %7
br label %46
35: ; preds = %2
%36 = load i32, i32* @B19200
store i32 %36, i32* %7
br label %46
37: ; preds = %2
%38 = load i32, i32* @B38400
store i32 %38, i32* %7
br label %46
39: ; preds = %2
%40 = load i32, i32* @B57600
store i32 %40, i32* %7
br label %46
41: ; preds = %2
%42 = load i32, i32* @B115200
store i32 %42, i32* %7
br label %46
43: ; preds = %2
%44 = load i32, i32* @B230400
store i32 %44, i32* %7
br label %46
45: ; preds = %2
store i32 -2, i32* %3
br label %136
46: ; preds = %43, %41, %39, %37, %35, %33, %31, %29, %27, %25, %23, %21, %19, %17, %15, %13, %11
%47 = load i8*, i8** %4
%48 = load i32, i32* @O_RDWR
%49 = load i32, i32* @O_NOCTTY
%50 = or i32 %48, %49
%51 = load i32, i32* @O_NDELAY
%52 = or i32 %50, %51
%53 = call i32 @open(i8* %47, i32 %52)
store i32 %53, i32* %9
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %56
55: ; preds = %46
store i32 -1, i32* %3
br label %136
56: ; preds = %46
%57 = load i32, i32* %9
%58 = load i32, i32* @F_SETFL
%59 = load i32, i32* @O_RDWR
%60 = call i32 @fcntl(i32 %57, i32 %58, i32 %59)
%61 = load i32, i32* %9
%62 = call i32 @tcgetattr(i32 %61, %struct.termios* %6)
%63 = call i32 @cfmakeraw(%struct.termios* %6)
%64 = load i32, i32* %7
%65 = call i32 @cfsetispeed(%struct.termios* %6, i32 %64)
%66 = load i32, i32* %7
%67 = call i32 @cfsetospeed(%struct.termios* %6, i32 %66)
%68 = load i32, i32* @CLOCAL
%69 = load i32, i32* @CREAD
%70 = or i32 %68, %69
%71 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%72 = load i32, i32* %71
%73 = or i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @PARENB
%75 = xor i32 %74, -1
%76 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%77 = load i32, i32* %76
%78 = and i32 %77, %75
store i32 %78, i32* %76
%79 = load i32, i32* @CSTOPB
%80 = xor i32 %79, -1
%81 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%82 = load i32, i32* %81
%83 = and i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* @CSIZE
%85 = xor i32 %84, -1
%86 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%87 = load i32, i32* %86
%88 = and i32 %87, %85
store i32 %88, i32* %86
%89 = load i32, i32* @CS8
%90 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%91 = load i32, i32* %90
%92 = or i32 %91, %89
store i32 %92, i32* %90
%93 = load i32, i32* @ICANON
%94 = load i32, i32* @ECHO
%95 = or i32 %93, %94
%96 = load i32, i32* @ECHOE
%97 = or i32 %95, %96
%98 = load i32, i32* @ISIG
%99 = or i32 %97, %98
%100 = xor i32 %99, -1
%101 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%102 = load i32, i32* %101
%103 = and i32 %102, %100
store i32 %103, i32* %101
%104 = load i32, i32* @OPOST
%105 = xor i32 %104, -1
%106 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%107 = load i32, i32* %106
%108 = and i32 %107, %105
store i32 %108, i32* %106
%109 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%110 = load i32*, i32** %109
%111 = load i64, i64* @VMIN
%112 = getelementptr inbounds i32, i32* %110, i64 %111
store i32 0, i32* %112
%113 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%114 = load i32*, i32** %113
%115 = load i64, i64* @VTIME
%116 = getelementptr inbounds i32, i32* %114, i64 %115
store i32 100, i32* %116
%117 = load i32, i32* %9
%118 = load i32, i32* @TCSANOW
%119 = load i32, i32* @TCSAFLUSH
%120 = or i32 %118, %119
%121 = call i32 @tcsetattr(i32 %117, i32 %120, %struct.termios* %6)
%122 = load i32, i32* %9
%123 = load i32, i32* @TIOCMGET
%124 = call i32 @ioctl(i32 %122, i32 %123, i32* %8)
%125 = load i32, i32* @TIOCM_DTR
%126 = load i32, i32* %8
%127 = or i32 %126, %125
store i32 %127, i32* %8
%128 = load i32, i32* @TIOCM_RTS
%129 = load i32, i32* %8
%130 = or i32 %129, %128
store i32 %130, i32* %8
%131 = load i32, i32* %9
%132 = load i32, i32* @TIOCMSET
%133 = call i32 @ioctl(i32 %131, i32 %132, i32* %8)
%134 = call i32 @usleep(i32 10000)
%135 = load i32, i32* %9
store i32 %135, i32* %3
br label %136
136: ; preds = %56, %55, %45
%137 = load i32, i32* %3
ret i32 %137
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i32 }
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B134 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = global i32 0
@B2400 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@TCSAFLUSH = global i32 0
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define i32 @serialOpen(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.termios
%4 = alloca i32
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast i32* %4 to i8*
switch i32 %1, label %92 [
i32 50, label %23
i32 75, label %7
i32 110, label %8
i32 134, label %9
i32 150, label %10
i32 200, label %11
i32 300, label %12
i32 600, label %13
i32 1200, label %14
i32 1800, label %15
i32 2400, label %16
i32 9600, label %17
i32 19200, label %18
i32 38400, label %19
i32 57600, label %20
i32 115200, label %21
i32 230400, label %22
]
7: ; preds = %2
br label %23
8: ; preds = %2
br label %23
9: ; preds = %2
br label %23
10: ; preds = %2
br label %23
11: ; preds = %2
br label %23
12: ; preds = %2
br label %23
13: ; preds = %2
br label %23
14: ; preds = %2
br label %23
15: ; preds = %2
br label %23
16: ; preds = %2
br label %23
17: ; preds = %2
br label %23
18: ; preds = %2
br label %23
19: ; preds = %2
br label %23
20: ; preds = %2
br label %23
21: ; preds = %2
br label %23
22: ; preds = %2
br label %23
23: ; preds = %2, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7
%24 = phi i32* [ @B230400, %22 ], [ @B115200, %21 ], [ @B57600, %20 ], [ @B38400, %19 ], [ @B19200, %18 ], [ @B9600, %17 ], [ @B2400, %16 ], [ @B1800, %15 ], [ @B1200, %14 ], [ @B600, %13 ], [ @B300, %12 ], [ @B200, %11 ], [ @B150, %10 ], [ @B134, %9 ], [ @B110, %8 ], [ @B75, %7 ], [ @B50, %2 ]
%25 = load i32, i32* %24
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_NOCTTY
%28 = or i32 %27, %26
%29 = load i32, i32* @O_NDELAY
%30 = or i32 %28, %29
%31 = tail call i32 @open(i8* %0, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %92, label %33
33: ; preds = %23
%34 = load i32, i32* @F_SETFL
%35 = load i32, i32* @O_RDWR
%36 = tail call i32 @fcntl(i32 %31, i32 %34, i32 %35)
%37 = call i32 @tcgetattr(i32 %31, %struct.termios* %3)
%38 = call i32 @cfmakeraw(%struct.termios* %3)
%39 = call i32 @cfsetispeed(%struct.termios* %3, i32 %25)
%40 = call i32 @cfsetospeed(%struct.termios* %3, i32 %25)
%41 = load i32, i32* @CLOCAL
%42 = load i32, i32* @CREAD
%43 = or i32 %42, %41
%44 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%45 = load i32, i32* %44
%46 = or i32 %43, %45
%47 = load i32, i32* @PARENB
%48 = load i32, i32* @CSTOPB
%49 = or i32 %47, %48
%50 = load i32, i32* @CSIZE
%51 = or i32 %49, %50
%52 = xor i32 %51, -1
%53 = and i32 %46, %52
%54 = load i32, i32* @CS8
%55 = or i32 %54, %53
store i32 %55, i32* %44
%56 = load i32, i32* @ICANON
%57 = load i32, i32* @ECHO
%58 = or i32 %57, %56
%59 = load i32, i32* @ECHOE
%60 = or i32 %58, %59
%61 = load i32, i32* @ISIG
%62 = or i32 %60, %61
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @OPOST
%68 = xor i32 %67, -1
%69 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%70 = load i32, i32* %69
%71 = and i32 %70, %68
store i32 %71, i32* %69
%72 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%73 = load i32*, i32** %72
%74 = load i64, i64* @VMIN
%75 = getelementptr inbounds i32, i32* %73, i64 %74
store i32 0, i32* %75
%76 = load i64, i64* @VTIME
%77 = getelementptr inbounds i32, i32* %73, i64 %76
store i32 100, i32* %77
%78 = load i32, i32* @TCSANOW
%79 = load i32, i32* @TCSAFLUSH
%80 = or i32 %79, %78
%81 = call i32 @tcsetattr(i32 %31, i32 %80, %struct.termios* %3)
%82 = load i32, i32* @TIOCMGET
%83 = call i32 @ioctl(i32 %31, i32 %82, i32* %4)
%84 = load i32, i32* @TIOCM_DTR
%85 = load i32, i32* %4
%86 = or i32 %85, %84
%87 = load i32, i32* @TIOCM_RTS
%88 = or i32 %87, %86
store i32 %88, i32* %4
%89 = load i32, i32* @TIOCMSET
%90 = call i32 @ioctl(i32 %31, i32 %89, i32* %4)
%91 = call i32 @usleep(i32 10000)
br label %92
92: ; preds = %23, %2, %33
%93 = phi i32 [ %31, %33 ], [ -2, %2 ], [ -1, %23 ]
ret i32 %93
}