#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;
};
typedef int /*<<< orphan*/ newtio;

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS7;
int CS8;
int CSIZE;
int CSTOPB;
int INPCK;
int ISTRIP;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_opt(int fd, long nSpeed, int nBits, char nEvent, int nStop) {
  struct termios newtio, oldtio;
  if (tcgetattr(fd, &oldtio) != 0) {
    perror("Setup Serial");
    return -1;
  }
  bzero(&newtio, sizeof(newtio));
  newtio.c_cflag |= CLOCAL | CREAD;
  newtio.c_cflag &= ~CSIZE;
  switch (nBits) {
  case 7:
    newtio.c_cflag |= CS7;
    break;
  case 8:
    newtio.c_cflag |= CS8;
    break;
  }
  switch (nEvent) {
  case 'o':
  case 'O':
    newtio.c_cflag |= PARENB;
    newtio.c_cflag |= PARODD;
    newtio.c_iflag |= (INPCK | ISTRIP);
    break;
  case 'e':
  case 'E':
    newtio.c_cflag |= PARENB;
    newtio.c_cflag &= ~PARODD;
    newtio.c_iflag |= (INPCK | ISTRIP);
    break;
  case 'n':
  case 'N':
    newtio.c_cflag &= ~PARENB;
    break;
  }
  switch (nSpeed) {
  case 1200:
    cfsetispeed(&newtio, B1200);
    cfsetospeed(&newtio, B1200);
    break;
  case 2400:
    cfsetispeed(&newtio, B2400);
    cfsetospeed(&newtio, B2400);
    break;
  case 4800:
    cfsetispeed(&newtio, B4800);
    cfsetospeed(&newtio, B4800);
    break;
  case 9600:
    cfsetispeed(&newtio, B9600);
    cfsetospeed(&newtio, B9600);
    break;
  case 19200:
    cfsetispeed(&newtio, B19200);
    cfsetospeed(&newtio, B19200);
    break;
  case 38400:
    cfsetispeed(&newtio, B38400);
    cfsetospeed(&newtio, B38400);
    break;
  case 57600:
    cfsetispeed(&newtio, B57600);
    cfsetospeed(&newtio, B57600);
    break;
  case 115200:
    cfsetispeed(&newtio, B115200);
    cfsetospeed(&newtio, B115200);
    break;
  }
  if (nStop == 1)
    newtio.c_cflag &= ~CSTOPB;
  else if (nStop == 2)
    newtio.c_cflag |= CSTOPB;
  newtio.c_cc[VTIME] = 0;
  newtio.c_cc[VMIN] = 0;
  tcflush(fd, TCIOFLUSH);
  if ((tcsetattr(fd, TCSANOW, &newtio)) != 0) {
    perror("com set error");
    return -1;
  }
  printf("Set done!\n");
  return 0;
}


