#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*/ B2400;
int /*<<< orphan*/ B4800;
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*/ TCIFLUSH;
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*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_opt(int fd, int nSpeed, int nBits, char nEvent, int nStop) {
  struct termios newtio, oldtio;
  if (tcgetattr(fd, &oldtio) != 0) {
    perror("SetupSerial 1");
    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 1:
    newtio.c_cflag |= PARENB;
    newtio.c_cflag |= PARODD;
    newtio.c_iflag |= (INPCK | ISTRIP);
    break;
  case 2:
    newtio.c_iflag |= (INPCK | ISTRIP);
    newtio.c_cflag |= PARENB;
    newtio.c_cflag &= ~PARODD;
    break;
  case 0:
    newtio.c_cflag &= ~PARENB;
    break;
  }
  switch (nSpeed) {
  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 115200:
    cfsetispeed(&newtio, B115200);
    cfsetospeed(&newtio, B115200);
    break;
  default:
    cfsetispeed(&newtio, B9600);
    cfsetospeed(&newtio, B9600);
    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, TCIFLUSH);
  if ((tcsetattr(fd, TCSANOW, &newtio)) != 0) {
    perror("com set error");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     11b8 <set_opt+0x48>
lea    0xe59(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <set_opt+0x35f>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%ecx
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%ecx
not    %ecx
mov    -0x28(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x7,%eax
je     121a <set_opt+0xaa>
jmp    1209 <set_opt+0x99>
mov    -0x3c(%rbp),%eax
sub    $0x8,%eax
je     122e <set_opt+0xbe>
jmp    123d <set_opt+0xcd>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    123d <set_opt+0xcd>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x40(%rbp)
test   %eax,%eax
je     12ec <set_opt+0x17c>
jmp    1251 <set_opt+0xe1>
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
je     1273 <set_opt+0x103>
jmp    1262 <set_opt+0xf2>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     12ae <set_opt+0x13e>
jmp    12fe <set_opt+0x18e>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    0x2cdf(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12fe <set_opt+0x18e>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    0x2cc2(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    12fe <set_opt+0x18e>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x960,%eax
je     134d <set_opt+0x1dd>
jmp    1314 <set_opt+0x1a4>
mov    -0x44(%rbp),%eax
sub    $0x12c0,%eax
je     1376 <set_opt+0x206>
jmp    1327 <set_opt+0x1b7>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     139f <set_opt+0x22f>
jmp    133a <set_opt+0x1ca>
mov    -0x44(%rbp),%eax
sub    $0x1c200,%eax
je     13c8 <set_opt+0x258>
jmp    13f1 <set_opt+0x281>
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2c2a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1415 <set_opt+0x2a5>
mov    0x2c53(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1415 <set_opt+0x2a5>
mov    0x2c22(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1415 <set_opt+0x2a5>
mov    0x2ba9(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1415 <set_opt+0x2a5>
mov    0x2bd0(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1436 <set_opt+0x2c6>
mov    0x2b3a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1454 <set_opt+0x2e4>
cmpl   $0x2,-0x18(%rbp)
jne    144f <set_opt+0x2df>
mov    0x2b19(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1454 <set_opt+0x2e4>
mov    -0x20(%rbp),%rax
mov    0x2b11(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    0x2b3b(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%edi
mov    0x2b0e(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2b45(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     14c8 <set_opt+0x358>
lea    0xb57(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <set_opt+0x35f>
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    %esi,%ebp
mov    %edi,%r15d
lea    0x10(%rsp),%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
jne    136b <set_opt+0x1fb>
mov    %rsp,%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    0x2da0(%rip),%rax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,(%rsp)
cmp    $0x8,%ebx
je     11e1 <set_opt+0x71>
cmp    $0x7,%ebx
jne    11ed <set_opt+0x7d>
mov    0x2d79(%rip),%rcx
jmp    11e8 <set_opt+0x78>
mov    0x2dd0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
movsbl %r12b,%ecx
test   %ecx,%ecx
je     1234 <set_opt+0xc4>
cmp    $0x2,%ecx
je     1265 <set_opt+0xf5>
cmp    $0x1,%ecx
jne    1244 <set_opt+0xd4>
mov    0x2de2(%rip),%rcx
or     (%rcx),%eax
mov    0x2dc9(%rip),%rcx
or     (%rcx),%eax
mov    0x2d70(%rip),%rcx
mov    0x2d61(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,(%rsp)
or     %edx,0x4(%rsp)
cmp    $0x257f,%ebp
jle    124c <set_opt+0xdc>
jmp    129c <set_opt+0x12c>
mov    0x2dad(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,(%rsp)
cmp    $0x257f,%ebp
jg     129c <set_opt+0x12c>
cmp    $0x960,%ebp
je     12be <set_opt+0x14e>
cmp    $0x12c0,%ebp
jne    12b5 <set_opt+0x145>
mov    0x2d6d(%rip),%rbp
jmp    12c5 <set_opt+0x155>
mov    0x2d1c(%rip),%rcx
mov    0x2d0d(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     %edx,0x4(%rsp)
mov    0x2d66(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4d(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
cmp    $0x257f,%ebp
jle    124c <set_opt+0xdc>
cmp    $0x2580,%ebp
je     12b5 <set_opt+0x145>
cmp    $0x1c200,%ebp
jne    12b5 <set_opt+0x145>
mov    0x2cc5(%rip),%rbp
jmp    12c5 <set_opt+0x155>
mov    0x2d0c(%rip),%rbp
jmp    12c5 <set_opt+0x155>
mov    0x2ccb(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
cmp    $0x2,%r14d
je     12fa <set_opt+0x18a>
cmp    $0x1,%r14d
jne    1306 <set_opt+0x196>
mov    0x2c6f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,(%rsp)
jmp    1306 <set_opt+0x196>
mov    0x2c5f(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2c5e(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c8c(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1040 <tcflush@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r15d,%edi
call   1060 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1374 <set_opt+0x204>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc8e(%rip),%rdi
jmp    137b <set_opt+0x20b>
lea    0xc93(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    135e <set_opt+0x1ee>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64* }
@.str = [14 x i8] c"SetupSerial 1\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
@B2400 = global i32 0
@B4800 = global i32 0
@B9600 = global i32 0
@B115200 = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"com set error\00"
define i32 @set_opt(i32 %0, i32 %1, i32 %2, i8 signext %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca %struct.termios
%13 = alloca %struct.termios
store i32 %0, i32* %7
store i32 %1, i32* %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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %147
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 1, label %46
i32 2, label %61
i32 0, label %77
]
46: ; preds = %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
%62 = load i32, i32* @INPCK
%63 = load i32, i32* @ISTRIP
%64 = or i32 %62, %63
%65 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 1
%66 = load i32, i32* %65
%67 = or i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @PARENB
%69 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%70 = load i32, i32* %69
%71 = or i32 %70, %68
store i32 %71, i32* %69
%72 = load i32, i32* @PARODD
%73 = xor i32 %72, -1
%74 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%75 = load i32, i32* %74
%76 = and i32 %75, %73
store i32 %76, i32* %74
br label %83
77: ; preds = %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 i32, i32* %8
switch i32 %84, label %105 [
i32 2400, label %85
i32 4800, label %90
i32 9600, label %95
i32 115200, label %100
]
85: ; preds = %83
%86 = load i32, i32* @B2400
%87 = call i32 @cfsetispeed(%struct.termios* %12, i32 %86)
%88 = load i32, i32* @B2400
%89 = call i32 @cfsetospeed(%struct.termios* %12, i32 %88)
br label %110
90: ; preds = %83
%91 = load i32, i32* @B4800
%92 = call i32 @cfsetispeed(%struct.termios* %12, i32 %91)
%93 = load i32, i32* @B4800
%94 = call i32 @cfsetospeed(%struct.termios* %12, i32 %93)
br label %110
95: ; preds = %83
%96 = load i32, i32* @B9600
%97 = call i32 @cfsetispeed(%struct.termios* %12, i32 %96)
%98 = load i32, i32* @B9600
%99 = call i32 @cfsetospeed(%struct.termios* %12, i32 %98)
br label %110
100: ; preds = %83
%101 = load i32, i32* @B115200
%102 = call i32 @cfsetispeed(%struct.termios* %12, i32 %101)
%103 = load i32, i32* @B115200
%104 = call i32 @cfsetospeed(%struct.termios* %12, i32 %103)
br label %110
105: ; preds = %83
%106 = load i32, i32* @B9600
%107 = call i32 @cfsetispeed(%struct.termios* %12, i32 %106)
%108 = load i32, i32* @B9600
%109 = call i32 @cfsetospeed(%struct.termios* %12, i32 %108)
br label %110
110: ; preds = %105, %100, %95, %90, %85
%111 = load i32, i32* %11
%112 = icmp eq i32 %111, 1
br i1 %112, label %113, label %119
113: ; preds = %110
%114 = load i32, i32* @CSTOPB
%115 = xor i32 %114, -1
%116 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%117 = load i32, i32* %116
%118 = and i32 %117, %115
store i32 %118, i32* %116
br label %128
119: ; preds = %110
%120 = load i32, i32* %11
%121 = icmp eq i32 %120, 2
br i1 %121, label %122, label %127
122: ; preds = %119
%123 = load i32, i32* @CSTOPB
%124 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%125 = load i32, i32* %124
%126 = or i32 %125, %123
store i32 %126, i32* %124
br label %127
127: ; preds = %122, %119
br label %128
128: ; preds = %127, %113
%129 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%130 = load i64*, i64** %129
%131 = load i64, i64* @VTIME
%132 = getelementptr inbounds i64, i64* %130, i64 %131
store i64 0, i64* %132
%133 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 2
%134 = load i64*, i64** %133
%135 = load i64, i64* @VMIN
%136 = getelementptr inbounds i64, i64* %134, i64 %135
store i64 0, i64* %136
%137 = load i32, i32* %7
%138 = load i32, i32* @TCIFLUSH
%139 = call i32 @tcflush(i32 %137, i32 %138)
%140 = load i32, i32* %7
%141 = load i32, i32* @TCSANOW
%142 = call i64 @tcsetattr(i32 %140, i32 %141, %struct.termios* %12)
%143 = icmp ne i64 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %128
%145 = 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 %147
146: ; preds = %128
store i32 0, i32* %6
br label %147
147: ; preds = %146, %144, %17
%148 = load i32, i32* %6
ret i32 %148
}

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