#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_cc;
  int c_cflag;
  int c_iflag;
  int c_lflag;
  int /*<<< orphan*/ c_oflag;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B1800;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS5;
int CS6;
int CS7;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ICRNL;
int ISIG;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCSANOW;
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 /*<<< orphan*/);
int open(char const *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serialOpen(const char *device, unsigned int baudrate, unsigned int bits,
               char parity, unsigned int stop) {
  int fd = -1;
  struct termios optnew;
  speed_t speed = B19200;
  fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd > 0) {
    fcntl(fd, F_SETFL, 0);
    tcgetattr(fd, &optnew);
    cfmakeraw(&optnew);
    optnew.c_cc[VMIN] = 0;
    optnew.c_cc[VTIME] = 2 * 10;
    switch (baudrate) {
    case 1200:
      speed = B1200;
      break;
    case 1800:
      speed = B1800;
      break;
    case 4800:
      speed = B4800;
      break;
    case 9600:
      speed = B9600;
      break;
    case 19200:
      speed = B19200;
      break;
    case 38400:
      speed = B38400;
      break;
    case 57600:
      speed = B57600;
      break;
    case 115200:
      speed = B115200;
      break;
    default:
      speed = B19200;
      break;
    }
    cfsetispeed(&optnew, speed);
    cfsetospeed(&optnew, speed);
    optnew.c_cflag &= ~CSIZE;
    optnew.c_cflag &= ~CRTSCTS;
    optnew.c_iflag &= ~(ICRNL | IXON);
    optnew.c_cflag |= CLOCAL | CREAD;
    optnew.c_oflag &= ~OPOST;
    switch (bits) {
    case 5:
      optnew.c_cflag |= CS5;
      break;
    case 6:
      optnew.c_cflag |= CS6;
      break;
    case 7:
      optnew.c_cflag |= CS7;
      break;
    default:
      optnew.c_cflag |= CS8;
      break;
    }
    optnew.c_cflag |= PARENB;
    switch (parity) {
    case 'e':
    case 'E':
      optnew.c_cflag &= ~PARODD;
      break;
    case 'o':
    case 'O':
      optnew.c_cflag &= PARODD;
      break;
    default:
      optnew.c_cflag &= ~PARENB;
      break;
    }
    if (stop == 2)
      optnew.c_cflag &= CSTOPB;
    else
      optnew.c_cflag &= ~CSTOPB;
    optnew.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
    tcsetattr(fd, TCSANOW, &optnew);
  }
  return fd;
}


