#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;
int /*<<< orphan*/ TIOCMSET;
int TIOCM_RTS;
size_t VMIN;
size_t VTIME;
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 *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serialport_init(const char *serialport, int baud) {
  struct termios toptions;
  int fd, iflags;
  fd = open(serialport, O_RDWR | O_NONBLOCK);
  if (fd == -1) {
    perror("serialport_init: Unable to open port ");
    return -1;
  }
  iflags &= ~TIOCM_RTS;
  ioctl(fd, TIOCMSET, &iflags);
  if (tcgetattr(fd, &toptions) < 0) {
    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) {
    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    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11bf <serialport_init+0x4f>
lea    0xe52(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1458 <serialport_init+0x2e8>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x3c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1214 <serialport_init+0xa4>
lea    0xe23(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1458 <serialport_init+0x2e8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x48(%rbp)
sub    $0x12c0,%eax
je     128f <serialport_init+0x11f>
jmp    1230 <serialport_init+0xc0>
mov    -0x48(%rbp),%eax
sub    $0x2580,%eax
je     12a0 <serialport_init+0x130>
jmp    1243 <serialport_init+0xd3>
mov    -0x48(%rbp),%eax
sub    $0x4b00,%eax
je     12b1 <serialport_init+0x141>
jmp    1256 <serialport_init+0xe6>
mov    -0x48(%rbp),%eax
sub    $0x9600,%eax
je     12c2 <serialport_init+0x152>
jmp    1269 <serialport_init+0xf9>
mov    -0x48(%rbp),%eax
sub    $0xe100,%eax
je     12d3 <serialport_init+0x163>
jmp    127c <serialport_init+0x10c>
mov    -0x48(%rbp),%eax
sub    $0x1c200,%eax
je     12e4 <serialport_init+0x174>
jmp    12f0 <serialport_init+0x180>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    12f0 <serialport_init+0x180>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    12f0 <serialport_init+0x180>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    12f0 <serialport_init+0x180>
mov    0x2c2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    12f0 <serialport_init+0x180>
mov    0x2c6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    12f0 <serialport_init+0x180>
mov    0x2c45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    -0x44(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2be7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c1d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bbc(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c02(%rip),%rax
mov    (%rax),%eax
mov    0x2b91(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c32(%rip),%rax
mov    (%rax),%eax
mov    0x2c49(%rip),%rcx
or     (%rcx),%eax
mov    0x2ba8(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2b7e(%rip),%rax
mov    (%rax),%eax
mov    0x2be5(%rip),%rcx
or     (%rcx),%eax
mov    0x2bd4(%rip),%rcx
or     (%rcx),%eax
mov    0x2bc3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2b73(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2b2d(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%edi
mov    0x2b90(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x3c(%rbp),%edi
mov    0x2bb3(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1452 <serialport_init+0x2e2>
lea    0xc13(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1458 <serialport_init+0x2e8>
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   %r14
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ebp
mov    0x2e5f(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     135b <serialport_init+0x1eb>
mov    %eax,%ebx
movl   $0x0,0xc(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     1364 <serialport_init+0x1f4>
cmp    $0x95ff,%ebp
jg     11f7 <serialport_init+0x87>
cmp    $0x12c0,%ebp
je     1218 <serialport_init+0xa8>
cmp    $0x2580,%ebp
je     1221 <serialport_init+0xb1>
cmp    $0x4b00,%ebp
jne    123c <serialport_init+0xcc>
mov    0x2dfb(%rip),%rax
jmp    123a <serialport_init+0xca>
cmp    $0x9600,%ebp
je     122a <serialport_init+0xba>
cmp    $0xe100,%ebp
je     1233 <serialport_init+0xc3>
cmp    $0x1c200,%ebp
jne    123c <serialport_init+0xcc>
mov    0x2d22(%rip),%rax
jmp    123a <serialport_init+0xca>
mov    0x2d61(%rip),%rax
jmp    123a <serialport_init+0xca>
mov    0x2d50(%rip),%rax
jmp    123a <serialport_init+0xca>
mov    0x2ccf(%rip),%rax
jmp    123a <serialport_init+0xca>
mov    0x2d16(%rip),%rax
mov    (%rax),%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
mov    %r14,%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    0x10(%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,0x10(%rsp)
mov    0x2d07(%rip),%rax
mov    0x2d20(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c85(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x14(%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,0x18(%rsp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x28(%rsp)
mov    0x20(%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    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
js     136d <serialport_init+0x1fd>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xc9e(%rip),%rdi
jmp    1374 <serialport_init+0x204>
lea    0xcbb(%rip),%rdi
jmp    1374 <serialport_init+0x204>
lea    0xce0(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1350 <serialport_init+0x1e0>

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

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