#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_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 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 |= CS8;
  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_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    0x2dbd(%rip),%rax
or     (%rax),%esi
mov    0x2dac(%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    0x2ce7(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x10(%rbp),%edi
mov    0x2cf0(%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    0x2c56(%rip),%rax
mov    (%rax),%eax
mov    0x2ca5(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c13(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c44(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c3a(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c63(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c69(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c55(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ba1(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
mov    0x2bd9(%rip),%rcx
or     (%rcx),%eax
mov    0x2bc8(%rip),%rcx
or     (%rcx),%eax
mov    0x2bb7(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2bba(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
jge    13f7 <openSwbPortDiv+0x287>
lea    0xc2e(%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    0x2dc8(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2db5(%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    0x2d30(%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    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     136d <openSwbPortDiv+0x1fd>
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    0x2c8d(%rip),%rax
mov    0x2cde(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%ecx
mov    0x2cbb(%rip),%rdx
mov    (%rdx),%edx
or     %edx,%ecx
mov    0x2ce0(%rip),%rsi
mov    (%rsi),%esi
not    %esi
and    %ecx,%esi
mov    0x2c5b(%rip),%rcx
or     (%rcx),%esi
mov    0x2cd2(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2ce1(%rip),%rdi
or     (%rdi),%ecx
mov    0x2cc8(%rip),%rdi
or     (%rdi),%ecx
and    %eax,%esi
mov    0x2cdd(%rip),%rax
or     (%rax),%ecx
or     %edx,%esi
mov    0x2cca(%rip),%rax
or     (%rax),%ecx
mov    %esi,(%rsp)
not    %ecx
and    0x8(%rsp),%ecx
mov    0x2c30(%rip),%rax
or     (%rax),%ecx
mov    0x2c1f(%rip),%rax
mov    0x2c70(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2c5d(%rip),%rax
or     (%rax),%edx
mov    %ecx,0x8(%rsp)
mov    0x2c48(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2c51(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r14d,%edi
call   1060 <tcsetattr@plt>
test   %rax,%rax
js     135f <openSwbPortDiv+0x1ef>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcba(%rip),%rdi
call   1090 <perror@plt>
jmp    1351 <openSwbPortDiv+0x1e1>
lea    0xc96(%rip),%rdi
call   1090 <perror@plt>
jmp    1218 <openSwbPortDiv+0xa8>

LLVM IR (-O0):
%struct.termios = type { 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
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = 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
@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* @CS8
%76 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%77 = load i32, i32* %76
%78 = or i32 %77, %75
store i32 %78, i32* %76
%79 = load i32, i32* @PARENB
%80 = xor i32 %79, -1
%81 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%82 = load i32, i32* %81
%83 = and i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* @CSTOPB
%85 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%86 = load i32, i32* %85
%87 = or i32 %86, %84
store i32 %87, i32* %85
%88 = load i32, i32* @CSIZE
%89 = xor i32 %88, -1
%90 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%91 = load i32, i32* %90
%92 = and i32 %91, %89
store i32 %92, i32* %90
%93 = load i32, i32* @CS8
%94 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%95 = load i32, i32* %94
%96 = or i32 %95, %93
store i32 %96, i32* %94
%97 = load i32, i32* @IXON
%98 = xor i32 %97, -1
%99 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%100 = load i32, i32* %99
%101 = and i32 %100, %98
store i32 %101, i32* %99
%102 = load i32, i32* @IXOFF
%103 = xor i32 %102, -1
%104 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%105 = load i32, i32* %104
%106 = and i32 %105, %103
store i32 %106, i32* %104
%107 = load i32, i32* @IGNCR
%108 = xor i32 %107, -1
%109 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%110 = load i32, i32* %109
%111 = and i32 %110, %108
store i32 %111, i32* %109
%112 = load i32, i32* @ICRNL
%113 = xor i32 %112, -1
%114 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%115 = load i32, i32* %114
%116 = and i32 %115, %113
store i32 %116, i32* %114
%117 = load i32, i32* @INLCR
%118 = xor i32 %117, -1
%119 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%120 = load i32, i32* %119
%121 = and i32 %120, %118
store i32 %121, i32* %119
%122 = load i32, i32* @IGNBRK
%123 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%124 = load i32, i32* %123
%125 = or i32 %124, %122
store i32 %125, i32* %123
%126 = load i32, i32* @ICANON
%127 = load i32, i32* @ECHO
%128 = or i32 %126, %127
%129 = load i32, i32* @ECHOE
%130 = or i32 %128, %129
%131 = load i32, i32* @ISIG
%132 = or i32 %130, %131
%133 = xor i32 %132, -1
%134 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%135 = load i32, i32* %134
%136 = and i32 %135, %133
store i32 %136, i32* %134
%137 = load i32, i32* %5
%138 = load i32, i32* @TCSANOW
%139 = call i64 @tcsetattr(i32 %137, i32 %138, %struct.termios* %6)
%140 = icmp slt i64 %139, 0
br i1 %140, label %141, label %143
141: ; preds = %63
%142 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %143
143: ; preds = %141, %63
%144 = load i32, i32* %5
ret i32 %144
}

LLVM IR (-O2):
%struct.termios = type { 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
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = 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
@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 = and i32 %57, %59
%61 = load i32, i32* @CS8
%62 = or i32 %61, %60
%63 = load i32, i32* @PARENB
%64 = xor i32 %63, -1
%65 = and i32 %62, %64
%66 = load i32, i32* @CSTOPB
%67 = or i32 %66, %65
%68 = and i32 %67, %59
%69 = or i32 %68, %61
store i32 %69, i32* %55
%70 = load i32, i32* @IXON
%71 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%72 = load i32, i32* %71
%73 = load i32, i32* @IXOFF
%74 = or i32 %70, %73
%75 = load i32, i32* @IGNCR
%76 = or i32 %74, %75
%77 = load i32, i32* @ICRNL
%78 = or i32 %76, %77
%79 = load i32, i32* @INLCR
%80 = or i32 %78, %79
%81 = xor i32 %80, -1
%82 = and i32 %72, %81
%83 = load i32, i32* @IGNBRK
%84 = or i32 %83, %82
store i32 %84, i32* %71
%85 = load i32, i32* @ICANON
%86 = load i32, i32* @ECHO
%87 = or i32 %86, %85
%88 = load i32, i32* @ECHOE
%89 = or i32 %87, %88
%90 = load i32, i32* @ISIG
%91 = or i32 %89, %90
%92 = xor i32 %91, -1
%93 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%94 = load i32, i32* %93
%95 = and i32 %94, %92
store i32 %95, i32* %93
%96 = load i32, i32* @TCSANOW
%97 = call i64 @tcsetattr(i32 %12, i32 %96, %struct.termios* %3)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %51
%100 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %101
101: ; preds = %99, %51
ret i32 %12
}