#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_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*/ B4800;
int /*<<< orphan*/ B50;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B600;
int /*<<< orphan*/ B75;
int /*<<< orphan*/ B9600;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int ser_init(char *dev, int br) {
  speed_t baud;
  int tt;
  struct termios term;
  tt = open(dev, O_RDWR | O_NOCTTY);
  if (tt == -1) {
    fprintf(stderr, "Unable to open serial port %s\n", dev);
    return -1;
  }
  if (tcgetattr(tt, &term) < 0) {
    fprintf(stderr, "Unable to get terminal attributes for %s\n", dev);
    return -1;
  }
  switch (br) {
  case 50:
    baud = B50;
    break;
  case 75:
    baud = B75;
    break;
  case 110:
    baud = B110;
    break;
  case 134:
    baud = B134;
    break;
  case 150:
    baud = B150;
    break;
  case 200:
    baud = B200;
    break;
  case 300:
    baud = B300;
    break;
  case 600:
    baud = B600;
    break;
  case 1200:
    baud = B1200;
    break;
  case 1800:
    baud = B1800;
    break;
  case 2400:
    baud = B2400;
    break;
  case 4800:
    baud = B4800;
    break;
  case 9600:
    baud = B9600;
    break;
  case 19200:
    baud = B19200;
    break;
  case 38400:
    baud = B38400;
    break;
  case 57600:
    baud = B57600;
    break;
  case 115200:
    baud = B115200;
    break;
  case 230400:
    baud = B230400;
    break;
  default:
    fprintf(stderr, "Baud rate of %d is invalid \n", br);
    return -1;
  }
  cfsetospeed(&term, baud);
  term.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS);
  term.c_cflag |= CS8;
  term.c_iflag &= ~(IXON | IXOFF | IXANY);
  term.c_lflag &= ~(ECHO | ECHOE | ISIG);
  term.c_lflag |= ICANON;
  term.c_oflag &= ~OPOST;
  term.c_cc[VMIN] = 1;
  term.c_cc[VTIME] = 0;
  if (tcsetattr(tt, TCSANOW, &term) == -1) {
    fprintf(stderr,
            "Unable to set terminal attributes for serial connection %s\n",
            dev);
    return -1;
  }
  return tt;
}


