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

/* Variables and functions */
int B115200;
int B19200;
int B38400;
int B4800;
int B57600;
int B9600;
int CLOCAL;
int CREAD;
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_NONBLOCK;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int open(char const *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serialport_init(const char *serialport, int baud, char wait) {
  struct termios toptions;
  int fd;
  fd = open(serialport, O_RDWR | O_NONBLOCK);
  if (fd == -1) {
    if (!wait)
      perror("serialport_init: Unable to open port ");
    return -1;
  }
  if (tcgetattr(fd, &toptions) < 0) {
    if (!wait)
      perror("serialport_init: Couldn't get term attributes");
    return -1;
  }
  speed_t brate = baud;
  switch (baud) {
  case 4800:
    brate = B4800;
    break;
  case 9600:
    brate = B9600;
    break;
  case 19200:
    brate = B19200;
    break;
  case 38400:
    brate = B38400;
    break;
  case 57600:
    brate = B57600;
    break;
  case 115200:
    brate = B115200;
    break;
  }
  cfsetispeed(&toptions, brate);
  cfsetospeed(&toptions, brate);
  toptions.c_cflag &= ~PARENB;
  toptions.c_cflag &= ~CSTOPB;
  toptions.c_cflag &= ~CSIZE;
  toptions.c_cflag |= CS8;
  toptions.c_cflag &= ~CRTSCTS;
  toptions.c_cflag |= CREAD | CLOCAL;
  toptions.c_iflag &= ~(IXON | IXOFF | IXANY);
  toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  toptions.c_oflag &= ~OPOST;
  toptions.c_cc[VMIN] = 0;
  toptions.c_cc[VTIME] = 0;
  tcsetattr(fd, TCSANOW, &toptions);
  if (tcsetattr(fd, TCSAFLUSH, &toptions) < 0) {
    if (!wait)
      perror("init_serialport: Couldn't set term attributes");
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<serialport_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11be <serialport_init+0x5e>
cmpb   $0x0,-0x15(%rbp)
jne    11b2 <serialport_init+0x52>
lea    0xe53(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1444 <serialport_init+0x2e4>
mov    -0x3c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11f6 <serialport_init+0x96>
cmpb   $0x0,-0x15(%rbp)
jne    11ea <serialport_init+0x8a>
lea    0xe41(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1444 <serialport_init+0x2e4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x12c0,%eax
je     1271 <serialport_init+0x111>
jmp    1212 <serialport_init+0xb2>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     1282 <serialport_init+0x122>
jmp    1225 <serialport_init+0xc5>
mov    -0x44(%rbp),%eax
sub    $0x4b00,%eax
je     1293 <serialport_init+0x133>
jmp    1238 <serialport_init+0xd8>
mov    -0x44(%rbp),%eax
sub    $0x9600,%eax
je     12a4 <serialport_init+0x144>
jmp    124b <serialport_init+0xeb>
mov    -0x44(%rbp),%eax
sub    $0xe100,%eax
je     12b5 <serialport_init+0x155>
jmp    125e <serialport_init+0xfe>
mov    -0x44(%rbp),%eax
sub    $0x1c200,%eax
je     12c6 <serialport_init+0x166>
jmp    12d2 <serialport_init+0x172>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    12d2 <serialport_init+0x172>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    12d2 <serialport_init+0x172>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    12d2 <serialport_init+0x172>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    12d2 <serialport_init+0x172>
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    12d2 <serialport_init+0x172>
mov    0x2c73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x40(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c15(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c4b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c49(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bea(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c30(%rip),%rax
mov    (%rax),%eax
mov    0x2bbf(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c58(%rip),%rax
mov    (%rax),%eax
mov    0x2c67(%rip),%rcx
or     (%rcx),%eax
mov    0x2bd6(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2bac(%rip),%rax
mov    (%rax),%eax
mov    0x2c13(%rip),%rcx
or     (%rcx),%eax
mov    0x2c02(%rip),%rcx
or     (%rcx),%eax
mov    0x2bf1(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c0f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2ba1(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2b5b(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%edi
mov    0x2bb6(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x3c(%rbp),%edi
mov    0x2bd1(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    143e <serialport_init+0x2de>
cmpb   $0x0,-0x15(%rbp)
jne    1432 <serialport_init+0x2d2>
lea    0xc27(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1444 <serialport_init+0x2e4>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialport_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    0x2e6a(%rip),%rax
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11cb <serialport_init+0x6b>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1040 <tcgetattr@plt>
test   %rax,%rax
js     11e5 <serialport_init+0x85>
cmp    $0x95ff,%ebp
jg     11ff <serialport_init+0x9f>
cmp    $0x12c0,%ebp
je     1220 <serialport_init+0xc0>
cmp    $0x2580,%ebp
je     1229 <serialport_init+0xc9>
cmp    $0x4b00,%ebp
jne    1244 <serialport_init+0xe4>
mov    0x2e27(%rip),%rax
jmp    1242 <serialport_init+0xe2>
mov    $0xffffffff,%ebx
test   %r14b,%r14b
jne    136e <serialport_init+0x20e>
lea    0xe20(%rip),%rdi
jmp    1369 <serialport_init+0x209>
mov    $0xffffffff,%ebx
test   %r14b,%r14b
jne    136e <serialport_init+0x20e>
lea    0xe2c(%rip),%rdi
jmp    1369 <serialport_init+0x209>
cmp    $0x9600,%ebp
je     1232 <serialport_init+0xd2>
cmp    $0xe100,%ebp
je     123b <serialport_init+0xdb>
cmp    $0x1c200,%ebp
jne    1244 <serialport_init+0xe4>
mov    0x2d22(%rip),%rax
jmp    1242 <serialport_init+0xe2>
mov    0x2d61(%rip),%rax
jmp    1242 <serialport_init+0xe2>
mov    0x2d50(%rip),%rax
jmp    1242 <serialport_init+0xe2>
mov    0x2ccf(%rip),%rax
jmp    1242 <serialport_init+0xe2>
mov    0x2d16(%rip),%rax
mov    (%rax),%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    0x2cab(%rip),%rcx
or     (%rcx),%eax
mov    0x2cea(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2ceb(%rip),%rcx
or     (%rcx),%eax
mov    0x2c92(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2cdd(%rip),%rax
mov    0x2c6e(%rip),%rdx
or     (%rax),%ecx
or     (%rdx),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d07(%rip),%rax
mov    0x2d18(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c85(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2c5e(%rip),%rax
mov    0x2cc7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cb4(%rip),%rax
or     (%rax),%ecx
mov    0x2ca3(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x20(%rsp)
mov    0x18(%rsp),%rax
mov    0x2c58(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c16(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c74(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1050 <tcsetattr@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1050 <tcsetattr@plt>
test   %rax,%rax
jns    136e <serialport_init+0x20e>
mov    $0xffffffff,%ebx
test   %r14b,%r14b
jne    136e <serialport_init+0x20e>
lea    0xceb(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str = [38 x i8] c"serialport_init: Unable to open port \00"
@.str.1 = [46 x i8] c"serialport_init: Couldn't get term attributes\00"
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@TCSAFLUSH = global i32 0
@.str.2 = [46 x i8] c"init_serialport: Couldn't set term attributes\00"
define i32 @serialport_init(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca %struct.termios
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8 %2, i8* %7
%11 = load i8*, i8** %5
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_NONBLOCK
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %11, i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %3
%19 = load i8, i8* %7
%20 = icmp ne i8 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
store i32 -1, i32* %4
br label %132
24: ; preds = %3
%25 = load i32, i32* %9
%26 = call i64 @tcgetattr(i32 %25, %struct.termios* %8)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i8, i8* %7
%30 = icmp ne i8 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
store i32 -1, i32* %4
br label %132
34: ; preds = %24
%35 = load i32, i32* %6
store i32 %35, i32* %10
%36 = load i32, i32* %6
switch i32 %36, label %49 [
i32 4800, label %37
i32 9600, label %39
i32 19200, label %41
i32 38400, label %43
i32 57600, label %45
i32 115200, label %47
]
37: ; preds = %34
%38 = load i32, i32* @B4800
store i32 %38, i32* %10
br label %49
39: ; preds = %34
%40 = load i32, i32* @B9600
store i32 %40, i32* %10
br label %49
41: ; preds = %34
%42 = load i32, i32* @B19200
store i32 %42, i32* %10
br label %49
43: ; preds = %34
%44 = load i32, i32* @B38400
store i32 %44, i32* %10
br label %49
45: ; preds = %34
%46 = load i32, i32* @B57600
store i32 %46, i32* %10
br label %49
47: ; preds = %34
%48 = load i32, i32* @B115200
store i32 %48, i32* %10
br label %49
49: ; preds = %34, %47, %45, %43, %41, %39, %37
%50 = load i32, i32* %10
%51 = call i32 @cfsetispeed(%struct.termios* %8, i32 %50)
%52 = load i32, i32* %10
%53 = call i32 @cfsetospeed(%struct.termios* %8, i32 %52)
%54 = load i32, i32* @PARENB
%55 = xor i32 %54, -1
%56 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%57 = load i32, i32* %56
%58 = and i32 %57, %55
store i32 %58, i32* %56
%59 = load i32, i32* @CSTOPB
%60 = xor i32 %59, -1
%61 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%62 = load i32, i32* %61
%63 = and i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* @CSIZE
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @CS8
%70 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%71 = load i32, i32* %70
%72 = or i32 %71, %69
store i32 %72, i32* %70
%73 = load i32, i32* @CRTSCTS
%74 = xor i32 %73, -1
%75 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%76 = load i32, i32* %75
%77 = and i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* @CREAD
%79 = load i32, i32* @CLOCAL
%80 = or i32 %78, %79
%81 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%82 = load i32, i32* %81
%83 = or i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* @IXON
%85 = load i32, i32* @IXOFF
%86 = or i32 %84, %85
%87 = load i32, i32* @IXANY
%88 = or i32 %86, %87
%89 = xor i32 %88, -1
%90 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%91 = load i32, i32* %90
%92 = and i32 %91, %89
store i32 %92, i32* %90
%93 = load i32, i32* @ICANON
%94 = load i32, i32* @ECHO
%95 = or i32 %93, %94
%96 = load i32, i32* @ECHOE
%97 = or i32 %95, %96
%98 = load i32, i32* @ISIG
%99 = or i32 %97, %98
%100 = xor i32 %99, -1
%101 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%102 = load i32, i32* %101
%103 = and i32 %102, %100
store i32 %103, i32* %101
%104 = load i32, i32* @OPOST
%105 = xor i32 %104, -1
%106 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
%107 = load i32, i32* %106
%108 = and i32 %107, %105
store i32 %108, i32* %106
%109 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%110 = load i64*, i64** %109
%111 = load i64, i64* @VMIN
%112 = getelementptr inbounds i64, i64* %110, i64 %111
store i64 0, i64* %112
%113 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%114 = load i64*, i64** %113
%115 = load i64, i64* @VTIME
%116 = getelementptr inbounds i64, i64* %114, i64 %115
store i64 0, i64* %116
%117 = load i32, i32* %9
%118 = load i32, i32* @TCSANOW
%119 = call i64 @tcsetattr(i32 %117, i32 %118, %struct.termios* %8)
%120 = load i32, i32* %9
%121 = load i32, i32* @TCSAFLUSH
%122 = call i64 @tcsetattr(i32 %120, i32 %121, %struct.termios* %8)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %130
124: ; preds = %49
%125 = load i8, i8* %7
%126 = icmp ne i8 %125, 0
br i1 %126, label %129, label %127
127: ; preds = %124
%128 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %129
129: ; preds = %127, %124
store i32 -1, i32* %4
br label %132
130: ; preds = %49
%131 = load i32, i32* %9
store i32 %131, i32* %4
br label %132
132: ; preds = %130, %129, %33, %23
%133 = load i32, i32* %4
ret i32 %133
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str = [38 x i8] c"serialport_init: Unable to open port \00"
@.str.1 = [46 x i8] c"serialport_init: Couldn't get term attributes\00"
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@TCSAFLUSH = global i32 0
@.str.2 = [46 x i8] c"init_serialport: Couldn't set term attributes\00"
define i32 @serialport_init(i8* nocapture %0, i32 %1, i8 signext %2) {
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %4 to i8*
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* %0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = icmp eq i8 %2, 0
br i1 %12, label %13, label %97
13: ; preds = %11
%14 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %97
15: ; preds = %3
%16 = call i64 @tcgetattr(i32 %9, %struct.termios* %4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = icmp eq i8 %2, 0
br i1 %19, label %20, label %97
20: ; preds = %18
%21 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %97
22: ; preds = %15
switch i32 %1, label %35 [
i32 4800, label %23
i32 9600, label %25
i32 19200, label %27
i32 38400, label %29
i32 57600, label %31
i32 115200, label %33
]
23: ; preds = %22
%24 = load i32, i32* @B4800
br label %35
25: ; preds = %22
%26 = load i32, i32* @B9600
br label %35
27: ; preds = %22
%28 = load i32, i32* @B19200
br label %35
29: ; preds = %22
%30 = load i32, i32* @B38400
br label %35
31: ; preds = %22
%32 = load i32, i32* @B57600
br label %35
33: ; preds = %22
%34 = load i32, i32* @B115200
br label %35
35: ; preds = %22, %33, %31, %29, %27, %25, %23
%36 = phi i32 [ %1, %22 ], [ %34, %33 ], [ %32, %31 ], [ %30, %29 ], [ %28, %27 ], [ %26, %25 ], [ %24, %23 ]
%37 = call i32 @cfsetispeed(%struct.termios* %4, i32 %36)
%38 = call i32 @cfsetospeed(%struct.termios* %4, i32 %36)
%39 = load i32, i32* @PARENB
%40 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%41 = load i32, i32* %40
%42 = load i32, i32* @CSTOPB
%43 = or i32 %39, %42
%44 = load i32, i32* @CSIZE
%45 = or i32 %43, %44
%46 = xor i32 %45, -1
%47 = and i32 %41, %46
%48 = load i32, i32* @CS8
%49 = or i32 %48, %47
%50 = load i32, i32* @CRTSCTS
%51 = xor i32 %50, -1
%52 = and i32 %49, %51
%53 = load i32, i32* @CREAD
%54 = load i32, i32* @CLOCAL
%55 = or i32 %53, %52
%56 = or i32 %55, %54
store i32 %56, i32* %40
%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* %4, i64 0, i32 1
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @ICANON
%67 = load i32, i32* @ECHO
%68 = or i32 %67, %66
%69 = load i32, i32* @ECHOE
%70 = or i32 %68, %69
%71 = load i32, i32* @ISIG
%72 = or i32 %70, %71
%73 = xor i32 %72, -1
%74 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%75 = load i32, i32* %74
%76 = and i32 %75, %73
store i32 %76, i32* %74
%77 = load i32, i32* @OPOST
%78 = xor i32 %77, -1
%79 = getelementptr inbounds %struct.termios, %struct.termios* %4, 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* %4, i64 0, i32 3
%83 = load i64*, i64** %82
%84 = load i64, i64* @VMIN
%85 = getelementptr inbounds i64, i64* %83, i64 %84
store i64 0, i64* %85
%86 = load i64, i64* @VTIME
%87 = getelementptr inbounds i64, i64* %83, i64 %86
store i64 0, i64* %87
%88 = load i32, i32* @TCSANOW
%89 = call i64 @tcsetattr(i32 %9, i32 %88, %struct.termios* %4)
%90 = load i32, i32* @TCSAFLUSH
%91 = call i64 @tcsetattr(i32 %9, i32 %90, %struct.termios* %4)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %35
%94 = icmp eq i8 %2, 0
br i1 %94, label %95, label %97
95: ; preds = %93
%96 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %97
97: ; preds = %95, %93, %35, %18, %20, %11, %13
%98 = phi i32 [ -1, %13 ], [ -1, %11 ], [ -1, %20 ], [ -1, %18 ], [ -1, %95 ], [ -1, %93 ], [ %9, %35 ]
ret i32 %98
}