x86 assembly (clang, -O0):
<serialOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r8d,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    0x2d8e(%rip),%rax
or     (%rax),%esi
mov    0x2d75(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    156c <serialOpen+0x3fc>
mov    -0x1c(%rbp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    %rsi,-0x48(%rbp)
call   1060 <tcgetattr@plt>
mov    -0x48(%rbp),%rdi
call   1050 <cfmakeraw@plt>
mov    -0x38(%rbp),%rax
mov    0x2d62(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
mov    0x2cfd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x14,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x4b0,%eax
je     12c0 <serialOpen+0x150>
jmp    123b <serialOpen+0xcb>
mov    -0x40(%rbp),%eax
sub    $0x708,%eax
je     12d1 <serialOpen+0x161>
jmp    124e <serialOpen+0xde>
mov    -0x40(%rbp),%eax
sub    $0x12c0,%eax
je     12e2 <serialOpen+0x172>
jmp    1261 <serialOpen+0xf1>
mov    -0x40(%rbp),%eax
sub    $0x2580,%eax
je     12f3 <serialOpen+0x183>
jmp    1274 <serialOpen+0x104>
mov    -0x40(%rbp),%eax
sub    $0x4b00,%eax
je     1304 <serialOpen+0x194>
jmp    1287 <serialOpen+0x117>
mov    -0x40(%rbp),%eax
sub    $0x9600,%eax
je     1315 <serialOpen+0x1a5>
jmp    129a <serialOpen+0x12a>
mov    -0x40(%rbp),%eax
sub    $0xe100,%eax
je     1326 <serialOpen+0x1b6>
jmp    12ad <serialOpen+0x13d>
mov    -0x40(%rbp),%eax
sub    $0x1c200,%eax
je     1337 <serialOpen+0x1c7>
jmp    1348 <serialOpen+0x1d8>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2c70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2ca7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2bbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2c2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2be2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    1354 <serialOpen+0x1e4>
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
lea    -0x38(%rbp),%rdi
mov    %rdi,-0x58(%rbp)
call   1090 <cfsetispeed@plt>
mov    -0x58(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1040 <cfsetospeed@plt>
mov    0x2be9(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x30(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    0x2b76(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x30(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    0x2c3b(%rip),%rax
mov    (%rax),%ecx
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
not    %ecx
mov    -0x2c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2b25(%rip),%rax
mov    (%rax),%ecx
mov    0x2bb4(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    0x2bf9(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x24(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x5,%eax
je     1419 <serialOpen+0x2a9>
jmp    13f7 <serialOpen+0x287>
mov    -0x4c(%rbp),%eax
sub    $0x6,%eax
je     142d <serialOpen+0x2bd>
jmp    1408 <serialOpen+0x298>
mov    -0x4c(%rbp),%eax
sub    $0x7,%eax
je     1441 <serialOpen+0x2d1>
jmp    1455 <serialOpen+0x2e5>
mov    0x2ad0(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1464 <serialOpen+0x2f4>
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1464 <serialOpen+0x2f4>
mov    0x2aa0(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1464 <serialOpen+0x2f4>
mov    0x2b14(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2b55(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x5c(%rbp)
sub    $0x45,%eax
je     14bd <serialOpen+0x34d>
jmp    148a <serialOpen+0x31a>
mov    -0x5c(%rbp),%eax
sub    $0x4f,%eax
je     14d4 <serialOpen+0x364>
jmp    149b <serialOpen+0x32b>
mov    -0x5c(%rbp),%eax
sub    $0x65,%eax
je     14bd <serialOpen+0x34d>
jmp    14ac <serialOpen+0x33c>
mov    -0x5c(%rbp),%eax
sub    $0x6f,%eax
je     14d4 <serialOpen+0x364>
jmp    14e8 <serialOpen+0x378>
mov    0x2adc(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    14fa <serialOpen+0x38a>
mov    0x2ac5(%rip),%rax
mov    (%rax),%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    14fa <serialOpen+0x38a>
mov    0x2ad1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x2,-0x18(%rbp)
jne    1518 <serialOpen+0x3a8>
mov    0x29ed(%rip),%rax
mov    (%rax),%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    152a <serialOpen+0x3ba>
mov    0x29d9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x29df(%rip),%rax
mov    (%rax),%eax
mov    0x2a76(%rip),%rcx
or     (%rcx),%eax
mov    0x2a65(%rip),%rcx
or     (%rcx),%eax
mov    0x2a4c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2a57(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x1c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialOpen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e5b(%rip),%rbp
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
or     0x0(%rbp),%eax
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebp
mov    0x2d95(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1080 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    13d5 <serialOpen+0x265>
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rsp,%rbx
mov    %r13d,%edi
mov    %rbx,%rsi
call   1060 <tcgetattr@plt>
mov    %rbx,%rdi
call   1050 <cfmakeraw@plt>
mov    (%rsp),%rax
mov    0x2d85(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d24(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x14,(%rax,%rcx,4)
cmp    $0x4aff,%ebp
jg     122f <serialOpen+0xbf>
cmp    $0x12bf,%ebp
jg     1250 <serialOpen+0xe0>
cmp    $0x4b0,%ebp
je     128b <serialOpen+0x11b>
cmp    $0x708,%ebp
jne    1282 <serialOpen+0x112>
mov    0x2d23(%rip),%rax
jmp    12a4 <serialOpen+0x134>
cmp    $0xe0ff,%ebp
jg     1269 <serialOpen+0xf9>
cmp    $0x4b00,%ebp
je     1282 <serialOpen+0x112>
cmp    $0x9600,%ebp
jne    1282 <serialOpen+0x112>
mov    0x2ca2(%rip),%rax
jmp    12a4 <serialOpen+0x134>
cmp    $0x12c0,%ebp
je     1294 <serialOpen+0x124>
cmp    $0x2580,%ebp
jne    1282 <serialOpen+0x112>
mov    0x2d21(%rip),%rax
jmp    12a4 <serialOpen+0x134>
cmp    $0xe100,%ebp
je     129d <serialOpen+0x12d>
cmp    $0x1c200,%ebp
jne    1282 <serialOpen+0x112>
mov    0x2ca8(%rip),%rax
jmp    12a4 <serialOpen+0x134>
mov    0x2d67(%rip),%rax
jmp    12a4 <serialOpen+0x134>
mov    0x2c9e(%rip),%rax
jmp    12a4 <serialOpen+0x134>
mov    0x2cf5(%rip),%rax
jmp    12a4 <serialOpen+0x134>
mov    0x2cbc(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
call   1090 <cfsetispeed@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <cfsetospeed@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%eax
mov    0x2c3b(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2cfc(%rip),%rcx
mov    0x2ce5(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
not    %edx
and    %edx,0xc(%rsp)
mov    0x2c04(%rip),%rcx
mov    0x2c85(%rip),%rdx
or     (%rcx),%eax
mov    0x2ccc(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,0x14(%rsp)
or     (%rdx),%eax
add    $0xfffffffb,%r12d
cmp    $0x2,%r12d
ja     1328 <serialOpen+0x1b8>
movslq %r12d,%rcx
lea    0x29f6(%rip),%rdx
mov    (%rdx,%rcx,8),%rcx
jmp    132f <serialOpen+0x1bf>
mov    0x2c49(%rip),%rcx
or     (%rcx),%eax
mov    0x2c88(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%ecx
or     %edx,%ecx
movsbl %r15b,%esi
cmp    $0x64,%esi
jg     1353 <serialOpen+0x1e3>
cmp    $0x45,%esi
je     135d <serialOpen+0x1ed>
cmp    $0x4f,%esi
je     136c <serialOpen+0x1fc>
jmp    1377 <serialOpen+0x207>
cmp    $0x6f,%esi
je     136c <serialOpen+0x1fc>
cmp    $0x65,%esi
jne    1377 <serialOpen+0x207>
mov    0x2c3c(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%ecx
jmp    137d <serialOpen+0x20d>
mov    0x2c2d(%rip),%rax
and    (%rax),%ecx
jmp    137d <serialOpen+0x20d>
not    %edx
and    %edx,%eax
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%r14d
setne  %al
mov    0x2b73(%rip),%rdx
neg    %eax
xor    (%rdx),%eax
mov    0x2b80(%rip),%rdx
mov    0x2c11(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
and    %ecx,%eax
mov    0x2bfc(%rip),%rcx
or     (%rcx),%esi
mov    %eax,0x8(%rsp)
mov    0x2bdf(%rip),%rax
or     (%rax),%esi
not    %esi
and    %esi,0x10(%rsp)
mov    0x2bf0(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r13d,%edi
call   1070 <tcsetattr@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32, i32, i32 }
@B19200 = global i32 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B1200 = global i32 0
@B1800 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@OPOST = global i32 0
@CS5 = global i32 0
@CS6 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
define i32 @serialOpen(i8* %0, i32 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.termios
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8 %3, i8* %9
store i32 %4, i32* %10
store i32 -1, i32* %11
%14 = load i32, i32* @B19200
store i32 %14, i32* %13
%15 = load i8*, i8** %6
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_NOCTTY
%18 = or i32 %16, %17
%19 = load i32, i32* @O_NDELAY
%20 = or i32 %18, %19
%21 = call i32 @open(i8* %15, i32 %20)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %165
24: ; preds = %5
%25 = load i32, i32* %11
%26 = load i32, i32* @F_SETFL
%27 = call i32 @fcntl(i32 %25, i32 %26, i32 0)
%28 = load i32, i32* %11
%29 = call i32 @tcgetattr(i32 %28, %struct.termios* %12)
%30 = call i32 @cfmakeraw(%struct.termios* %12)
%31 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%32 = load i32*, i32** %31
%33 = load i64, i64* @VMIN
%34 = getelementptr inbounds i32, i32* %32, i64 %33
store i32 0, i32* %34
%35 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%36 = load i32*, i32** %35
%37 = load i64, i64* @VTIME
%38 = getelementptr inbounds i32, i32* %36, i64 %37
store i32 20, i32* %38
%39 = load i32, i32* %7
switch i32 %39, label %56 [
i32 1200, label %40
i32 1800, label %42
i32 4800, label %44
i32 9600, label %46
i32 19200, label %48
i32 38400, label %50
i32 57600, label %52
i32 115200, label %54
]
40: ; preds = %24
%41 = load i32, i32* @B1200
store i32 %41, i32* %13
br label %58
42: ; preds = %24
%43 = load i32, i32* @B1800
store i32 %43, i32* %13
br label %58
44: ; preds = %24
%45 = load i32, i32* @B4800
store i32 %45, i32* %13
br label %58
46: ; preds = %24
%47 = load i32, i32* @B9600
store i32 %47, i32* %13
br label %58
48: ; preds = %24
%49 = load i32, i32* @B19200
store i32 %49, i32* %13
br label %58
50: ; preds = %24
%51 = load i32, i32* @B38400
store i32 %51, i32* %13
br label %58
52: ; preds = %24
%53 = load i32, i32* @B57600
store i32 %53, i32* %13
br label %58
54: ; preds = %24
%55 = load i32, i32* @B115200
store i32 %55, i32* %13
br label %58
56: ; preds = %24
%57 = load i32, i32* @B19200
store i32 %57, i32* %13
br label %58
58: ; preds = %56, %54, %52, %50, %48, %46, %44, %42, %40
%59 = load i32, i32* %13
%60 = call i32 @cfsetispeed(%struct.termios* %12, i32 %59)
%61 = load i32, i32* %13
%62 = call i32 @cfsetospeed(%struct.termios* %12, i32 %61)
%63 = load i32, i32* @CSIZE
%64 = xor i32 %63, -1
%65 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%66 = load i32, i32* %65
%67 = and i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @CRTSCTS
%69 = xor i32 %68, -1
%70 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%71 = load i32, i32* %70
%72 = and i32 %71, %69
store i32 %72, i32* %70
%73 = load i32, i32* @ICRNL
%74 = load i32, i32* @IXON
%75 = or i32 %73, %74
%76 = xor i32 %75, -1
%77 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%78 = load i32, i32* %77
%79 = and i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* @CLOCAL
%81 = load i32, i32* @CREAD
%82 = or i32 %80, %81
%83 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%84 = load i32, i32* %83
%85 = or i32 %84, %82
store i32 %85, i32* %83
%86 = load i32, i32* @OPOST
%87 = xor i32 %86, -1
%88 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 4
%89 = load i32, i32* %88
%90 = and i32 %89, %87
store i32 %90, i32* %88
%91 = load i32, i32* %8
switch i32 %91, label %107 [
i32 5, label %92
i32 6, label %97
i32 7, label %102
]
92: ; preds = %58
%93 = load i32, i32* @CS5
%94 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%95 = load i32, i32* %94
%96 = or i32 %95, %93
store i32 %96, i32* %94
br label %112
97: ; preds = %58
%98 = load i32, i32* @CS6
%99 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%100 = load i32, i32* %99
%101 = or i32 %100, %98
store i32 %101, i32* %99
br label %112
102: ; preds = %58
%103 = load i32, i32* @CS7
%104 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%105 = load i32, i32* %104
%106 = or i32 %105, %103
store i32 %106, i32* %104
br label %112
107: ; preds = %58
%108 = load i32, i32* @CS8
%109 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%110 = load i32, i32* %109
%111 = or i32 %110, %108
store i32 %111, i32* %109
br label %112
112: ; preds = %107, %102, %97, %92
%113 = load i32, i32* @PARENB
%114 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%115 = load i32, i32* %114
%116 = or i32 %115, %113
store i32 %116, i32* %114
%117 = load i8, i8* %9
%118 = sext i8 %117 to i32
switch i32 %118, label %130 [
i32 101, label %119
i32 69, label %119
i32 111, label %125
i32 79, label %125
]
119: ; preds = %112, %112
%120 = load i32, i32* @PARODD
%121 = xor i32 %120, -1
%122 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%123 = load i32, i32* %122
%124 = and i32 %123, %121
store i32 %124, i32* %122
br label %136
125: ; preds = %112, %112
%126 = load i32, i32* @PARODD
%127 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%128 = load i32, i32* %127
%129 = and i32 %128, %126
store i32 %129, i32* %127
br label %136
130: ; preds = %112
%131 = load i32, i32* @PARENB
%132 = xor i32 %131, -1
%133 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%134 = load i32, i32* %133
%135 = and i32 %134, %132
store i32 %135, i32* %133
br label %136
136: ; preds = %130, %125, %119
%137 = load i32, i32* %10
%138 = icmp eq i32 %137, 2
br i1 %138, label %139, label %144
139: ; preds = %136
%140 = load i32, i32* @CSTOPB
%141 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%142 = load i32, i32* %141
%143 = and i32 %142, %140
store i32 %143, i32* %141
br label %150
144: ; preds = %136
%145 = load i32, i32* @CSTOPB
%146 = xor i32 %145, -1
%147 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%148 = load i32, i32* %147
%149 = and i32 %148, %146
store i32 %149, i32* %147
br label %150
150: ; preds = %144, %139
%151 = load i32, i32* @ICANON
%152 = load i32, i32* @ECHO
%153 = or i32 %151, %152
%154 = load i32, i32* @ECHOE
%155 = or i32 %153, %154
%156 = load i32, i32* @ISIG
%157 = or i32 %155, %156
%158 = xor i32 %157, -1
%159 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 3
%160 = load i32, i32* %159
%161 = and i32 %160, %158
store i32 %161, i32* %159
%162 = load i32, i32* %11
%163 = load i32, i32* @TCSANOW
%164 = call i32 @tcsetattr(i32 %162, i32 %163, %struct.termios* %12)
br label %165
165: ; preds = %150, %5
%166 = load i32, i32* %11
ret i32 %166
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32, i32, i32 }
@B19200 = global i32 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B1200 = global i32 0
@B1800 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@OPOST = global i32 0
@CS5 = global i32 0
@CS6 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@switch.table.serialOpen = [3 x i32*] [i32* @CS5, i32* @CS6, i32* @CS7]
define i32 @serialOpen(i8* nocapture %0, i32 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca %struct.termios
%7 = bitcast %struct.termios* %6 to i8*
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %9, %8
%11 = load i32, i32* @O_NDELAY
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* %0, i32 %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %105
15: ; preds = %5
%16 = load i32, i32* @F_SETFL
%17 = tail call i32 @fcntl(i32 %13, i32 %16, i32 0)
%18 = call i32 @tcgetattr(i32 %13, %struct.termios* %6)
%19 = call i32 @cfmakeraw(%struct.termios* %6)
%20 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 0
%21 = load i32*, i32** %20
%22 = load i64, i64* @VMIN
%23 = getelementptr inbounds i32, i32* %21, i64 %22
store i32 0, i32* %23
%24 = load i64, i64* @VTIME
%25 = getelementptr inbounds i32, i32* %21, i64 %24
store i32 20, i32* %25
switch i32 %1, label %33 [
i32 1200, label %34
i32 1800, label %26
i32 4800, label %27
i32 9600, label %28
i32 19200, label %29
i32 38400, label %30
i32 57600, label %31
i32 115200, label %32
]
26: ; preds = %15
br label %34
27: ; preds = %15
br label %34
28: ; preds = %15
br label %34
29: ; preds = %15
br label %34
30: ; preds = %15
br label %34
31: ; preds = %15
br label %34
32: ; preds = %15
br label %34
33: ; preds = %15
br label %34
34: ; preds = %15, %33, %32, %31, %30, %29, %28, %27, %26
%35 = phi i32* [ @B19200, %33 ], [ @B115200, %32 ], [ @B57600, %31 ], [ @B38400, %30 ], [ @B19200, %29 ], [ @B9600, %28 ], [ @B4800, %27 ], [ @B1800, %26 ], [ @B1200, %15 ]
%36 = load i32, i32* %35
%37 = call i32 @cfsetispeed(%struct.termios* %6, i32 %36)
%38 = call i32 @cfsetospeed(%struct.termios* %6, i32 %36)
%39 = load i32, i32* @CSIZE
%40 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 1
%41 = load i32, i32* %40
%42 = load i32, i32* @CRTSCTS
%43 = or i32 %39, %42
%44 = xor i32 %43, -1
%45 = and i32 %41, %44
%46 = load i32, i32* @ICRNL
%47 = load i32, i32* @IXON
%48 = or i32 %47, %46
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 2
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @CLOCAL
%54 = load i32, i32* @CREAD
%55 = or i32 %53, %45
%56 = or i32 %55, %54
%57 = load i32, i32* @OPOST
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 4
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = add i32 %2, -5
%63 = icmp ult i32 %62, 3
br i1 %63, label %64, label %68
64: ; preds = %34
%65 = sext i32 %62 to i64
%66 = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.serialOpen, i64 0, i64 %65
%67 = load i32*, i32** %66
br label %68
68: ; preds = %34, %64
%69 = phi i32* [ %67, %64 ], [ @CS8, %34 ]
%70 = load i32, i32* %69
%71 = or i32 %70, %56
%72 = load i32, i32* @PARENB
%73 = or i32 %71, %72
%74 = sext i8 %3 to i32
switch i32 %74, label %82 [
i32 101, label %75
i32 69, label %75
i32 111, label %79
i32 79, label %79
]
75: ; preds = %68, %68
%76 = load i32, i32* @PARODD
%77 = xor i32 %76, -1
%78 = and i32 %73, %77
br label %85
79: ; preds = %68, %68
%80 = load i32, i32* @PARODD
%81 = and i32 %80, %73
br label %85
82: ; preds = %68
%83 = xor i32 %72, -1
%84 = and i32 %71, %83
br label %85
85: ; preds = %82, %79, %75
%86 = phi i32 [ %84, %82 ], [ %81, %79 ], [ %78, %75 ]
%87 = icmp ne i32 %4, 2
%88 = load i32, i32* @CSTOPB
%89 = sext i1 %87 to i32
%90 = xor i32 %88, %89
%91 = and i32 %86, %90
store i32 %91, i32* %40
%92 = load i32, i32* @ICANON
%93 = load i32, i32* @ECHO
%94 = or i32 %93, %92
%95 = load i32, i32* @ECHOE
%96 = or i32 %94, %95
%97 = load i32, i32* @ISIG
%98 = or i32 %96, %97
%99 = xor i32 %98, -1
%100 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 3
%101 = load i32, i32* %100
%102 = and i32 %101, %99
store i32 %102, i32* %100
%103 = load i32, i32* @TCSANOW
%104 = call i32 @tcsetattr(i32 %13, i32 %103, %struct.termios* %6)
br label %105
105: ; preds = %85, %5
ret i32 %13
}