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

/* Variables and functions */
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS6;
int CS7;
int CS8;
int CSIZE;
int CSTOPB;
int HUPCL;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCMGET;
int /*<<< orphan*/ TIOCMSET;
int TIOCM_DTR;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char const *, int);
int /*<<< orphan*/ perror(char *);
int serial_port_get_speed(unsigned int);
scalar_t__ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_port_init(const char *device_name, unsigned int speed,
                     unsigned int flags, int *port) {
  struct termios term_st;
  assert(device_name != NULL);
  assert(port != NULL);
  *port = open(device_name, O_RDWR | O_NOCTTY);
  if (*port < 0) {
    return -1;
  }
  bzero(&term_st, sizeof(struct termios));
  if (tcgetattr(*port, &term_st)) {
    perror("tcgetattr");
    return -1;
  }
  int status;
  ioctl(*port, TIOCMGET, &status);
  status &= ~TIOCM_DTR;
  ioctl(*port, TIOCMSET, &status);
  {
    int spd_macro = serial_port_get_speed(speed);
    if (spd_macro == -1)
      return -1;
    cfsetispeed(&term_st, spd_macro);
    cfsetospeed(&term_st, spd_macro);
  }
  cfmakeraw(&term_st);
  term_st.c_oflag &= ~OPOST;
  term_st.c_cflag |= (CREAD | HUPCL | CLOCAL);
  term_st.c_cflag &= ~CSIZE;
  switch (flags & (3 << 5)) {
  case (0 << 5):
    term_st.c_cflag |= CS8;
    break;
  case (2 << 5):
    term_st.c_cflag |= CS7;
    break;
  case (1 << 5):
    term_st.c_cflag |= CS6;
    break;
  }
  term_st.c_cflag &= ~(PARENB | PARODD);
  switch (flags & (3 << 0)) {
  case (0 << 0):
  default:
    break;
  case (2 << 0):
    term_st.c_cflag |= (PARENB | PARODD);
    break;
  case (1 << 0):
    term_st.c_cflag |= PARENB;
    break;
  }
  if (flags & (1 << 4)) {
    term_st.c_cflag |= CSTOPB;
  } else {
    term_st.c_cflag &= ~CSTOPB;
  }
  term_st.c_cflag &= ~CRTSCTS;
  term_st.c_iflag &= ~(IXON | IXOFF | IXANY);
  switch (flags & (3 << 2)) {
  case 0:
  default:
    break;
  case (1 << 2):
    term_st.c_cflag |= CRTSCTS;
    break;
  case (2 << 2):
    term_st.c_iflag |= (IXON | IXOFF);
    break;
  }
  term_st.c_cc[VMIN] = 0;
  term_st.c_cc[VTIME] = 0;
  if (tcflush(*port, TCIOFLUSH)) {
    perror("tcflush");
    return -1;
  }
  if (tcsetattr(*port, TCSANOW, &term_st)) {
    perror("tcgetattr");
    return -1;
  }
  ioctl(*port, TIOCMGET, &status);
  status |= TIOCM_DTR;
  ioctl(*port, TIOCMSET, &status);
  return 0;
}


