#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 */
typedef int /*<<< orphan*/ uint32_t;
struct termios {
  int c_iflag;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_lflag;
  int /*<<< orphan*/ c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B230400;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B57600;
int /*<<< orphan*/ B9600;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CREAD;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ECHOE;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ HUPCL;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_open(char *device, uint32_t baud) {
  int fd;
  struct termios options, options_new;
  switch (baud) {
  case 9600:
    baud = B9600;
    break;
  case 19200:
    baud = B19200;
    break;
  case 38400:
    baud = B38400;
    break;
  case 57600:
    baud = B57600;
    break;
  case 115200:
    baud = B115200;
    break;
  case 230400:
    baud = B230400;
    break;
  default:
    fprintf(stderr, "Unspported baud rate\n");
    return -1;
  }
  fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  fcntl(fd, F_SETFL, 0);
  tcgetattr(fd, &options);
  cfsetispeed(&options, baud);
  cfsetospeed(&options, baud);
  options.c_cflag |= CLOCAL;
  options.c_cflag |= CREAD;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CRTSCTS;
  options.c_cflag &= ~HUPCL;
  options.c_lflag &= ~ICANON;
  options.c_lflag &= ~ECHO;
  options.c_lflag &= ~ECHOE;
  options.c_lflag &= ~ISIG;
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_oflag &= ~OPOST;
  tcsetattr(fd, TCSANOW, &options);
  tcgetattr(fd, &options_new);
  if ((options.c_cflag != options_new.c_cflag) ||
      (options.c_lflag != options_new.c_lflag) ||
      (options.c_iflag != options_new.c_iflag) ||
      (options.c_oflag != options_new.c_oflag)) {
    fprintf(stderr, "tcsetattr: Some options did not stick?\n");
    exit(1);
  }
  return fd;
}


x86 assembly (clang, -O0):
<serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x2580,%eax
je     1214 <serial_open+0x84>
jmp    11b5 <serial_open+0x25>
mov    -0x3c(%rbp),%eax
sub    $0x4b00,%eax
je     1225 <serial_open+0x95>
jmp    11c8 <serial_open+0x38>
mov    -0x3c(%rbp),%eax
sub    $0x9600,%eax
je     1236 <serial_open+0xa6>
jmp    11db <serial_open+0x4b>
mov    -0x3c(%rbp),%eax
sub    $0xe100,%eax
je     1247 <serial_open+0xb7>
jmp    11ee <serial_open+0x5e>
mov    -0x3c(%rbp),%eax
sub    $0x1c200,%eax
je     1258 <serial_open+0xc8>
jmp    1201 <serial_open+0x71>
mov    -0x3c(%rbp),%eax
sub    $0x38400,%eax
je     1269 <serial_open+0xd9>
jmp    127a <serial_open+0xea>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    129b <serial_open+0x10b>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    129b <serial_open+0x10b>
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    129b <serial_open+0x10b>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    129b <serial_open+0x10b>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    129b <serial_open+0x10b>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    129b <serial_open+0x10b>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1494 <serial_open+0x304>
mov    -0x10(%rbp),%rdi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
mov    0x2cb1(%rip),%rax
or     (%rax),%esi
mov    0x2c90(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12e2 <serial_open+0x152>
lea    0xd43(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2be8(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c38(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2b9f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2b9d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2ba3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2b89(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2bf7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2bdd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2bc3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2bd9(%rip),%rax
mov    (%rax),%eax
mov    0x2be0(%rip),%rcx
or     (%rcx),%eax
mov    0x2b67(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2bbd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2b90(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    146f <serial_open+0x2df>
mov    -0x20(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    146f <serial_open+0x2df>
mov    -0x28(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    146f <serial_open+0x2df>
mov    -0x24(%rbp),%eax
cmp    -0x34(%rbp),%eax
je     148e <serial_open+0x2fe>
mov    0x2ae2(%rip),%rax
mov    (%rax),%edi
lea    0xb9c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_open>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0xe0ff,%esi
jg     11c5 <serial_open+0x35>
cmp    $0x2580,%esi
je     11ea <serial_open+0x5a>
cmp    $0x4b00,%esi
je     11f3 <serial_open+0x63>
cmp    $0x9600,%esi
jne    136d <serial_open+0x1dd>
mov    0x2d3d(%rip),%rax
jmp    120c <serial_open+0x7c>
cmp    $0xe100,%esi
je     11fc <serial_open+0x6c>
cmp    $0x1c200,%esi
je     1205 <serial_open+0x75>
cmp    $0x38400,%esi
jne    136d <serial_open+0x1dd>
mov    0x2d30(%rip),%rax
jmp    120c <serial_open+0x7c>
mov    0x2da7(%rip),%rax
jmp    120c <serial_open+0x7c>
mov    0x2df6(%rip),%rax
jmp    120c <serial_open+0x7c>
mov    0x2d75(%rip),%rax
jmp    120c <serial_open+0x7c>
mov    0x2d34(%rip),%rax
mov    0x2dcd(%rip),%rcx
mov    0x2d46(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    (%rax),%ebp
mov    0x2d21(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     13a8 <serial_open+0x218>
mov    %eax,%ebx
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1090 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <cfsetospeed@plt>
mov    0x2c96(%rip),%rax
mov    0xc(%rsp),%ecx
or     (%rax),%ecx
mov    0x2d11(%rip),%rax
or     (%rax),%ecx
mov    0x2cf8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2cf3(%rip),%rcx
or     (%rcx),%eax
mov    0x2d22(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2c69(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c70(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c7f(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2c6a(%rip),%rax
mov    (%rax),%eax
mov    0x2ce1(%rip),%rdx
or     (%rdx),%eax
mov    %ecx,0xc(%rsp)
mov    0x2ccc(%rip),%rcx
or     (%rcx),%eax
mov    0x2cbb(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    0x2cd4(%rip),%rax
mov    0x2cdd(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c62(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    0x2c95(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   1060 <tcgetattr@plt>
mov    0xc(%rsp),%eax
cmp    0x1c(%rsp),%eax
jne    1389 <serial_open+0x1f9>
mov    0x8(%rsp),%eax
cmp    0x18(%rsp),%eax
jne    1389 <serial_open+0x1f9>
mov    (%rsp),%eax
cmp    0x10(%rsp),%eax
jne    1389 <serial_open+0x1f9>
mov    0x4(%rsp),%eax
cmp    0x14(%rsp),%eax
jne    1389 <serial_open+0x1f9>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
lea    0xc83(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1362 <serial_open+0x1d2>
mov    0x2bc8(%rip),%rax
mov    (%rax),%edi
lea    0xc82(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xc67(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Unspported baud rate\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@F_SETFL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
@.str.2 = [40 x i8] c"tcsetattr: Some options did not stick?\0A\00"
define i32 @serial_open(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
%8 = alloca %struct.termios
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
switch i32 %9, label %22 [
i32 9600, label %10
i32 19200, label %12
i32 38400, label %14
i32 57600, label %16
i32 115200, label %18
i32 230400, label %20
]
10: ; preds = %2
%11 = load i32, i32* @B9600
store i32 %11, i32* %5
br label %25
12: ; preds = %2
%13 = load i32, i32* @B19200
store i32 %13, i32* %5
br label %25
14: ; preds = %2
%15 = load i32, i32* @B38400
store i32 %15, i32* %5
br label %25
16: ; preds = %2
%17 = load i32, i32* @B57600
store i32 %17, i32* %5
br label %25
18: ; preds = %2
%19 = load i32, i32* @B115200
store i32 %19, i32* %5
br label %25
20: ; preds = %2
%21 = load i32, i32* @B230400
store i32 %21, i32* %5
br label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %153
25: ; preds = %20, %18, %16, %14, %12, %10
%26 = load i8*, i8** %4
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_NOCTTY
%29 = or i32 %27, %28
%30 = load i32, i32* @O_NDELAY
%31 = or i32 %29, %30
%32 = call i32 @open(i8* %26, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
%39 = load i32, i32* %6
%40 = load i32, i32* @F_SETFL
%41 = call i32 @fcntl(i32 %39, i32 %40, i32 0)
%42 = load i32, i32* %6
%43 = call i32 @tcgetattr(i32 %42, %struct.termios* %7)
%44 = load i32, i32* %5
%45 = call i32 @cfsetispeed(%struct.termios* %7, i32 %44)
%46 = load i32, i32* %5
%47 = call i32 @cfsetospeed(%struct.termios* %7, i32 %46)
%48 = load i32, i32* @CLOCAL
%49 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%50 = load i32, i32* %49
%51 = or i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @CREAD
%53 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%54 = load i32, i32* %53
%55 = or i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @CSIZE
%57 = xor i32 %56, -1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%59 = load i32, i32* %58
%60 = and i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @CS8
%62 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%63 = load i32, i32* %62
%64 = or i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* @PARENB
%66 = xor i32 %65, -1
%67 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%68 = load i32, i32* %67
%69 = and i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* @CSTOPB
%71 = xor i32 %70, -1
%72 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%73 = load i32, i32* %72
%74 = and i32 %73, %71
store i32 %74, i32* %72
%75 = load i32, i32* @CRTSCTS
%76 = xor i32 %75, -1
%77 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%78 = load i32, i32* %77
%79 = and i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* @HUPCL
%81 = xor i32 %80, -1
%82 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%83 = load i32, i32* %82
%84 = and i32 %83, %81
store i32 %84, i32* %82
%85 = load i32, i32* @ICANON
%86 = xor i32 %85, -1
%87 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%88 = load i32, i32* %87
%89 = and i32 %88, %86
store i32 %89, i32* %87
%90 = load i32, i32* @ECHO
%91 = xor i32 %90, -1
%92 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%93 = load i32, i32* %92
%94 = and i32 %93, %91
store i32 %94, i32* %92
%95 = load i32, i32* @ECHOE
%96 = xor i32 %95, -1
%97 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%98 = load i32, i32* %97
%99 = and i32 %98, %96
store i32 %99, i32* %97
%100 = load i32, i32* @ISIG
%101 = xor i32 %100, -1
%102 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%103 = load i32, i32* %102
%104 = and i32 %103, %101
store i32 %104, i32* %102
%105 = load i32, i32* @IXON
%106 = load i32, i32* @IXOFF
%107 = or i32 %105, %106
%108 = load i32, i32* @IXANY
%109 = or i32 %107, %108
%110 = xor i32 %109, -1
%111 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%112 = load i32, i32* %111
%113 = and i32 %112, %110
store i32 %113, i32* %111
%114 = load i32, i32* @OPOST
%115 = xor i32 %114, -1
%116 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%117 = load i32, i32* %116
%118 = and i32 %117, %115
store i32 %118, i32* %116
%119 = load i32, i32* %6
%120 = load i32, i32* @TCSANOW
%121 = call i32 @tcsetattr(i32 %119, i32 %120, %struct.termios* %7)
%122 = load i32, i32* %6
%123 = call i32 @tcgetattr(i32 %122, %struct.termios* %8)
%124 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%125 = load i32, i32* %124
%126 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%127 = load i32, i32* %126
%128 = icmp ne i32 %125, %127
br i1 %128, label %147, label %129
129: ; preds = %38
%130 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%131 = load i32, i32* %130
%132 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%133 = load i32, i32* %132
%134 = icmp ne i32 %131, %133
br i1 %134, label %147, label %135
135: ; preds = %129
%136 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%137 = load i32, i32* %136
%138 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%139 = load i32, i32* %138
%140 = icmp ne i32 %137, %139
br i1 %140, label %147, label %141
141: ; preds = %135
%142 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%143 = load i32, i32* %142
%144 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%145 = load i32, i32* %144
%146 = icmp ne i32 %143, %145
br i1 %146, label %147, label %151
147: ; preds = %141, %135, %129, %38
%148 = load i32, i32* @stderr
%149 = call i32 @fprintf(i32 %148, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%150 = call i32 @exit(i32 1)
unreachable
151: ; preds = %141
%152 = load i32, i32* %6
store i32 %152, i32* %3
br label %153
153: ; preds = %151, %22
%154 = load i32, i32* %3
ret i32 %154
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@B230400 = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Unspported baud rate\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@F_SETFL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
@.str.2 = [40 x i8] c"tcsetattr: Some options did not stick?\0A\00"
define i32 @serial_open(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast %struct.termios* %4 to i8*
switch i32 %1, label %12 [
i32 9600, label %15
i32 19200, label %7
i32 38400, label %8
i32 57600, label %9
i32 115200, label %10
i32 230400, label %11
]
7: ; preds = %2
br label %15
8: ; preds = %2
br label %15
9: ; preds = %2
br label %15
10: ; preds = %2
br label %15
11: ; preds = %2
br label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %105
15: ; preds = %2, %11, %10, %9, %8, %7
%16 = phi i32* [ @B230400, %11 ], [ @B115200, %10 ], [ @B57600, %9 ], [ @B38400, %8 ], [ @B19200, %7 ], [ @B9600, %2 ]
%17 = load i32, i32* %16
%18 = load i32, i32* @O_RDWR
%19 = load i32, i32* @O_NOCTTY
%20 = or i32 %19, %18
%21 = load i32, i32* @O_NDELAY
%22 = or i32 %20, %21
%23 = tail call i32 @open(i8* %0, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %15
%29 = load i32, i32* @F_SETFL
%30 = tail call i32 @fcntl(i32 %23, i32 %29, i32 0)
%31 = call i32 @tcgetattr(i32 %23, %struct.termios* %3)
%32 = call i32 @cfsetispeed(%struct.termios* %3, i32 %17)
%33 = call i32 @cfsetospeed(%struct.termios* %3, i32 %17)
%34 = load i32, i32* @CLOCAL
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%36 = load i32, i32* %35
%37 = or i32 %36, %34
%38 = load i32, i32* @CREAD
%39 = or i32 %38, %37
%40 = load i32, i32* @CSIZE
%41 = xor i32 %40, -1
%42 = and i32 %39, %41
%43 = load i32, i32* @CS8
%44 = or i32 %43, %42
%45 = load i32, i32* @PARENB
%46 = load i32, i32* @CSTOPB
%47 = or i32 %45, %46
%48 = load i32, i32* @CRTSCTS
%49 = or i32 %47, %48
%50 = load i32, i32* @HUPCL
%51 = or i32 %49, %50
%52 = xor i32 %51, -1
%53 = and i32 %44, %52
store i32 %53, i32* %35
%54 = load i32, i32* @ICANON
%55 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%56 = load i32, i32* %55
%57 = load i32, i32* @ECHO
%58 = or i32 %54, %57
%59 = load i32, i32* @ECHOE
%60 = or i32 %58, %59
%61 = load i32, i32* @ISIG
%62 = or i32 %60, %61
%63 = xor i32 %62, -1
%64 = and i32 %56, %63
store i32 %64, i32* %55
%65 = load i32, i32* @IXON
%66 = load i32, i32* @IXOFF
%67 = or i32 %66, %65
%68 = load i32, i32* @IXANY
%69 = or i32 %67, %68
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @OPOST
%75 = xor i32 %74, -1
%76 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%77 = load i32, i32* %76
%78 = and i32 %77, %75
store i32 %78, i32* %76
%79 = load i32, i32* @TCSANOW
%80 = call i32 @tcsetattr(i32 %23, i32 %79, %struct.termios* %3)
%81 = call i32 @tcgetattr(i32 %23, %struct.termios* %4)
%82 = load i32, i32* %35
%83 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
%84 = load i32, i32* %83
%85 = icmp eq i32 %82, %84
br i1 %85, label %86, label %101
86: ; preds = %28
%87 = load i32, i32* %55
%88 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%89 = load i32, i32* %88
%90 = icmp eq i32 %87, %89
br i1 %90, label %91, label %101
91: ; preds = %86
%92 = load i32, i32* %71
%93 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%94 = load i32, i32* %93
%95 = icmp eq i32 %92, %94
br i1 %95, label %96, label %101
96: ; preds = %91
%97 = load i32, i32* %76
%98 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%99 = load i32, i32* %98
%100 = icmp eq i32 %97, %99
br i1 %100, label %105, label %101
101: ; preds = %96, %91, %86, %28
%102 = load i32, i32* @stderr
%103 = call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %96, %12
%106 = phi i32 [ -1, %12 ], [ %23, %96 ]
ret i32 %106
}