#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 /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_iflag;
};
struct serial_struct {
  int custom_divisor;
  int /*<<< orphan*/ flags;
};

/* Variables and functions */
int /*<<< orphan*/ ASYNC_SPD_CUST;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B38400;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int /*<<< orphan*/ ICRNL;
int /*<<< orphan*/ IGNBRK;
int /*<<< orphan*/ IGNCR;
int /*<<< orphan*/ INLCR;
int ISIG;
int /*<<< orphan*/ IXOFF;
int /*<<< orphan*/ IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCGSERIAL;
int /*<<< orphan*/ TIOCSSERIAL;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct serial_struct *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int openSwbPortDiv(char *port, int divisor) {
  int fd;
  fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
  struct termios options;
  struct serial_struct ser;
  if (tcgetattr(fd, &options) < 0)
    perror("tcGetattr");
  if (divisor == 0) {
    cfsetispeed(&options, B19200);
    cfsetospeed(&options, B19200);
  } else if (divisor >= 0) {
    if (divisor > 65536)
      divisor = 65536;
    cfsetispeed(&options, B38400);
    cfsetospeed(&options, B38400);
    if (ioctl(fd, TIOCGSERIAL, &ser) < 0)
      perror("tioGserial");
    ser.flags |= ASYNC_SPD_CUST;
    ser.custom_divisor = divisor;
    if (ioctl(fd, TIOCSSERIAL, &ser) < 0)
      perror("tioSserial");
  }
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~CSIZE;
  options.c_cflag &= ~PARENB;
  options.c_cflag |= CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_iflag &= ~IXON;
  options.c_iflag &= ~IXOFF;
  options.c_iflag &= ~IGNCR;
  options.c_iflag &= ~ICRNL;
  options.c_iflag &= ~INLCR;
  options.c_iflag |= IGNBRK;
  options.c_oflag &= ~OPOST;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  if (tcsetattr(fd, TCSANOW, &options) < 0)
    perror("tcsetattr");
  return fd;
}


