#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*/ 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, 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 'O':
    newtio.c_cflag |= PARENB;
    newtio.c_cflag |= PARODD;
    newtio.c_iflag |= (INPCK | ISTRIP);
    break;
  case 'E':
    newtio.c_iflag |= (INPCK | ISTRIP);
    newtio.c_cflag |= PARENB;
    newtio.c_cflag &= ~PARODD;
    break;
  case 'N':
    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;
  }
  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    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
je     11c8 <set_opt+0x48>
lea    0xe49(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ec <set_opt+0x36c>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%ecx
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
or     %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    0x2daf(%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     122a <set_opt+0xaa>
jmp    1219 <set_opt+0x99>
mov    -0x3c(%rbp),%eax
sub    $0x8,%eax
je     123e <set_opt+0xbe>
jmp    124d <set_opt+0xcd>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    124d <set_opt+0xcd>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x45,%eax
je     12bf <set_opt+0x13f>
jmp    1262 <set_opt+0xe2>
mov    -0x40(%rbp),%eax
sub    $0x4e,%eax
je     12fd <set_opt+0x17d>
jmp    1273 <set_opt+0xf3>
mov    -0x40(%rbp),%eax
sub    $0x4f,%eax
jne    130f <set_opt+0x18f>
jmp    1284 <set_opt+0x104>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
mov    0x2cce(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    130f <set_opt+0x18f>
mov    0x2cc2(%rip),%rax
mov    (%rax),%eax
mov    0x2cb1(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    130f <set_opt+0x18f>
mov    0x2ce4(%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     135e <set_opt+0x1de>
jmp    1325 <set_opt+0x1a5>
mov    -0x44(%rbp),%eax
sub    $0x12c0,%eax
je     1387 <set_opt+0x207>
jmp    1338 <set_opt+0x1b8>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     13b0 <set_opt+0x230>
jmp    134b <set_opt+0x1cb>
mov    -0x44(%rbp),%eax
sub    $0x1c200,%eax
je     13d9 <set_opt+0x259>
jmp    1402 <set_opt+0x282>
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1426 <set_opt+0x2a6>
mov    0x2c42(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1426 <set_opt+0x2a6>
mov    0x2c11(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1426 <set_opt+0x2a6>
mov    0x2b98(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2b86(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
jmp    1426 <set_opt+0x2a6>
mov    0x2bbf(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2bad(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1447 <set_opt+0x2c7>
mov    0x2b29(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1465 <set_opt+0x2e5>
cmpl   $0x2,-0x18(%rbp)
jne    1460 <set_opt+0x2e0>
mov    0x2b08(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1465 <set_opt+0x2e5>
mov    -0x20(%rbp),%rax
mov    0x2b00(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    0x2b2a(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%edi
mov    0x2afd(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2b34(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     14d9 <set_opt+0x359>
lea    0xb46(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ec <set_opt+0x36c>
lea    0xb3c(%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    %esi,%ebp
mov    %edi,%r15d
lea    0x10(%rsp),%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
jne    1389 <set_opt+0x209>
mov    %rsp,%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    0x2d90(%rip),%rax
mov    0x2df9(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,(%rsp)
cmp    $0x8,%ebx
je     11f1 <set_opt+0x71>
cmp    $0x7,%ebx
jne    11fd <set_opt+0x7d>
mov    0x2d69(%rip),%rcx
jmp    11f8 <set_opt+0x78>
mov    0x2dc0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
movsbl %r12b,%ecx
cmp    $0x45,%ecx
je     1249 <set_opt+0xc9>
cmp    $0x4e,%ecx
je     1299 <set_opt+0x119>
cmp    $0x4f,%ecx
jne    1278 <set_opt+0xf8>
mov    0x2dcd(%rip),%rcx
or     (%rcx),%eax
mov    0x2db4(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5b(%rip),%rcx
mov    0x2d4c(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,(%rsp)
or     %edx,0x4(%rsp)
cmp    $0x257f,%ebp
jle    1280 <set_opt+0x100>
jmp    12b1 <set_opt+0x131>
mov    0x2d38(%rip),%rcx
mov    0x2d29(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     %edx,0x4(%rsp)
mov    0x2d82(%rip),%rcx
or     (%rcx),%eax
mov    0x2d69(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
cmp    $0x257f,%ebp
jg     12b1 <set_opt+0x131>
cmp    $0x960,%ebp
je     12d3 <set_opt+0x153>
cmp    $0x12c0,%ebp
jne    12ca <set_opt+0x14a>
mov    0x2d39(%rip),%rbp
jmp    12da <set_opt+0x15a>
mov    0x2d48(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,(%rsp)
cmp    $0x257f,%ebp
jle    1280 <set_opt+0x100>
cmp    $0x2580,%ebp
je     12ca <set_opt+0x14a>
cmp    $0x1c200,%ebp
jne    12ca <set_opt+0x14a>
mov    0x2cb0(%rip),%rbp
jmp    12da <set_opt+0x15a>
mov    0x2cf7(%rip),%rbp
jmp    12da <set_opt+0x15a>
mov    0x2cb6(%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     130f <set_opt+0x18f>
cmp    $0x1,%r14d
jne    131b <set_opt+0x19b>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,(%rsp)
jmp    131b <set_opt+0x19b>
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2c49(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c77(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c4d(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1050 <tcflush@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r15d,%edi
call   1070 <tcsetattr@plt>
test   %rax,%rax
jne    1392 <set_opt+0x212>
lea    0xca7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc70(%rip),%rdi
jmp    1399 <set_opt+0x219>
lea    0xc75(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    137c <set_opt+0x1fc>

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"
@.str.2 = [11 x i8] c"set done!\0A\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 %148
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 79, label %46
i32 69, label %61
i32 78, 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 %148
146: ; preds = %128
%147 = 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 %148
148: ; preds = %146, %144, %17
%149 = load i32, i32* %6
ret i32 %149
}

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"
@str = [10 x i8] c"set done!\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 %14, label %12
12: ; preds = %5
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %97
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 79, label %34
i32 69, label %45
i32 78, label %57
]
34: ; preds = %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
%46 = load i32, i32* @INPCK
%47 = load i32, i32* @ISTRIP
%48 = or i32 %47, %46
%49 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 1
%50 = load i32, i32* %49
%51 = or i32 %48, %50
store i32 %51, i32* %49
%52 = load i32, i32* @PARENB
%53 = or i32 %32, %52
%54 = load i32, i32* @PARODD
%55 = xor i32 %54, -1
%56 = and i32 %53, %55
store i32 %56, i32* %19
br label %61
57: ; preds = %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 i32 %1, label %65 [
i32 2400, label %66
i32 4800, label %62
i32 9600, label %63
i32 115200, label %64
]
62: ; preds = %61
br label %66
63: ; preds = %61
br label %66
64: ; preds = %61
br label %66
65: ; preds = %61
br label %66
66: ; preds = %61, %65, %64, %63, %62
%67 = phi i32* [ @B9600, %65 ], [ @B115200, %64 ], [ @B9600, %63 ], [ @B4800, %62 ], [ @B2400, %61 ]
%68 = load i32, i32* %67
%69 = call i32 @cfsetispeed(%struct.termios* %6, i32 %68)
%70 = load i32, i32* %67
%71 = call i32 @cfsetospeed(%struct.termios* %6, i32 %70)
switch i32 %4, label %81 [
i32 1, label %72
i32 2, label %77
]
72: ; preds = %66
%73 = load i32, i32* @CSTOPB
%74 = xor i32 %73, -1
%75 = load i32, i32* %19
%76 = and i32 %75, %74
store i32 %76, i32* %19
br label %81
77: ; preds = %66
%78 = load i32, i32* @CSTOPB
%79 = load i32, i32* %19
%80 = or i32 %79, %78
store i32 %80, i32* %19
br label %81
81: ; preds = %66, %77, %72
%82 = getelementptr inbounds %struct.termios, %struct.termios* %6, i64 0, i32 2
%83 = load i64*, i64** %82
%84 = load i64, i64* @VTIME
%85 = getelementptr inbounds i64, i64* %83, i64 %84
store i64 0, i64* %85
%86 = load i64, i64* @VMIN
%87 = getelementptr inbounds i64, i64* %83, i64 %86
store i64 0, i64* %87
%88 = load i32, i32* @TCIFLUSH
%89 = call i32 @tcflush(i32 %0, i32 %88)
%90 = load i32, i32* @TCSANOW
%91 = call i64 @tcsetattr(i32 %0, i32 %90, %struct.termios* %6)
%92 = icmp eq i64 %91, 0
br i1 %92, label %95, label %93
93: ; preds = %81
%94 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %97
95: ; preds = %81
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %97
97: ; preds = %95, %93, %12
%98 = phi i32 [ -1, %12 ], [ -1, %93 ], [ 0, %95 ]
ret i32 %98
}