x86 assembly (clang, -O0):
<set_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cl,%al
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
je     11c9 <set_opt+0x49>
lea    0xe48(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f8 <set_opt+0x478>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%ecx
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x30(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x7,%eax
je     122b <set_opt+0xab>
jmp    121a <set_opt+0x9a>
mov    -0x44(%rbp),%eax
sub    $0x8,%eax
je     123f <set_opt+0xbf>
jmp    124e <set_opt+0xce>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    124e <set_opt+0xce>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
movsbl -0x15(%rbp),%eax
mov    %eax,-0x48(%rbp)
sub    $0x45,%eax
je     12f3 <set_opt+0x173>
jmp    1263 <set_opt+0xe3>
mov    -0x48(%rbp),%eax
sub    $0x4e,%eax
je     1331 <set_opt+0x1b1>
jmp    1274 <set_opt+0xf4>
mov    -0x48(%rbp),%eax
sub    $0x4f,%eax
je     12b8 <set_opt+0x138>
jmp    1285 <set_opt+0x105>
mov    -0x48(%rbp),%eax
sub    $0x65,%eax
je     12f3 <set_opt+0x173>
jmp    1296 <set_opt+0x116>
mov    -0x48(%rbp),%eax
sub    $0x6e,%eax
je     1331 <set_opt+0x1b1>
jmp    12a7 <set_opt+0x127>
mov    -0x48(%rbp),%eax
sub    $0x6f,%eax
jne    1343 <set_opt+0x1c3>
jmp    12b8 <set_opt+0x138>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ca3(%rip),%rax
mov    (%rax),%eax
mov    0x2c8a(%rip),%rcx
or     (%rcx),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1343 <set_opt+0x1c3>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
mov    0x2c4c(%rip),%rcx
or     (%rcx),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1343 <set_opt+0x1c3>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
sub    $0x4b0,%rax
je     13ef <set_opt+0x26f>
jmp    135c <set_opt+0x1dc>
mov    -0x50(%rbp),%rax
sub    $0x960,%rax
je     1418 <set_opt+0x298>
jmp    1371 <set_opt+0x1f1>
mov    -0x50(%rbp),%rax
sub    $0x12c0,%rax
je     1441 <set_opt+0x2c1>
jmp    1386 <set_opt+0x206>
mov    -0x50(%rbp),%rax
sub    $0x2580,%rax
je     146a <set_opt+0x2ea>
jmp    139b <set_opt+0x21b>
mov    -0x50(%rbp),%rax
sub    $0x4b00,%rax
je     1493 <set_opt+0x313>
jmp    13b0 <set_opt+0x230>
mov    -0x50(%rbp),%rax
sub    $0x9600,%rax
je     14bc <set_opt+0x33c>
jmp    13c5 <set_opt+0x245>
mov    -0x50(%rbp),%rax
sub    $0xe100,%rax
je     14e5 <set_opt+0x365>
jmp    13da <set_opt+0x25a>
mov    -0x50(%rbp),%rax
sub    $0x1c200,%rax
je     150e <set_opt+0x38e>
jmp    1532 <set_opt+0x3b2>
mov    0x2b72(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b60(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2b69(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b57(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2b80(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2b4f(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b3d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2b56(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b44(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2a6d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2a5b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2aac(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2a9a(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1532 <set_opt+0x3b2>
mov    0x2a4b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2a39(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    1553 <set_opt+0x3d3>
mov    0x2a05(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1571 <set_opt+0x3f1>
cmpl   $0x2,-0x1c(%rbp)
jne    156c <set_opt+0x3ec>
mov    0x29e4(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1571 <set_opt+0x3f1>
mov    -0x28(%rbp),%rax
mov    0x29dc(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2a16(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%edi
mov    0x29d1(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2a20(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     15e5 <set_opt+0x465>
lea    0xa39(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f8 <set_opt+0x478>
lea    0xa2f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_opt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8d,%r14d
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %edi,%r15d
lea    0x10(%rsp),%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
jne    1426 <set_opt+0x2a6>
mov    %rsp,%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    0x2d77(%rip),%rax
mov    0x2df0(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,(%rsp)
cmp    $0x8,%ebx
je     11f2 <set_opt+0x72>
cmp    $0x7,%ebx
jne    11fe <set_opt+0x7e>
mov    0x2d50(%rip),%rcx
jmp    11f9 <set_opt+0x79>
mov    0x2db7(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
movsbl %r12b,%ecx
add    $0xffffffbb,%ecx
cmp    $0x2a,%ecx
ja     12aa <set_opt+0x12a>
movabs $0x100000001,%rdx
bt     %rcx,%rdx
jb     127b <set_opt+0xfb>
movabs $0x20000000200,%rdx
bt     %rcx,%rdx
jb     12e2 <set_opt+0x162>
movabs $0x40000000400,%rdx
bt     %rcx,%rdx
jae    12aa <set_opt+0x12a>
mov    0x2d97(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d25(%rip),%rcx
mov    0x2d0e(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,(%rsp)
or     %edx,0x4(%rsp)
cmp    $0x4aff,%rbp
jle    12b3 <set_opt+0x133>
jmp    12fb <set_opt+0x17b>
mov    0x2d5e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d45(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2ce8(%rip),%rax
mov    0x2cd1(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    %ecx,(%rsp)
or     %edx,0x4(%rsp)
cmp    $0x4aff,%rbp
jg     12fb <set_opt+0x17b>
cmp    $0x12bf,%rbp
jg     131f <set_opt+0x19f>
cmp    $0x4b0,%rbp
je     1355 <set_opt+0x1d5>
cmp    $0x960,%rbp
jne    1390 <set_opt+0x210>
mov    0x2cab(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
mov    0x2cf7(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,(%rsp)
cmp    $0x4aff,%rbp
jle    12b3 <set_opt+0x133>
cmp    $0xe0ff,%rbp
jg     133a <set_opt+0x1ba>
cmp    $0x4b00,%rbp
je     135e <set_opt+0x1de>
cmp    $0x9600,%rbp
jne    1390 <set_opt+0x210>
mov    0x2c13(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
cmp    $0x12c0,%rbp
je     1367 <set_opt+0x1e7>
cmp    $0x2580,%rbp
jne    1390 <set_opt+0x210>
mov    0x2c88(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
cmp    $0xe100,%rbp
je     1370 <set_opt+0x1f0>
cmp    $0x1c200,%rbp
jne    1390 <set_opt+0x210>
mov    0x2c0d(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
mov    0x2c0c(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
mov    0x2c8b(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
mov    0x2c5a(%rip),%rbp
jmp    1377 <set_opt+0x1f7>
mov    0x2c21(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1040 <cfsetospeed@plt>
cmp    $0x2,%r14d
je     13ac <set_opt+0x22c>
cmp    $0x1,%r14d
jne    13b8 <set_opt+0x238>
mov    0x2ba5(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,(%rsp)
jmp    13b8 <set_opt+0x238>
mov    0x2b95(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2b94(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2bd2(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2b90(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1050 <tcflush@plt>
mov    0x2bdf(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r15d,%edi
call   1070 <tcsetattr@plt>
test   %rax,%rax
jne    142f <set_opt+0x2af>
lea    0xc09(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbd3(%rip),%rdi
jmp    1436 <set_opt+0x2b6>
lea    0xbd7(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    1419 <set_opt+0x299>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64* }
@.str = [13 x i8] c"Setup Serial\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"com set error\00"
@.str.2 = [11 x i8] c"Set done!\0A\00"
define i32 @set_opt(i32 %0, i64 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca %struct.termios
%13 = alloca %struct.termios
store i32 %0, i32* %7
store i64 %1, i64* %8
store i32 %2, i32* %9
store i8 %3, i8* %10
store i32 %4, i32* %11
%14 = load i32, i32* %7
%15 = call i64 @tcgetattr(i32 %14, %struct.termios* %13)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %163
19: ; preds = %5
%20 = call i32 @bzero(%struct.termios* %12, i32 16)
%21 = load i32, i32* @CLOCAL
%22 = load i32, i32* @CREAD
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @CSIZE
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* %9
switch i32 %32, label %43 [
i32 7, label %33
i32 8, label %38
]
33: ; preds = %19
%34 = load i32, i32* @CS7
%35 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%36 = load i32, i32* %35
%37 = or i32 %36, %34
store i32 %37, i32* %35
br label %43
38: ; preds = %19
%39 = load i32, i32* @CS8
%40 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%41 = load i32, i32* %40
%42 = or i32 %41, %39
store i32 %42, i32* %40
br label %43
43: ; preds = %19, %38, %33
%44 = load i8, i8* %10
%45 = sext i8 %44 to i32
switch i32 %45, label %83 [
i32 111, label %46
i32 79, label %46
i32 101, label %61
i32 69, label %61
i32 110, label %77
i32 78, label %77
]
46: ; preds = %43, %43
%47 = load i32, i32* @PARENB
%48 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @PARODD
%52 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%53 = load i32, i32* %52
%54 = or i32 %53, %51
store i32 %54, i32* %52
%55 = load i32, i32* @INPCK
%56 = load i32, i32* @ISTRIP
%57 = or i32 %55, %56
%58 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%59 = load i32, i32* %58
%60 = or i32 %59, %57
store i32 %60, i32* %58
br label %83
61: ; preds = %43, %43
%62 = load i32, i32* @PARENB
%63 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%64 = load i32, i32* %63
%65 = or i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @PARODD
%67 = xor i32 %66, -1
%68 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%69 = load i32, i32* %68
%70 = and i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @INPCK
%72 = load i32, i32* @ISTRIP
%73 = or i32 %71, %72
%74 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%75 = load i32, i32* %74
%76 = or i32 %75, %73
store i32 %76, i32* %74
br label %83
77: ; preds = %43, %43
%78 = load i32, i32* @PARENB
%79 = xor i32 %78, -1
%80 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%81 = load i32, i32* %80
%82 = and i32 %81, %79
store i32 %82, i32* %80
br label %83
83: ; preds = %43, %77, %61, %46
%84 = load i64, i64* %8
switch i64 %84, label %125 [
i64 1200, label %85
i64 2400, label %90
i64 4800, label %95
i64 9600, label %100
i64 19200, label %105
i64 38400, label %110
i64 57600, label %115
i64 115200, label %120
]
85: ; preds = %83
%86 = load i32, i32* @B1200
%87 = call i32 @cfsetispeed(%struct.termios* %12, i32 %86)
%88 = load i32, i32* @B1200
%89 = call i32 @cfsetospeed(%struct.termios* %12, i32 %88)
br label %125
90: ; preds = %83
%91 = load i32, i32* @B2400
%92 = call i32 @cfsetispeed(%struct.termios* %12, i32 %91)
%93 = load i32, i32* @B2400
%94 = call i32 @cfsetospeed(%struct.termios* %12, i32 %93)
br label %125
95: ; preds = %83
%96 = load i32, i32* @B4800
%97 = call i32 @cfsetispeed(%struct.termios* %12, i32 %96)
%98 = load i32, i32* @B4800
%99 = call i32 @cfsetospeed(%struct.termios* %12, i32 %98)
br label %125
100: ; preds = %83
%101 = load i32, i32* @B9600
%102 = call i32 @cfsetispeed(%struct.termios* %12, i32 %101)
%103 = load i32, i32* @B9600
%104 = call i32 @cfsetospeed(%struct.termios* %12, i32 %103)
br label %125
105: ; preds = %83
%106 = load i32, i32* @B19200
%107 = call i32 @cfsetispeed(%struct.termios* %12, i32 %106)
%108 = load i32, i32* @B19200
%109 = call i32 @cfsetospeed(%struct.termios* %12, i32 %108)
br label %125
110: ; preds = %83
%111 = load i32, i32* @B38400
%112 = call i32 @cfsetispeed(%struct.termios* %12, i32 %111)
%113 = load i32, i32* @B38400
%114 = call i32 @cfsetospeed(%struct.termios* %12, i32 %113)
br label %125
115: ; preds = %83
%116 = load i32, i32* @B57600
%117 = call i32 @cfsetispeed(%struct.termios* %12, i32 %116)
%118 = load i32, i32* @B57600
%119 = call i32 @cfsetospeed(%struct.termios* %12, i32 %118)
br label %125
120: ; preds = %83
%121 = load i32, i32* @B115200
%122 = call i32 @cfsetispeed(%struct.termios* %12, i32 %121)
%123 = load i32, i32* @B115200
%124 = call i32 @cfsetospeed(%struct.termios* %12, i32 %123)
br label %125
125: ; preds = %83, %120, %115, %110, %105, %100, %95, %90, %85
%126 = load i32, i32* %11
%127 = icmp eq i32 %126, 1
br i1 %127, label %128, label %134
128: ; preds = %125
%129 = load i32, i32* @CSTOPB
%130 = xor i32 %129, -1
%131 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%132 = load i32, i32* %131
%133 = and i32 %132, %130
store i32 %133, i32* %131
br label %143
134: ; preds = %125
%135 = load i32, i32* %11
%136 = icmp eq i32 %135, 2
br i1 %136, label %137, label %142
137: ; preds = %134
%138 = load i32, i32* @CSTOPB
%139 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%140 = load i32, i32* %139
%141 = or i32 %140, %138
store i32 %141, i32* %139
br label %142
142: ; preds = %137, %134
br label %143
143: ; preds = %142, %128
%144 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%145 = load i64*, i64** %144
%146 = load i64, i64* @VTIME
%147 = getelementptr inbounds i64, i64* %145, i64 %146
store i64 0, i64* %147
%148 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%149 = load i64*, i64** %148
%150 = load i64, i64* @VMIN
%151 = getelementptr inbounds i64, i64* %149, i64 %150
store i64 0, i64* %151
%152 = load i32, i32* %7
%153 = load i32, i32* @TCIOFLUSH
%154 = call i32 @tcflush(i32 %152, i32 %153)
%155 = load i32, i32* %7
%156 = load i32, i32* @TCSANOW
%157 = call i64 @tcsetattr(i32 %155, i32 %156, %struct.termios* %12)
%158 = icmp ne i64 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %143
%160 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %163
161: ; preds = %143
%162 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %163
163: ; preds = %161, %159, %17
%164 = load i32, i32* %6
ret i32 %164
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i64* }
@.str = [13 x i8] c"Setup Serial\00"
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@B1200 = global i32 0
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"com set error\00"
@str = [10 x i8] c"Set done!\00"
define i32 @set_opt(i32 %0, i64 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = bitcast %struct.termios* %6 to i8*
%9 = bitcast %struct.termios* %7 to i8*
%10 = call i64 @tcgetattr(i32 %0, %struct.termios* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %101
14: ; preds = %5
%15 = call i32 @bzero(%struct.termios* %6, i32 16)
%16 = load i32, i32* @CLOCAL
%17 = load i32, i32* @CREAD
%18 = or i32 %17, %16
%19 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 0
%20 = load i32, i32* %19
%21 = or i32 %18, %20
%22 = load i32, i32* @CSIZE
%23 = xor i32 %22, -1
%24 = and i32 %21, %23
store i32 %24, i32* %19
switch i32 %2, label %31 [
i32 7, label %25
i32 8, label %28
]
25: ; preds = %14
%26 = load i32, i32* @CS7
%27 = or i32 %26, %24
store i32 %27, i32* %19
br label %31
28: ; preds = %14
%29 = load i32, i32* @CS8
%30 = or i32 %29, %24
store i32 %30, i32* %19
br label %31
31: ; preds = %14, %28, %25
%32 = phi i32 [ %24, %14 ], [ %30, %28 ], [ %27, %25 ]
%33 = sext i8 %3 to i32
switch i32 %33, label %61 [
i32 111, label %34
i32 79, label %34
i32 101, label %45
i32 69, label %45
i32 110, label %57
i32 78, label %57
]
34: ; preds = %31, %31
%35 = load i32, i32* @PARENB
%36 = or i32 %32, %35
%37 = load i32, i32* @PARODD
%38 = or i32 %37, %36
store i32 %38, i32* %19
%39 = load i32, i32* @INPCK
%40 = load i32, i32* @ISTRIP
%41 = or i32 %40, %39
%42 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 1
%43 = load i32, i32* %42
%44 = or i32 %41, %43
store i32 %44, i32* %42
br label %61
45: ; preds = %31, %31
%46 = load i32, i32* @PARENB
%47 = or i32 %32, %46
%48 = load i32, i32* @PARODD
%49 = xor i32 %48, -1
%50 = and i32 %47, %49
store i32 %50, i32* %19
%51 = load i32, i32* @INPCK
%52 = load i32, i32* @ISTRIP
%53 = or i32 %52, %51
%54 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 1
%55 = load i32, i32* %54
%56 = or i32 %53, %55
store i32 %56, i32* %54
br label %61
57: ; preds = %31, %31
%58 = load i32, i32* @PARENB
%59 = xor i32 %58, -1
%60 = and i32 %32, %59
store i32 %60, i32* %19
br label %61
61: ; preds = %31, %57, %45, %34
switch i64 %1, label %75 [
i64 1200, label %69
i64 2400, label %62
i64 4800, label %63
i64 9600, label %64
i64 19200, label %65
i64 38400, label %66
i64 57600, label %67
i64 115200, label %68
]
62: ; preds = %61
br label %69
63: ; preds = %61
br label %69
64: ; preds = %61
br label %69
65: ; preds = %61
br label %69
66: ; preds = %61
br label %69
67: ; preds = %61
br label %69
68: ; preds = %61
br label %69
69: ; preds = %61, %62, %63, %64, %65, %66, %67, %68
%70 = phi i32* [ @B115200, %68 ], [ @B57600, %67 ], [ @B38400, %66 ], [ @B19200, %65 ], [ @B9600, %64 ], [ @B4800, %63 ], [ @B2400, %62 ], [ @B1200, %61 ]
%71 = load i32, i32* %70
%72 = call i32 @cfsetispeed(%struct.termios* %6, i32 %71)
%73 = load i32, i32* %70
%74 = call i32 @cfsetospeed(%struct.termios* %6, i32 %73)
br label %75
75: ; preds = %69, %61
switch i32 %4, label %85 [
i32 1, label %76
i32 2, label %81
]
76: ; preds = %75
%77 = load i32, i32* @CSTOPB
%78 = xor i32 %77, -1
%79 = load i32, i32* %19
%80 = and i32 %79, %78
store i32 %80, i32* %19
br label %85
81: ; preds = %75
%82 = load i32, i32* @CSTOPB
%83 = load i32, i32* %19
%84 = or i32 %83, %82
store i32 %84, i32* %19
br label %85
85: ; preds = %75, %81, %76
%86 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 2
%87 = load i64*, i64** %86
%88 = load i64, i64* @VTIME
%89 = getelementptr inbounds i64, i64* %87, i64 %88
store i64 0, i64* %89
%90 = load i64, i64* @VMIN
%91 = getelementptr inbounds i64, i64* %87, i64 %90
store i64 0, i64* %91
%92 = load i32, i32* @TCIOFLUSH
%93 = call i32 @tcflush(i32 %0, i32 %92)
%94 = load i32, i32* @TCSANOW
%95 = call i64 @tcsetattr(i32 %0, i32 %94, %struct.termios* %6)
%96 = icmp eq i64 %95, 0
br i1 %96, label %99, label %97
97: ; preds = %85
%98 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %101
99: ; preds = %85
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %101
101: ; preds = %99, %97, %12
%102 = phi i32 [ -1, %12 ], [ -1, %97 ], [ 0, %99 ]
ret i32 %102
}