x86 assembly (clang, -O0):
<openSwbPortDiv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2db5(%rip),%rax
or     (%rax),%esi
mov    0x2da4(%rip),%rax
or     (%rax),%esi
mov    0x2e0b(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11d1 <openSwbPortDiv+0x61>
lea    0xe34(%rip),%rdi
call   1090 <perror@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1204 <openSwbPortDiv+0x94>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    12bb <openSwbPortDiv+0x14b>
cmpl   $0x0,-0xc(%rbp)
jl     12b6 <openSwbPortDiv+0x146>
cmpl   $0x10000,-0xc(%rbp)
jle    1222 <openSwbPortDiv+0xb2>
movl   $0x10000,-0xc(%rbp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x10(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1271 <openSwbPortDiv+0x101>
lea    0xd9e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    12b1 <openSwbPortDiv+0x141>
lea    0xd69(%rip),%rdi
call   1090 <perror@plt>
jmp    12b6 <openSwbPortDiv+0x146>
jmp    12bb <openSwbPortDiv+0x14b>
mov    0x2c4e(%rip),%rax
mov    (%rax),%eax
mov    0x2c9d(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ca4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c1a(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c4b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c6a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2c56(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2c64(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2ba8(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2c09(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2b7f(%rip),%rax
mov    (%rax),%eax
mov    0x2bce(%rip),%rcx
or     (%rcx),%eax
mov    0x2bbd(%rip),%rcx
or     (%rcx),%eax
mov    0x2bac(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2baf(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
jge    13fa <openSwbPortDiv+0x28a>
lea    0xc2b(%rip),%rdi
call   1090 <perror@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openSwbPortDiv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e4f(%rip),%rcx
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2dad(%rip),%rcx
or     (%rcx),%eax
mov    %esi,%ebp
mov    0x2e12(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     1252 <openSwbPortDiv+0xe2>
test   %ebp,%ebp
je     1266 <openSwbPortDiv+0xf6>
js     1284 <openSwbPortDiv+0x114>
cmp    $0x10000,%ebp
mov    $0x10000,%ebx
cmovb  %ebp,%ebx
mov    0x2d28(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1080 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1378 <openSwbPortDiv+0x208>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
or     %eax,0x14(%rsp)
mov    %ebx,0x10(%rsp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jns    1284 <openSwbPortDiv+0x114>
lea    0xdca(%rip),%rdi
call   1090 <perror@plt>
jmp    1284 <openSwbPortDiv+0x114>
lea    0xda7(%rip),%rdi
call   1090 <perror@plt>
test   %ebp,%ebp
jne    11c5 <openSwbPortDiv+0x55>
mov    0x2d7b(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1080 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %rbp,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2c85(%rip),%rax
mov    0x2cd6(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,%edx
not    %edx
mov    0x2ce3(%rip),%rsi
or     (%rsi),%eax
not    %eax
and    %ecx,%eax
mov    0x2c5e(%rip),%rcx
or     (%rcx),%eax
and    %edx,%eax
mov    0x2c9b(%rip),%rcx
or     (%rcx),%eax
mov    0x2cca(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2ce1(%rip),%rdx
or     (%rdx),%ecx
mov    0x2cc8(%rip),%rdx
or     (%rdx),%ecx
mov    0x2cdf(%rip),%rdx
or     (%rdx),%ecx
mov    0x2cce(%rip),%rdx
or     (%rdx),%ecx
mov    %eax,(%rsp)
not    %ecx
and    0xc(%rsp),%ecx
mov    0x2c2c(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    0x2c08(%rip),%rax
mov    0x2c59(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c46(%rip),%rax
or     (%rax),%ecx
mov    0x2c35(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r14d,%edi
call   1060 <tcsetattr@plt>
test   %rax,%rax
js     136a <openSwbPortDiv+0x1fa>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcaf(%rip),%rdi
call   1090 <perror@plt>
jmp    135c <openSwbPortDiv+0x1ec>
lea    0xc8b(%rip),%rdi
call   1090 <perror@plt>
jmp    1218 <openSwbPortDiv+0xa8>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
%struct.serial_struct = type { i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [10 x i8] c"tcGetattr\00"
@B19200 = global i32 0
@B38400 = global i32 0
@TIOCGSERIAL = global i32 0
@.str.1 = [11 x i8] c"tioGserial\00"
@ASYNC_SPD_CUST = global i32 0
@TIOCSSERIAL = global i32 0
@.str.2 = [11 x i8] c"tioSserial\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CS8 = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNBRK = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str.3 = [10 x i8] c"tcsetattr\00"
define i32 @openSwbPortDiv(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca %struct.serial_struct
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_NOCTTY
%11 = or i32 %9, %10
%12 = load i32, i32* @O_NDELAY
%13 = or i32 %11, %12
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %8, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = call i64 @tcgetattr(i32 %17, %struct.termios* %6)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @B19200
%27 = call i32 @cfsetispeed(%struct.termios* %6, i32 %26)
%28 = load i32, i32* @B19200
%29 = call i32 @cfsetospeed(%struct.termios* %6, i32 %28)
br label %63
30: ; preds = %22
%31 = load i32, i32* %4
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %62
33: ; preds = %30
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 65536
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 65536, i32* %4
br label %37
37: ; preds = %36, %33
%38 = load i32, i32* @B38400
%39 = call i32 @cfsetispeed(%struct.termios* %6, i32 %38)
%40 = load i32, i32* @B38400
%41 = call i32 @cfsetospeed(%struct.termios* %6, i32 %40)
%42 = load i32, i32* %5
%43 = load i32, i32* @TIOCGSERIAL
%44 = call i64 @ioctl(i32 %42, i32 %43, %struct.serial_struct* %7)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %37
%47 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %37
%49 = load i32, i32* @ASYNC_SPD_CUST
%50 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %7, i32 0, i32 1
%51 = load i32, i32* %50
%52 = or i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* %4
%54 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %7, i32 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* %5
%56 = load i32, i32* @TIOCSSERIAL
%57 = call i64 @ioctl(i32 %55, i32 %56, %struct.serial_struct* %7)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %48
%60 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %48
br label %62
62: ; preds = %61, %30
br label %63
63: ; preds = %62, %25
%64 = load i32, i32* @CLOCAL
%65 = load i32, i32* @CREAD
%66 = or i32 %64, %65
%67 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%68 = load i32, i32* %67
%69 = or i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* @CSIZE
%71 = xor i32 %70, -1
%72 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%73 = load i32, i32* %72
%74 = and i32 %73, %71
store i32 %74, i32* %72
%75 = load i32, i32* @PARENB
%76 = xor i32 %75, -1
%77 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%78 = load i32, i32* %77
%79 = and i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* @CSTOPB
%81 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%82 = load i32, i32* %81
%83 = or 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* @IXON
%94 = xor i32 %93, -1
%95 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%96 = load i32, i32* %95
%97 = and i32 %96, %94
store i32 %97, i32* %95
%98 = load i32, i32* @IXOFF
%99 = xor i32 %98, -1
%100 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%101 = load i32, i32* %100
%102 = and i32 %101, %99
store i32 %102, i32* %100
%103 = load i32, i32* @IGNCR
%104 = xor i32 %103, -1
%105 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%106 = load i32, i32* %105
%107 = and i32 %106, %104
store i32 %107, i32* %105
%108 = load i32, i32* @ICRNL
%109 = xor i32 %108, -1
%110 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%111 = load i32, i32* %110
%112 = and i32 %111, %109
store i32 %112, i32* %110
%113 = load i32, i32* @INLCR
%114 = xor i32 %113, -1
%115 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%116 = load i32, i32* %115
%117 = and i32 %116, %114
store i32 %117, i32* %115
%118 = load i32, i32* @IGNBRK
%119 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%120 = load i32, i32* %119
%121 = or i32 %120, %118
store i32 %121, i32* %119
%122 = load i32, i32* @OPOST
%123 = xor i32 %122, -1
%124 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%125 = load i32, i32* %124
%126 = and i32 %125, %123
store i32 %126, i32* %124
%127 = load i32, i32* @ICANON
%128 = load i32, i32* @ECHO
%129 = or i32 %127, %128
%130 = load i32, i32* @ECHOE
%131 = or i32 %129, %130
%132 = load i32, i32* @ISIG
%133 = or i32 %131, %132
%134 = xor i32 %133, -1
%135 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%136 = load i32, i32* %135
%137 = and i32 %136, %134
store i32 %137, i32* %135
%138 = load i32, i32* %5
%139 = load i32, i32* @TCSANOW
%140 = call i64 @tcsetattr(i32 %138, i32 %139, %struct.termios* %6)
%141 = icmp slt i64 %140, 0
br i1 %141, label %142, label %144
142: ; preds = %63
%143 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %144
144: ; preds = %142, %63
%145 = load i32, i32* %5
ret i32 %145
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
%struct.serial_struct = type { i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [10 x i8] c"tcGetattr\00"
@B19200 = global i32 0
@B38400 = global i32 0
@TIOCGSERIAL = global i32 0
@.str.1 = [11 x i8] c"tioGserial\00"
@ASYNC_SPD_CUST = global i32 0
@TIOCSSERIAL = global i32 0
@.str.2 = [11 x i8] c"tioSserial\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CS8 = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNBRK = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str.3 = [10 x i8] c"tcsetattr\00"
define i32 @openSwbPortDiv(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.serial_struct
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %6, %5
%8 = load i32, i32* @O_NDELAY
%9 = or i32 %7, %8
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %9, %10
%12 = tail call i32 @open(i8* %0, i32 %11)
%13 = bitcast %struct.termios* %3 to i8*
%14 = bitcast %struct.serial_struct* %4 to i8*
%15 = call i64 @tcgetattr(i32 %12, %struct.termios* %3)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = icmp eq i32 %1, 0
br i1 %20, label %21, label %26
21: ; preds = %19
%22 = load i32, i32* @B19200
%23 = call i32 @cfsetispeed(%struct.termios* %3, i32 %22)
%24 = load i32, i32* @B19200
%25 = call i32 @cfsetospeed(%struct.termios* %3, i32 %24)
br label %51
26: ; preds = %19
%27 = icmp sgt i32 %1, -1
br i1 %27, label %28, label %51
28: ; preds = %26
%29 = icmp ult i32 %1, 65536
%30 = select i1 %29, i32 %1, i32 65536
%31 = load i32, i32* @B38400
%32 = call i32 @cfsetispeed(%struct.termios* %3, i32 %31)
%33 = load i32, i32* @B38400
%34 = call i32 @cfsetospeed(%struct.termios* %3, i32 %33)
%35 = load i32, i32* @TIOCGSERIAL
%36 = call i64 @ioctl(i32 %12, i32 %35, %struct.serial_struct* %4)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %28
%39 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %28
%41 = load i32, i32* @ASYNC_SPD_CUST
%42 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %4, i64 0, i32 1
%43 = load i32, i32* %42
%44 = or i32 %43, %41
store i32 %44, i32* %42
%45 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %4, i64 0, i32 0
store i32 %30, i32* %45
%46 = load i32, i32* @TIOCSSERIAL
%47 = call i64 @ioctl(i32 %12, i32 %46, %struct.serial_struct* %4)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %40
%50 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %26, %49, %40, %21
%52 = load i32, i32* @CLOCAL
%53 = load i32, i32* @CREAD
%54 = or i32 %53, %52
%55 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%56 = load i32, i32* %55
%57 = or i32 %54, %56
%58 = load i32, i32* @CSIZE
%59 = xor i32 %58, -1
%60 = load i32, i32* @PARENB
%61 = or i32 %58, %60
%62 = xor i32 %61, -1
%63 = and i32 %57, %62
%64 = load i32, i32* @CSTOPB
%65 = or i32 %64, %63
%66 = and i32 %65, %59
%67 = load i32, i32* @CS8
%68 = or i32 %66, %67
store i32 %68, i32* %55
%69 = load i32, i32* @IXON
%70 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%71 = load i32, i32* %70
%72 = load i32, i32* @IXOFF
%73 = or i32 %69, %72
%74 = load i32, i32* @IGNCR
%75 = or i32 %73, %74
%76 = load i32, i32* @ICRNL
%77 = or i32 %75, %76
%78 = load i32, i32* @INLCR
%79 = or i32 %77, %78
%80 = xor i32 %79, -1
%81 = and i32 %71, %80
%82 = load i32, i32* @IGNBRK
%83 = or i32 %82, %81
store i32 %83, i32* %70
%84 = load i32, i32* @OPOST
%85 = xor i32 %84, -1
%86 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%87 = load i32, i32* %86
%88 = and i32 %87, %85
store i32 %88, i32* %86
%89 = load i32, i32* @ICANON
%90 = load i32, i32* @ECHO
%91 = or i32 %90, %89
%92 = load i32, i32* @ECHOE
%93 = or i32 %91, %92
%94 = load i32, i32* @ISIG
%95 = or i32 %93, %94
%96 = xor i32 %95, -1
%97 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%98 = load i32, i32* %97
%99 = and i32 %98, %96
store i32 %99, i32* %97
%100 = load i32, i32* @TCSANOW
%101 = call i64 @tcsetattr(i32 %12, i32 %100, %struct.termios* %3)
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %51
%104 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %105
105: ; preds = %103, %51
ret i32 %12
}