x86 assembly (clang, -O0):
<serial_port_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1236 <serial_port_init+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    1600 <serial_port_init+0x440>
lea    -0x38(%rbp),%rdi
mov    $0x18,%esi
call   10e0 <bzero@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmp    $0x0,%rax
je     1275 <serial_port_init+0xb5>
lea    0xd9c(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1600 <serial_port_init+0x440>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
call   1060 <ioctl@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1030 <serial_port_get_speed@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    12d8 <serial_port_init+0x118>
movl   $0xffffffff,-0x4(%rbp)
jmp    1600 <serial_port_init+0x440>
mov    -0x40(%rbp),%esi
lea    -0x38(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
call   10c0 <cfsetispeed@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1040 <cfsetospeed@plt>
mov    -0x50(%rbp),%rdi
call   1080 <cfmakeraw@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x28(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    0x2c81(%rip),%rax
mov    (%rax),%ecx
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    0x2bf5(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    -0x38(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    0x2c42(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x38(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
and    $0x60,%eax
mov    %eax,-0x44(%rbp)
je     1380 <serial_port_init+0x1c0>
jmp    135e <serial_port_init+0x19e>
mov    -0x44(%rbp),%eax
sub    $0x20,%eax
je     13a8 <serial_port_init+0x1e8>
jmp    136f <serial_port_init+0x1af>
mov    -0x44(%rbp),%eax
sub    $0x40,%eax
je     1394 <serial_port_init+0x1d4>
jmp    13b7 <serial_port_init+0x1f7>
mov    0x2c09(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    13b7 <serial_port_init+0x1f7>
mov    0x2b8d(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    13b7 <serial_port_init+0x1f7>
mov    0x2bf1(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c02(%rip),%rax
mov    (%rax),%ecx
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
not    %ecx
mov    -0x38(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x54(%rbp)
je     140b <serial_port_init+0x24b>
jmp    13e9 <serial_port_init+0x229>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
je     1432 <serial_port_init+0x272>
jmp    13fa <serial_port_init+0x23a>
mov    -0x54(%rbp),%eax
sub    $0x2,%eax
je     1415 <serial_port_init+0x255>
jmp    1410 <serial_port_init+0x250>
jmp    1410 <serial_port_init+0x250>
jmp    1441 <serial_port_init+0x281>
mov    0x2ba4(%rip),%rax
mov    (%rax),%eax
mov    0x2b8b(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1441 <serial_port_init+0x281>
mov    0x2b87(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     1464 <serial_port_init+0x2a4>
mov    0x2ad9(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1476 <serial_port_init+0x2b6>
mov    0x2ac5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2abb(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x38(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    0x2b38(%rip),%rax
mov    (%rax),%ecx
mov    0x2b47(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    0x2ac4(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
not    %ecx
mov    -0x34(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
and    $0xc,%eax
mov    %eax,-0x58(%rbp)
je     14e8 <serial_port_init+0x328>
jmp    14c6 <serial_port_init+0x306>
mov    -0x58(%rbp),%eax
sub    $0x4,%eax
je     14f2 <serial_port_init+0x332>
jmp    14d7 <serial_port_init+0x317>
mov    -0x58(%rbp),%eax
sub    $0x8,%eax
je     1506 <serial_port_init+0x346>
jmp    14ed <serial_port_init+0x32d>
jmp    14ed <serial_port_init+0x32d>
jmp    151e <serial_port_init+0x35e>
mov    0x2a3f(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    151e <serial_port_init+0x35e>
mov    0x2abb(%rip),%rax
mov    (%rax),%eax
mov    0x2aca(%rip),%rcx
or     (%rcx),%eax
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2a5f(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    0x2a11(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    0x2a01(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
cmp    $0x0,%rax
je     1580 <serial_port_init+0x3c0>
lea    0xa9b(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1600 <serial_port_init+0x440>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    0x2a2b(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
je     15ba <serial_port_init+0x3fa>
lea    0xa57(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1600 <serial_port_init+0x440>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    0x29b1(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
call   1060 <ioctl@plt>
mov    0x29cf(%rip),%rax
mov    (%rax),%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    0x29ea(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
call   1060 <ioctl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_port_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r13
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1070 <assert@plt>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1070 <assert@plt>
mov    0x2deb(%rip),%rax
mov    0x2d5c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbp,%rdi
call   10b0 <open@plt>
mov    %eax,0x0(%r13)
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1468 <serial_port_init+0x2a8>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   10e0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <tcgetattr@plt>
test   %rax,%rax
jne    147a <serial_port_init+0x2ba>
mov    0x0(%r13),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x0(%r13),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    %r12d,%edi
call   1030 <serial_port_get_speed@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     1468 <serial_port_init+0x2a8>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   10c0 <cfsetispeed@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <cfsetospeed@plt>
mov    %rbx,%rdi
call   1080 <cfmakeraw@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x20(%rsp)
mov    0x2cc1(%rip),%rax
mov    0x2c6a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c37(%rip),%rax
or     (%rax),%edx
or     0x10(%rsp),%edx
mov    0x2c8a(%rip),%rax
mov    (%rax),%ecx
not    %ecx
and    %edx,%ecx
mov    %r15d,%eax
and    $0x60,%eax
cmp    $0x40,%eax
je     1319 <serial_port_init+0x159>
cmp    $0x20,%eax
je     1322 <serial_port_init+0x162>
test   %eax,%eax
jne    132b <serial_port_init+0x16b>
mov    0x2c79(%rip),%rax
jmp    1329 <serial_port_init+0x169>
mov    0x2c08(%rip),%rax
jmp    1329 <serial_port_init+0x169>
mov    0x2c77(%rip),%rax
or     (%rax),%ecx
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
mov    0x2c75(%rip),%rax
mov    (%rax),%edx
or     %esi,%edx
mov    %edx,%eax
not    %eax
and    %ecx,%eax
mov    %r15d,%edi
and    $0x3,%edi
cmp    $0x1,%edi
je     135b <serial_port_init+0x19b>
cmp    $0x2,%edi
jne    135d <serial_port_init+0x19d>
or     %edx,%ecx
mov    %ecx,%eax
jmp    135d <serial_port_init+0x19d>
or     %esi,%eax
mov    0x2bcc(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
not    %edx
and    %eax,%edx
or     %ecx,%eax
test   $0x10,%r15b
cmove  %edx,%eax
mov    0x2bbc(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
not    %edx
and    %eax,%edx
mov    %edx,0x10(%rsp)
mov    0x2c39(%rip),%rsi
mov    0x2c4a(%rip),%rdx
mov    (%rdx),%edx
or     (%rsi),%edx
mov    0x2bc7(%rip),%rsi
mov    (%rsi),%esi
or     %edx,%esi
not    %esi
and    0x14(%rsp),%esi
mov    %esi,0x14(%rsp)
and    $0xc,%r15d
cmp    $0x8,%r15d
je     13c7 <serial_port_init+0x207>
cmp    $0x4,%r15d
jne    13cd <serial_port_init+0x20d>
or     %eax,%ecx
mov    %ecx,0x10(%rsp)
jmp    13cd <serial_port_init+0x20d>
or     %edx,%esi
mov    %esi,0x14(%rsp)
mov    0x18(%rsp),%rax
mov    0x2baf(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2b65(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x0(%r13),%edi
mov    0x2b57(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
test   %rax,%rax
jne    1488 <serial_port_init+0x2c8>
mov    0x0(%r13),%edi
mov    0x2ba0(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   10a0 <tcsetattr@plt>
test   %rax,%rax
jne    147a <serial_port_init+0x2ba>
mov    0x0(%r13),%edi
mov    0x2b44(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <ioctl@plt>
mov    0x2b5e(%rip),%rax
mov    (%rax),%eax
or     %eax,0xc(%rsp)
mov    0x0(%r13),%edi
mov    0x2b7d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb7f(%rip),%rdi
call   10d0 <perror@plt>
jmp    1468 <serial_port_init+0x2a8>
lea    0xb7b(%rip),%rdi
call   10d0 <perror@plt>
jmp    1468 <serial_port_init+0x2a8>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [10 x i8] c"tcgetattr\00"
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMSET = global i32 0
@OPOST = global i32 0
@CREAD = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CS7 = global i32 0
@CS6 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIOFLUSH = global i32 0
@.str.1 = [8 x i8] c"tcflush\00"
@TCSANOW = global i32 0
define i32 @serial_port_init(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.termios
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32*, i32** %9
%18 = icmp ne i32* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %6
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_NOCTTY
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %21, i32 %24)
%26 = load i32*, i32** %9
store i32 %25, i32* %26
%27 = load i32*, i32** %9
%28 = load i32, i32* %27
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %4
store i32 -1, i32* %5
br label %204
31: ; preds = %4
%32 = call i32 @bzero(%struct.termios* %10, i32 24)
%33 = load i32*, i32** %9
%34 = load i32, i32* %33
%35 = call i64 @tcgetattr(i32 %34, %struct.termios* %10)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %204
39: ; preds = %31
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = load i32, i32* @TIOCMGET
%43 = call i32 @ioctl(i32 %41, i32 %42, i32* %11)
%44 = load i32, i32* @TIOCM_DTR
%45 = xor i32 %44, -1
%46 = load i32, i32* %11
%47 = and i32 %46, %45
store i32 %47, i32* %11
%48 = load i32*, i32** %9
%49 = load i32, i32* %48
%50 = load i32, i32* @TIOCMSET
%51 = call i32 @ioctl(i32 %49, i32 %50, i32* %11)
%52 = load i32, i32* %7
%53 = call i32 @serial_port_get_speed(i32 %52)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %57
56: ; preds = %39
store i32 -1, i32* %5
br label %204
57: ; preds = %39
%58 = load i32, i32* %12
%59 = call i32 @cfsetispeed(%struct.termios* %10, i32 %58)
%60 = load i32, i32* %12
%61 = call i32 @cfsetospeed(%struct.termios* %10, i32 %60)
%62 = call i32 @cfmakeraw(%struct.termios* %10)
%63 = load i32, i32* @OPOST
%64 = xor i32 %63, -1
%65 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 3
%66 = load i32, i32* %65
%67 = and i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @CREAD
%69 = load i32, i32* @HUPCL
%70 = or i32 %68, %69
%71 = load i32, i32* @CLOCAL
%72 = or i32 %70, %71
%73 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%74 = load i32, i32* %73
%75 = or i32 %74, %72
store i32 %75, i32* %73
%76 = load i32, i32* @CSIZE
%77 = xor i32 %76, -1
%78 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%79 = load i32, i32* %78
%80 = and i32 %79, %77
store i32 %80, i32* %78
%81 = load i32, i32* %8
%82 = and i32 %81, 96
switch i32 %82, label %98 [
i32 0, label %83
i32 64, label %88
i32 32, label %93
]
83: ; preds = %57
%84 = load i32, i32* @CS8
%85 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%86 = load i32, i32* %85
%87 = or i32 %86, %84
store i32 %87, i32* %85
br label %98
88: ; preds = %57
%89 = load i32, i32* @CS7
%90 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%91 = load i32, i32* %90
%92 = or i32 %91, %89
store i32 %92, i32* %90
br label %98
93: ; preds = %57
%94 = load i32, i32* @CS6
%95 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%96 = load i32, i32* %95
%97 = or i32 %96, %94
store i32 %97, i32* %95
br label %98
98: ; preds = %57, %93, %88, %83
%99 = load i32, i32* @PARENB
%100 = load i32, i32* @PARODD
%101 = or i32 %99, %100
%102 = xor i32 %101, -1
%103 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%104 = load i32, i32* %103
%105 = and i32 %104, %102
store i32 %105, i32* %103
%106 = load i32, i32* %8
%107 = and i32 %106, 3
switch i32 %107, label %109 [
i32 0, label %108
i32 2, label %110
i32 1, label %117
]
108: ; preds = %98
br label %109
109: ; preds = %98, %108
br label %122
110: ; preds = %98
%111 = load i32, i32* @PARENB
%112 = load i32, i32* @PARODD
%113 = or i32 %111, %112
%114 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%115 = load i32, i32* %114
%116 = or i32 %115, %113
store i32 %116, i32* %114
br label %122
117: ; preds = %98
%118 = load i32, i32* @PARENB
%119 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%120 = load i32, i32* %119
%121 = or i32 %120, %118
store i32 %121, i32* %119
br label %122
122: ; preds = %117, %110, %109
%123 = load i32, i32* %8
%124 = and i32 %123, 16
%125 = icmp ne i32 %124, 0
br i1 %125, label %126, label %131
126: ; preds = %122
%127 = load i32, i32* @CSTOPB
%128 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%129 = load i32, i32* %128
%130 = or i32 %129, %127
store i32 %130, i32* %128
br label %137
131: ; preds = %122
%132 = load i32, i32* @CSTOPB
%133 = xor i32 %132, -1
%134 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%135 = load i32, i32* %134
%136 = and i32 %135, %133
store i32 %136, i32* %134
br label %137
137: ; preds = %131, %126
%138 = load i32, i32* @CRTSCTS
%139 = xor i32 %138, -1
%140 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%141 = load i32, i32* %140
%142 = and i32 %141, %139
store i32 %142, i32* %140
%143 = load i32, i32* @IXON
%144 = load i32, i32* @IXOFF
%145 = or i32 %143, %144
%146 = load i32, i32* @IXANY
%147 = or i32 %145, %146
%148 = xor i32 %147, -1
%149 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%150 = load i32, i32* %149
%151 = and i32 %150, %148
store i32 %151, i32* %149
%152 = load i32, i32* %8
%153 = and i32 %152, 12
switch i32 %153, label %155 [
i32 0, label %154
i32 4, label %156
i32 8, label %161
]
154: ; preds = %137
br label %155
155: ; preds = %137, %154
br label %168
156: ; preds = %137
%157 = load i32, i32* @CRTSCTS
%158 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%159 = load i32, i32* %158
%160 = or i32 %159, %157
store i32 %160, i32* %158
br label %168
161: ; preds = %137
%162 = load i32, i32* @IXON
%163 = load i32, i32* @IXOFF
%164 = or i32 %162, %163
%165 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%166 = load i32, i32* %165
%167 = or i32 %166, %164
store i32 %167, i32* %165
br label %168
168: ; preds = %161, %156, %155
%169 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
%170 = load i64*, i64** %169
%171 = load i64, i64* @VMIN
%172 = getelementptr inbounds i64, i64* %170, i64 %171
store i64 0, i64* %172
%173 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
%174 = load i64*, i64** %173
%175 = load i64, i64* @VTIME
%176 = getelementptr inbounds i64, i64* %174, i64 %175
store i64 0, i64* %176
%177 = load i32*, i32** %9
%178 = load i32, i32* %177
%179 = load i32, i32* @TCIOFLUSH
%180 = call i64 @tcflush(i32 %178, i32 %179)
%181 = icmp ne i64 %180, 0
br i1 %181, label %182, label %184
182: ; preds = %168
%183 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %204
184: ; preds = %168
%185 = load i32*, i32** %9
%186 = load i32, i32* %185
%187 = load i32, i32* @TCSANOW
%188 = call i64 @tcsetattr(i32 %186, i32 %187, %struct.termios* %10)
%189 = icmp ne i64 %188, 0
br i1 %189, label %190, label %192
190: ; preds = %184
%191 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %204
192: ; preds = %184
%193 = load i32*, i32** %9
%194 = load i32, i32* %193
%195 = load i32, i32* @TIOCMGET
%196 = call i32 @ioctl(i32 %194, i32 %195, i32* %11)
%197 = load i32, i32* @TIOCM_DTR
%198 = load i32, i32* %11
%199 = or i32 %198, %197
store i32 %199, i32* %11
%200 = load i32*, i32** %9
%201 = load i32, i32* %200
%202 = load i32, i32* @TIOCMSET
%203 = call i32 @ioctl(i32 %201, i32 %202, i32* %11)
store i32 0, i32* %5
br label %204
204: ; preds = %192, %190, %182, %56, %37, %30
%205 = load i32, i32* %5
ret i32 %205
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [10 x i8] c"tcgetattr\00"
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMSET = global i32 0
@OPOST = global i32 0
@CREAD = global i32 0
@HUPCL = global i32 0
@CLOCAL = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CS7 = global i32 0
@CS6 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIOFLUSH = global i32 0
@.str.1 = [8 x i8] c"tcflush\00"
@TCSANOW = global i32 0
define i32 @serial_port_init(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca %struct.termios
%6 = alloca i32
%7 = bitcast %struct.termios* %5 to i8*
%8 = icmp ne i8* %0, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = icmp ne i32* %3, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_NOCTTY
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* %0, i32 %16)
store i32 %17, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %139, label %19
19: ; preds = %4
%20 = call i32 @bzero(%struct.termios* %5, i32 24)
%21 = call i64 @tcgetattr(i32 %17, %struct.termios* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %139
25: ; preds = %19
%26 = bitcast i32* %6 to i8*
%27 = load i32, i32* %3
%28 = load i32, i32* @TIOCMGET
%29 = call i32 @ioctl(i32 %27, i32 %28, i32* %6)
%30 = load i32, i32* @TIOCM_DTR
%31 = xor i32 %30, -1
%32 = load i32, i32* %6
%33 = and i32 %32, %31
store i32 %33, i32* %6
%34 = load i32, i32* %3
%35 = load i32, i32* @TIOCMSET
%36 = call i32 @ioctl(i32 %34, i32 %35, i32* %6)
%37 = call i32 @serial_port_get_speed(i32 %1)
%38 = icmp eq i32 %37, -1
br i1 %38, label %137, label %39
39: ; preds = %25
%40 = call i32 @cfsetispeed(%struct.termios* %5, i32 %37)
%41 = call i32 @cfsetospeed(%struct.termios* %5, i32 %37)
%42 = call i32 @cfmakeraw(%struct.termios* %5)
%43 = load i32, i32* @OPOST
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 3
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @CREAD
%49 = load i32, i32* @HUPCL
%50 = or i32 %49, %48
%51 = load i32, i32* @CLOCAL
%52 = or i32 %50, %51
%53 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%54 = load i32, i32* %53
%55 = or i32 %52, %54
%56 = load i32, i32* @CSIZE
%57 = xor i32 %56, -1
%58 = and i32 %55, %57
%59 = and i32 %2, 96
switch i32 %59, label %69 [
i32 0, label %60
i32 64, label %63
i32 32, label %66
]
60: ; preds = %39
%61 = load i32, i32* @CS8
%62 = or i32 %61, %58
br label %69
63: ; preds = %39
%64 = load i32, i32* @CS7
%65 = or i32 %64, %58
br label %69
66: ; preds = %39
%67 = load i32, i32* @CS6
%68 = or i32 %67, %58
br label %69
69: ; preds = %39, %66, %63, %60
%70 = phi i32 [ %58, %39 ], [ %68, %66 ], [ %65, %63 ], [ %62, %60 ]
%71 = load i32, i32* @PARENB
%72 = load i32, i32* @PARODD
%73 = or i32 %72, %71
%74 = xor i32 %73, -1
%75 = and i32 %70, %74
%76 = and i32 %2, 3
switch i32 %76, label %81 [
i32 1, label %79
i32 2, label %77
]
77: ; preds = %69
%78 = or i32 %70, %73
br label %81
79: ; preds = %69
%80 = or i32 %75, %71
br label %81
81: ; preds = %69, %79, %77
%82 = phi i32 [ %75, %69 ], [ %80, %79 ], [ %78, %77 ]
%83 = and i32 %2, 16
%84 = icmp eq i32 %83, 0
%85 = load i32, i32* @CSTOPB
%86 = xor i32 %85, -1
%87 = and i32 %82, %86
%88 = or i32 %82, %85
%89 = select i1 %84, i32 %87, i32 %88
%90 = load i32, i32* @CRTSCTS
%91 = xor i32 %90, -1
%92 = and i32 %89, %91
store i32 %92, i32* %53
%93 = load i32, i32* @IXON
%94 = load i32, i32* @IXOFF
%95 = or i32 %94, %93
%96 = load i32, i32* @IXANY
%97 = or i32 %95, %96
%98 = xor i32 %97, -1
%99 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 1
%100 = load i32, i32* %99
%101 = and i32 %100, %98
store i32 %101, i32* %99
%102 = and i32 %2, 12
switch i32 %102, label %107 [
i32 8, label %105
i32 4, label %103
]
103: ; preds = %81
%104 = or i32 %90, %89
store i32 %104, i32* %53
br label %107
105: ; preds = %81
%106 = or i32 %101, %95
store i32 %106, i32* %99
br label %107
107: ; preds = %81, %105, %103
%108 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 2
%109 = load i64*, i64** %108
%110 = load i64, i64* @VMIN
%111 = getelementptr inbounds i64, i64* %109, i64 %110
store i64 0, i64* %111
%112 = load i64, i64* @VTIME
%113 = getelementptr inbounds i64, i64* %109, i64 %112
store i64 0, i64* %113
%114 = load i32, i32* %3
%115 = load i32, i32* @TCIOFLUSH
%116 = call i64 @tcflush(i32 %114, i32 %115)
%117 = icmp eq i64 %116, 0
br i1 %117, label %120, label %118
118: ; preds = %107
%119 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %137
120: ; preds = %107
%121 = load i32, i32* %3
%122 = load i32, i32* @TCSANOW
%123 = call i64 @tcsetattr(i32 %121, i32 %122, %struct.termios* %5)
%124 = icmp eq i64 %123, 0
br i1 %124, label %127, label %125
125: ; preds = %120
%126 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %137
127: ; preds = %120
%128 = load i32, i32* %3
%129 = load i32, i32* @TIOCMGET
%130 = call i32 @ioctl(i32 %128, i32 %129, i32* %6)
%131 = load i32, i32* @TIOCM_DTR
%132 = load i32, i32* %6
%133 = or i32 %132, %131
store i32 %133, i32* %6
%134 = load i32, i32* %3
%135 = load i32, i32* @TIOCMSET
%136 = call i32 @ioctl(i32 %134, i32 %135, i32* %6)
br label %137
137: ; preds = %25, %127, %125, %118
%138 = phi i32 [ -1, %118 ], [ -1, %125 ], [ 0, %127 ], [ -1, %25 ]
br label %139
139: ; preds = %4, %137, %23
%140 = phi i32 [ -1, %23 ], [ %138, %137 ], [ -1, %4 ]
ret i32 %140
}