x86 assembly (clang, -O0):
<ser_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2da5(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ae <ser_init+0x5e>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15bc <ser_init+0x46c>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11eb <ser_init+0x9b>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15bc <ser_init+0x46c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x32,%eax
je     133e <ser_init+0x1ee>
jmp    11ff <ser_init+0xaf>
mov    -0x44(%rbp),%eax
sub    $0x4b,%eax
je     134f <ser_init+0x1ff>
jmp    1210 <ser_init+0xc0>
mov    -0x44(%rbp),%eax
sub    $0x6e,%eax
je     1360 <ser_init+0x210>
jmp    1221 <ser_init+0xd1>
mov    -0x44(%rbp),%eax
sub    $0x86,%eax
je     1371 <ser_init+0x221>
jmp    1234 <ser_init+0xe4>
mov    -0x44(%rbp),%eax
sub    $0x96,%eax
je     1382 <ser_init+0x232>
jmp    1247 <ser_init+0xf7>
mov    -0x44(%rbp),%eax
sub    $0xc8,%eax
je     1393 <ser_init+0x243>
jmp    125a <ser_init+0x10a>
mov    -0x44(%rbp),%eax
sub    $0x12c,%eax
je     13a4 <ser_init+0x254>
jmp    126d <ser_init+0x11d>
mov    -0x44(%rbp),%eax
sub    $0x258,%eax
je     13b5 <ser_init+0x265>
jmp    1280 <ser_init+0x130>
mov    -0x44(%rbp),%eax
sub    $0x4b0,%eax
je     13c6 <ser_init+0x276>
jmp    1293 <ser_init+0x143>
mov    -0x44(%rbp),%eax
sub    $0x708,%eax
je     13d7 <ser_init+0x287>
jmp    12a6 <ser_init+0x156>
mov    -0x44(%rbp),%eax
sub    $0x960,%eax
je     13e8 <ser_init+0x298>
jmp    12b9 <ser_init+0x169>
mov    -0x44(%rbp),%eax
sub    $0x12c0,%eax
je     13f9 <ser_init+0x2a9>
jmp    12cc <ser_init+0x17c>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     140a <ser_init+0x2ba>
jmp    12df <ser_init+0x18f>
mov    -0x44(%rbp),%eax
sub    $0x4b00,%eax
je     141b <ser_init+0x2cb>
jmp    12f2 <ser_init+0x1a2>
mov    -0x44(%rbp),%eax
sub    $0x9600,%eax
je     142c <ser_init+0x2dc>
jmp    1305 <ser_init+0x1b5>
mov    -0x44(%rbp),%eax
sub    $0xe100,%eax
je     143d <ser_init+0x2ed>
jmp    1318 <ser_init+0x1c8>
mov    -0x44(%rbp),%eax
sub    $0x1c200,%eax
je     144e <ser_init+0x2fe>
jmp    132b <ser_init+0x1db>
mov    -0x44(%rbp),%eax
sub    $0x38400,%eax
je     145f <ser_init+0x30f>
jmp    1470 <ser_init+0x320>
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2c72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2c71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2b77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2bb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2bbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2be4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2b2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2b4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2b19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2b78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2b5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2bce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2a85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2af4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2a9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2a62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1496 <ser_init+0x346>
mov    0x2a99(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xbc6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15bc <ser_init+0x46c>
mov    -0x18(%rbp),%esi
lea    -0x40(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2b07(%rip),%rax
mov    (%rax),%eax
mov    0x2a0e(%rip),%rcx
or     (%rcx),%eax
mov    0x2a85(%rip),%rcx
or     (%rcx),%eax
mov    0x2a0c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2a82(%rip),%rax
mov    (%rax),%eax
or     -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2ad3(%rip),%rax
mov    (%rax),%eax
mov    0x2ae2(%rip),%rcx
or     (%rcx),%eax
mov    0x2a29(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2a8f(%rip),%rax
mov    (%rax),%eax
mov    0x2a7e(%rip),%rcx
or     (%rcx),%eax
mov    0x2a6d(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x29b3(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2a84(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    0x29f6(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    0x2981(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edi
mov    0x2a2d(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    15b6 <ser_init+0x466>
mov    0x297a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xac3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15bc <ser_init+0x46c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ser_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e7c(%rip),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11da <ser_init+0x8a>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     11ef <ser_init+0x9f>
cmp    $0x707,%ebx
jg     1204 <ser_init+0xb4>
cmp    $0x95,%ebx
jle    1248 <ser_init+0xf8>
cmp    $0x12b,%ebx
jle    129f <ser_init+0x14f>
cmp    $0x12c,%ebx
je     131e <ser_init+0x1ce>
cmp    $0x258,%ebx
je     1327 <ser_init+0x1d7>
cmp    $0x4b0,%ebx
jne    147f <ser_init+0x32f>
mov    0x2d23(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
jmp    1465 <ser_init+0x315>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
jmp    1465 <ser_init+0x315>
cmp    $0x4aff,%ebx
jle    126f <ser_init+0x11f>
cmp    $0xe0ff,%ebx
jle    12c3 <ser_init+0x173>
cmp    $0xe100,%ebx
je     1330 <ser_init+0x1e0>
cmp    $0x1c200,%ebx
je     1339 <ser_init+0x1e9>
cmp    $0x38400,%ebx
jne    147f <ser_init+0x32f>
mov    0x2c85(%rip),%rax
jmp    1376 <ser_init+0x226>
cmp    $0x6d,%ebx
jg     12e7 <ser_init+0x197>
cmp    $0x32,%ebx
je     1342 <ser_init+0x1f2>
cmp    $0x4b,%ebx
jne    147f <ser_init+0x32f>
mov    0x2d5e(%rip),%rax
jmp    1376 <ser_init+0x226>
cmp    $0x12bf,%ebx
jg     1301 <ser_init+0x1b1>
cmp    $0x708,%ebx
je     134b <ser_init+0x1fb>
cmp    $0x960,%ebx
jne    147f <ser_init+0x32f>
mov    0x2c6e(%rip),%rax
jmp    1376 <ser_init+0x226>
cmp    $0x96,%ebx
je     1354 <ser_init+0x204>
cmp    $0xc8,%ebx
jne    147f <ser_init+0x32f>
mov    0x2c92(%rip),%rax
jmp    1376 <ser_init+0x226>
cmp    $0x4b00,%ebx
je     135d <ser_init+0x20d>
cmp    $0x9600,%ebx
jne    147f <ser_init+0x32f>
mov    0x2bd6(%rip),%rax
jmp    1376 <ser_init+0x226>
cmp    $0x6e,%ebx
je     1366 <ser_init+0x216>
cmp    $0x86,%ebx
jne    147f <ser_init+0x32f>
mov    0x2c81(%rip),%rax
jmp    1376 <ser_init+0x226>
cmp    $0x12c0,%ebx
je     136f <ser_init+0x21f>
cmp    $0x2580,%ebx
jne    147f <ser_init+0x32f>
mov    0x2c54(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c43(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c72(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c01(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2bb0(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c17(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2bd6(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2ba5(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c8c(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c6b(%rip),%rax
jmp    1376 <ser_init+0x226>
mov    0x2c02(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2c26(%rip),%rax
mov    0x2b2f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2ba4(%rip),%rax
or     (%rax),%ecx
mov    0x2b2b(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    (%rsp),%ecx
mov    0x2ba5(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    0x2bf9(%rip),%rax
mov    0x2c0a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2b4f(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2bb8(%rip),%rax
mov    0x2ba9(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2b96(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x8(%rsp),%ecx
mov    0x2adf(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2bb2(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2b26(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2ab5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2b64(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1474 <ser_init+0x324>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
lea    0xc01(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2a8a(%rip),%rax
mov    (%rax),%edi
lea    0xbba(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    146f <ser_init+0x31f>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Unable to open serial port %s\0A\00"
@.str.1 = [42 x i8] c"Unable to get terminal attributes for %s\0A\00"
@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
@B4800 = 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
@.str.2 = [29 x i8] c"Baud rate of %d is invalid \0A\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.3 = [60 x i8] c"Unable to set terminal attributes for serial connection %s\0A\00"
define i32 @ser_init(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_NOCTTY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %133
20: ; preds = %2
%21 = load i32, i32* %7
%22 = call i64 @tcgetattr(i32 %21, %struct.termios* %8)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %4
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -1, i32* %3
br label %133
28: ; preds = %20
%29 = load i32, i32* %5
switch i32 %29, label %66 [
i32 50, label %30
i32 75, label %32
i32 110, label %34
i32 134, label %36
i32 150, label %38
i32 200, label %40
i32 300, label %42
i32 600, label %44
i32 1200, label %46
i32 1800, label %48
i32 2400, label %50
i32 4800, label %52
i32 9600, label %54
i32 19200, label %56
i32 38400, label %58
i32 57600, label %60
i32 115200, label %62
i32 230400, label %64
]
30: ; preds = %28
%31 = load i32, i32* @B50
store i32 %31, i32* %6
br label %70
32: ; preds = %28
%33 = load i32, i32* @B75
store i32 %33, i32* %6
br label %70
34: ; preds = %28
%35 = load i32, i32* @B110
store i32 %35, i32* %6
br label %70
36: ; preds = %28
%37 = load i32, i32* @B134
store i32 %37, i32* %6
br label %70
38: ; preds = %28
%39 = load i32, i32* @B150
store i32 %39, i32* %6
br label %70
40: ; preds = %28
%41 = load i32, i32* @B200
store i32 %41, i32* %6
br label %70
42: ; preds = %28
%43 = load i32, i32* @B300
store i32 %43, i32* %6
br label %70
44: ; preds = %28
%45 = load i32, i32* @B600
store i32 %45, i32* %6
br label %70
46: ; preds = %28
%47 = load i32, i32* @B1200
store i32 %47, i32* %6
br label %70
48: ; preds = %28
%49 = load i32, i32* @B1800
store i32 %49, i32* %6
br label %70
50: ; preds = %28
%51 = load i32, i32* @B2400
store i32 %51, i32* %6
br label %70
52: ; preds = %28
%53 = load i32, i32* @B4800
store i32 %53, i32* %6
br label %70
54: ; preds = %28
%55 = load i32, i32* @B9600
store i32 %55, i32* %6
br label %70
56: ; preds = %28
%57 = load i32, i32* @B19200
store i32 %57, i32* %6
br label %70
58: ; preds = %28
%59 = load i32, i32* @B38400
store i32 %59, i32* %6
br label %70
60: ; preds = %28
%61 = load i32, i32* @B57600
store i32 %61, i32* %6
br label %70
62: ; preds = %28
%63 = load i32, i32* @B115200
store i32 %63, i32* %6
br label %70
64: ; preds = %28
%65 = load i32, i32* @B230400
store i32 %65, i32* %6
br label %70
66: ; preds = %28
%67 = load i32, i32* @stderr
%68 = load i32, i32* %5
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %68)
store i32 -1, i32* %3
br label %133
70: ; preds = %64, %62, %60, %58, %56, %54, %52, %50, %48, %46, %44, %42, %40, %38, %36, %34, %32, %30
%71 = load i32, i32* %6
%72 = call i32 @cfsetospeed(%struct.termios* %8, i32 %71)
%73 = load i32, i32* @PARENB
%74 = load i32, i32* @CSTOPB
%75 = or i32 %73, %74
%76 = load i32, i32* @CSIZE
%77 = or i32 %75, %76
%78 = load i32, i32* @CRTSCTS
%79 = or i32 %77, %78
%80 = xor i32 %79, -1
%81 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%82 = load i32, i32* %81
%83 = and i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* @CS8
%85 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%86 = load i32, i32* %85
%87 = or i32 %86, %84
store i32 %87, i32* %85
%88 = load i32, i32* @IXON
%89 = load i32, i32* @IXOFF
%90 = or i32 %88, %89
%91 = load i32, i32* @IXANY
%92 = or i32 %90, %91
%93 = xor i32 %92, -1
%94 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%95 = load i32, i32* %94
%96 = and i32 %95, %93
store i32 %96, i32* %94
%97 = load i32, i32* @ECHO
%98 = load i32, i32* @ECHOE
%99 = or i32 %97, %98
%100 = load i32, i32* @ISIG
%101 = or i32 %99, %100
%102 = xor i32 %101, -1
%103 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%104 = load i32, i32* %103
%105 = and i32 %104, %102
store i32 %105, i32* %103
%106 = load i32, i32* @ICANON
%107 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%108 = load i32, i32* %107
%109 = or i32 %108, %106
store i32 %109, i32* %107
%110 = load i32, i32* @OPOST
%111 = xor i32 %110, -1
%112 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
%113 = load i32, i32* %112
%114 = and i32 %113, %111
store i32 %114, i32* %112
%115 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%116 = load i32*, i32** %115
%117 = load i64, i64* @VMIN
%118 = getelementptr inbounds i32, i32* %116, i64 %117
store i32 1, i32* %118
%119 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%120 = load i32*, i32** %119
%121 = load i64, i64* @VTIME
%122 = getelementptr inbounds i32, i32* %120, i64 %121
store i32 0, i32* %122
%123 = load i32, i32* %7
%124 = load i32, i32* @TCSANOW
%125 = call i32 @tcsetattr(i32 %123, i32 %124, %struct.termios* %8)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %131
127: ; preds = %70
%128 = load i32, i32* @stderr
%129 = load i8*, i8** %4
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i8* %129)
store i32 -1, i32* %3
br label %133
131: ; preds = %70
%132 = load i32, i32* %7
store i32 %132, i32* %3
br label %133
133: ; preds = %131, %127, %66, %24, %16
%134 = load i32, i32* %3
ret i32 %134
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Unable to open serial port %s\0A\00"
@.str.1 = [42 x i8] c"Unable to get terminal attributes for %s\0A\00"
@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
@B4800 = 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
@.str.2 = [29 x i8] c"Baud rate of %d is invalid \0A\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.3 = [60 x i8] c"Unable to set terminal attributes for serial connection %s\0A\00"
define i32 @ser_init(i8* %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %94
13: ; preds = %2
%14 = call i64 @tcgetattr(i32 %8, %struct.termios* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %94
19: ; preds = %13
switch i32 %1, label %37 [
i32 50, label %40
i32 75, label %20
i32 110, label %21
i32 134, label %22
i32 150, label %23
i32 200, label %24
i32 300, label %25
i32 600, label %26
i32 1200, label %27
i32 1800, label %28
i32 2400, label %29
i32 4800, label %30
i32 9600, label %31
i32 19200, label %32
i32 38400, label %33
i32 57600, label %34
i32 115200, label %35
i32 230400, label %36
]
20: ; preds = %19
br label %40
21: ; preds = %19
br label %40
22: ; preds = %19
br label %40
23: ; preds = %19
br label %40
24: ; preds = %19
br label %40
25: ; preds = %19
br label %40
26: ; preds = %19
br label %40
27: ; preds = %19
br label %40
28: ; preds = %19
br label %40
29: ; preds = %19
br label %40
30: ; preds = %19
br label %40
31: ; preds = %19
br label %40
32: ; preds = %19
br label %40
33: ; preds = %19
br label %40
34: ; preds = %19
br label %40
35: ; preds = %19
br label %40
36: ; preds = %19
br label %40
37: ; preds = %19
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %94
40: ; preds = %19, %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20
%41 = phi i32* [ @B230400, %36 ], [ @B115200, %35 ], [ @B57600, %34 ], [ @B38400, %33 ], [ @B19200, %32 ], [ @B9600, %31 ], [ @B4800, %30 ], [ @B2400, %29 ], [ @B1800, %28 ], [ @B1200, %27 ], [ @B600, %26 ], [ @B300, %25 ], [ @B200, %24 ], [ @B150, %23 ], [ @B134, %22 ], [ @B110, %21 ], [ @B75, %20 ], [ @B50, %19 ]
%42 = load i32, i32* %41
%43 = call i32 @cfsetospeed(%struct.termios* %3, i32 %42)
%44 = load i32, i32* @PARENB
%45 = load i32, i32* @CSTOPB
%46 = or i32 %45, %44
%47 = load i32, i32* @CSIZE
%48 = or i32 %46, %47
%49 = load i32, i32* @CRTSCTS
%50 = or i32 %48, %49
%51 = xor i32 %50, -1
%52 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%53 = load i32, i32* %52
%54 = and i32 %53, %51
%55 = load i32, i32* @CS8
%56 = or i32 %55, %54
store i32 %56, i32* %52
%57 = load i32, i32* @IXON
%58 = load i32, i32* @IXOFF
%59 = or i32 %58, %57
%60 = load i32, i32* @IXANY
%61 = or i32 %59, %60
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @ECHO
%67 = load i32, i32* @ECHOE
%68 = or i32 %67, %66
%69 = load i32, i32* @ISIG
%70 = or i32 %68, %69
%71 = xor i32 %70, -1
%72 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%73 = load i32, i32* %72
%74 = and i32 %73, %71
%75 = load i32, i32* @ICANON
%76 = or i32 %75, %74
store i32 %76, i32* %72
%77 = load i32, i32* @OPOST
%78 = xor i32 %77, -1
%79 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%80 = load i32, i32* %79
%81 = and i32 %80, %78
store i32 %81, i32* %79
%82 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%83 = load i32*, i32** %82
%84 = load i64, i64* @VMIN
%85 = getelementptr inbounds i32, i32* %83, i64 %84
store i32 1, i32* %85
%86 = load i64, i64* @VTIME
%87 = getelementptr inbounds i32, i32* %83, i64 %86
store i32 0, i32* %87
%88 = load i32, i32* @TCSANOW
%89 = call i32 @tcsetattr(i32 %8, i32 %88, %struct.termios* %3)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %40
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %94
94: ; preds = %40, %91, %37, %16, %10
%95 = phi i32 [ -1, %10 ], [ -1, %16 ], [ -1, %37 ], [ -1, %91 ], [ %8, %40 ]
ret i32 %95
}