#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 /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int B110;
int B115200;
int B1200;
int B134;
int B150;
int B1800;
int B19200;
int B200;
int B230400;
int B2400;
int B300;
int B38400;
int B4800;
int B50;
int B57600;
int B600;
int B75;
int B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NDELAY;
int O_RDWR;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct termios *memset(struct termios *, int /*<<< orphan*/, int);
int open(char const *, int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
scalar_t__ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_open(const char *device, unsigned long baud) {
  int fd;
  struct termios tio;
  fd = open(device, O_RDWR | O_NDELAY);
  if (fd == -1) {
    fprintf(stderr, "serial_open: ");
    perror(device);
    return -1;
  }
  if (memset(&tio, 0, sizeof(struct termios)) != &tio) {
    perror("serial_open: memset");
    close(fd);
    return -2;
  }
  switch (baud) {
  case 50L:
    tio.c_cflag = B50;
    break;
  case 75L:
    tio.c_cflag = B75;
    break;
  case 110L:
    tio.c_cflag = B110;
    break;
  case 134L:
    tio.c_cflag = B134;
    break;
  case 150L:
    tio.c_cflag = B150;
    break;
  case 200L:
    tio.c_cflag = B200;
    break;
  case 300L:
    tio.c_cflag = B300;
    break;
  case 600L:
    tio.c_cflag = B600;
    break;
  case 1200L:
    tio.c_cflag = B1200;
    break;
  case 1800L:
    tio.c_cflag = B1800;
    break;
  case 2400L:
    tio.c_cflag = B2400;
    break;
  case 4800L:
    tio.c_cflag = B4800;
    break;
  case 9600L:
    tio.c_cflag = B9600;
    break;
  case 19200L:
    tio.c_cflag = B19200;
    break;
  case 38400L:
    tio.c_cflag = B38400;
    break;
  case 57600L:
    tio.c_cflag = B57600;
    break;
  case 115200L:
    tio.c_cflag = B115200;
    break;
  case 230400L:
    tio.c_cflag = B230400;
    break;
  default:
    fprintf(stderr, "serial_open: baudrate %lu not supported\n", baud);
    return -5;
  }
  tio.c_cflag |= CS8 | CLOCAL | CREAD;
  tio.c_iflag = IGNPAR;
  if (tcflush(fd, TCIOFLUSH) < 0) {
    perror("serial_open: tcflush");
    close(fd);
    return -3;
  }
  if (tcsetattr(fd, TCSANOW, &tio) < 0) {
    perror("serial_open: tcsetattr");
    close(fd);
    return -4;
  }
  return fd;
}


x86 assembly (clang, -O0):
<serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d4 <serial_open+0x64>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    158f <serial_open+0x41f>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x28(%rbp),%rcx
cmp    %rcx,%rax
je     1211 <serial_open+0xa1>
lea    0xe16(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    158f <serial_open+0x41f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
sub    $0x32,%rax
je     1389 <serial_open+0x219>
jmp    1228 <serial_open+0xb8>
mov    -0x30(%rbp),%rax
sub    $0x4b,%rax
je     139a <serial_open+0x22a>
jmp    123b <serial_open+0xcb>
mov    -0x30(%rbp),%rax
sub    $0x6e,%rax
je     13ab <serial_open+0x23b>
jmp    124e <serial_open+0xde>
mov    -0x30(%rbp),%rax
sub    $0x86,%rax
je     13bc <serial_open+0x24c>
jmp    1263 <serial_open+0xf3>
mov    -0x30(%rbp),%rax
sub    $0x96,%rax
je     13cd <serial_open+0x25d>
jmp    1278 <serial_open+0x108>
mov    -0x30(%rbp),%rax
sub    $0xc8,%rax
je     13de <serial_open+0x26e>
jmp    128d <serial_open+0x11d>
mov    -0x30(%rbp),%rax
sub    $0x12c,%rax
je     13ef <serial_open+0x27f>
jmp    12a2 <serial_open+0x132>
mov    -0x30(%rbp),%rax
sub    $0x258,%rax
je     1400 <serial_open+0x290>
jmp    12b7 <serial_open+0x147>
mov    -0x30(%rbp),%rax
sub    $0x4b0,%rax
je     1411 <serial_open+0x2a1>
jmp    12cc <serial_open+0x15c>
mov    -0x30(%rbp),%rax
sub    $0x708,%rax
je     1422 <serial_open+0x2b2>
jmp    12e1 <serial_open+0x171>
mov    -0x30(%rbp),%rax
sub    $0x960,%rax
je     1433 <serial_open+0x2c3>
jmp    12f6 <serial_open+0x186>
mov    -0x30(%rbp),%rax
sub    $0x12c0,%rax
je     1444 <serial_open+0x2d4>
jmp    130b <serial_open+0x19b>
mov    -0x30(%rbp),%rax
sub    $0x2580,%rax
je     1455 <serial_open+0x2e5>
jmp    1320 <serial_open+0x1b0>
mov    -0x30(%rbp),%rax
sub    $0x4b00,%rax
je     1466 <serial_open+0x2f6>
jmp    1335 <serial_open+0x1c5>
mov    -0x30(%rbp),%rax
sub    $0x9600,%rax
je     1477 <serial_open+0x307>
jmp    134a <serial_open+0x1da>
mov    -0x30(%rbp),%rax
sub    $0xe100,%rax
je     1488 <serial_open+0x318>
jmp    135f <serial_open+0x1ef>
mov    -0x30(%rbp),%rax
sub    $0x1c200,%rax
je     1499 <serial_open+0x329>
jmp    1374 <serial_open+0x204>
mov    -0x30(%rbp),%rax
sub    $0x38400,%rax
je     14aa <serial_open+0x33a>
jmp    14bb <serial_open+0x34b>
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2c2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2c26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2bf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2baa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2bb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2b83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2a8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2ae9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2a90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2a67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    14e2 <serial_open+0x372>
mov    0x2a9e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xb53(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    158f <serial_open+0x41f>
mov    0x2a9f(%rip),%rax
mov    (%rax),%eax
mov    0x2a1e(%rip),%rcx
or     (%rcx),%eax
mov    0x2a95(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2a1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2a27(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
cmp    $0x0,%rax
jge    154a <serial_open+0x3da>
lea    0xb1a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    158f <serial_open+0x41f>
mov    -0x1c(%rbp),%edi
mov    0x2a74(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1589 <serial_open+0x419>
lea    0xaf0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    158f <serial_open+0x41f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_open>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2e5b(%rip),%rax
mov    0x2dbc(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1355 <serial_open+0x1e5>
mov    %eax,%r14d
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmp    %rbp,%rax
jne    137f <serial_open+0x20f>
cmp    $0x707,%rbx
jg     1214 <serial_open+0xa4>
cmp    $0x95,%rbx
jle    1263 <serial_open+0xf3>
cmp    $0x12b,%rbx
jle    12c0 <serial_open+0x150>
cmp    $0x12c,%rbx
je     139e <serial_open+0x22e>
cmp    $0x258,%rbx
je     13a7 <serial_open+0x237>
cmp    $0x4b0,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2d29(%rip),%rax
jmp    13f6 <serial_open+0x286>
cmp    $0x4aff,%rbx
jle    128d <serial_open+0x11d>
cmp    $0xe0ff,%rbx
jle    12e6 <serial_open+0x176>
cmp    $0xe100,%rbx
je     13b0 <serial_open+0x240>
cmp    $0x1c200,%rbx
je     13b9 <serial_open+0x249>
cmp    $0x38400,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
jmp    13f8 <serial_open+0x288>
cmp    $0x6d,%rbx
jg     130c <serial_open+0x19c>
cmp    $0x32,%rbx
je     13c2 <serial_open+0x252>
cmp    $0x4b,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2d48(%rip),%rax
jmp    13f6 <serial_open+0x286>
cmp    $0x12bf,%rbx
jg     132f <serial_open+0x1bf>
cmp    $0x708,%rbx
je     13cb <serial_open+0x25b>
cmp    $0x960,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2c9d(%rip),%rax
jmp    13f6 <serial_open+0x286>
cmp    $0x96,%rbx
je     13d4 <serial_open+0x264>
cmp    $0xc8,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2c9f(%rip),%rax
jmp    13f6 <serial_open+0x286>
cmp    $0x4b00,%rbx
je     13dd <serial_open+0x26d>
cmp    $0x9600,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2c01(%rip),%rax
jmp    13f6 <serial_open+0x286>
cmp    $0x6e,%rbx
je     13e6 <serial_open+0x276>
cmp    $0x86,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2c8e(%rip),%rax
jmp    13f6 <serial_open+0x286>
cmp    $0x12c0,%rbx
je     13ef <serial_open+0x27f>
cmp    $0x2580,%rbx
jne    1463 <serial_open+0x2f3>
mov    0x2c58(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
lea    0xc9b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1457 <serial_open+0x2e7>
lea    0xc88(%rip),%rdi
call   1090 <perror@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    $0xfffffffe,%r14d
jmp    1457 <serial_open+0x2e7>
mov    0x2bfb(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2c12(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2bc1(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2b70(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2bcf(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2b96(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2b75(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2c0c(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2beb(%rip),%rax
jmp    13f6 <serial_open+0x286>
mov    0x2bba(%rip),%rax
mov    (%rax),%eax
mov    0x2b89(%rip),%rcx
mov    0x2b0a(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2b7f(%rip),%rcx
or     (%rcx),%edx
or     %eax,%edx
mov    %edx,0x8(%rsp)
mov    0x2b08(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2b13(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1030 <tcflush@plt>
test   %rax,%rax
js     1485 <serial_open+0x315>
mov    0x2b85(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   1070 <tcsetattr@plt>
test   %rax,%rax
js     14a1 <serial_open+0x331>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2af6(%rip),%rax
mov    (%rax),%edi
lea    0xbaf(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xfffffffb,%r14d
jmp    1457 <serial_open+0x2e7>
lea    0xbbf(%rip),%rdi
call   1090 <perror@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    $0xfffffffd,%r14d
jmp    1457 <serial_open+0x2e7>
lea    0xbb8(%rip),%rdi
call   1090 <perror@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    $0xfffffffc,%r14d
jmp    1457 <serial_open+0x2e7>

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"serial_open: \00"
@.str.1 = [20 x i8] c"serial_open: memset\00"
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B134 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = 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
@B230400 = global i32 0
@.str.2 = [41 x i8] c"serial_open: baudrate %lu not supported\0A\00"
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@TCIOFLUSH = global i32 0
@.str.3 = [21 x i8] c"serial_open: tcflush\00"
@TCSANOW = global i32 0
@.str.4 = [23 x i8] c"serial_open: tcsetattr\00"
define i32 @serial_open(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.termios
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_NDELAY
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %8, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %4
%19 = call i32 @perror(i8* %18)
store i32 -1, i32* %3
br label %117
20: ; preds = %2
%21 = call %struct.termios* @memset(%struct.termios* %7, i32 0, i32 8)
%22 = icmp ne %struct.termios* %21, %7
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
store i32 -2, i32* %3
br label %117
27: ; preds = %20
%28 = load i64, i64* %5
switch i64 %28, label %83 [
i64 50, label %29
i64 75, label %32
i64 110, label %35
i64 134, label %38
i64 150, label %41
i64 200, label %44
i64 300, label %47
i64 600, label %50
i64 1200, label %53
i64 1800, label %56
i64 2400, label %59
i64 4800, label %62
i64 9600, label %65
i64 19200, label %68
i64 38400, label %71
i64 57600, label %74
i64 115200, label %77
i64 230400, label %80
]
29: ; preds = %27
%30 = load i32, i32* @B50
%31 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %30, i32* %31
br label %87
32: ; preds = %27
%33 = load i32, i32* @B75
%34 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %33, i32* %34
br label %87
35: ; preds = %27
%36 = load i32, i32* @B110
%37 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %36, i32* %37
br label %87
38: ; preds = %27
%39 = load i32, i32* @B134
%40 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %39, i32* %40
br label %87
41: ; preds = %27
%42 = load i32, i32* @B150
%43 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %42, i32* %43
br label %87
44: ; preds = %27
%45 = load i32, i32* @B200
%46 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %45, i32* %46
br label %87
47: ; preds = %27
%48 = load i32, i32* @B300
%49 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %48, i32* %49
br label %87
50: ; preds = %27
%51 = load i32, i32* @B600
%52 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %51, i32* %52
br label %87
53: ; preds = %27
%54 = load i32, i32* @B1200
%55 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %54, i32* %55
br label %87
56: ; preds = %27
%57 = load i32, i32* @B1800
%58 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %57, i32* %58
br label %87
59: ; preds = %27
%60 = load i32, i32* @B2400
%61 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %60, i32* %61
br label %87
62: ; preds = %27
%63 = load i32, i32* @B4800
%64 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %63, i32* %64
br label %87
65: ; preds = %27
%66 = load i32, i32* @B9600
%67 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %66, i32* %67
br label %87
68: ; preds = %27
%69 = load i32, i32* @B19200
%70 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %69, i32* %70
br label %87
71: ; preds = %27
%72 = load i32, i32* @B38400
%73 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %72, i32* %73
br label %87
74: ; preds = %27
%75 = load i32, i32* @B57600
%76 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %75, i32* %76
br label %87
77: ; preds = %27
%78 = load i32, i32* @B115200
%79 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %78, i32* %79
br label %87
80: ; preds = %27
%81 = load i32, i32* @B230400
%82 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %81, i32* %82
br label %87
83: ; preds = %27
%84 = load i32, i32* @stderr
%85 = load i64, i64* %5
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i64 %85)
store i32 -5, i32* %3
br label %117
87: ; preds = %80, %77, %74, %71, %68, %65, %62, %59, %56, %53, %50, %47, %44, %41, %38, %35, %32, %29
%88 = load i32, i32* @CS8
%89 = load i32, i32* @CLOCAL
%90 = or i32 %88, %89
%91 = load i32, i32* @CREAD
%92 = or i32 %90, %91
%93 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%94 = load i32, i32* %93
%95 = or i32 %94, %92
store i32 %95, i32* %93
%96 = load i32, i32* @IGNPAR
%97 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
store i32 %96, i32* %97
%98 = load i32, i32* %6
%99 = load i32, i32* @TCIOFLUSH
%100 = call i64 @tcflush(i32 %98, i32 %99)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %106
102: ; preds = %87
%103 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%104 = load i32, i32* %6
%105 = call i32 @close(i32 %104)
store i32 -3, i32* %3
br label %117
106: ; preds = %87
%107 = load i32, i32* %6
%108 = load i32, i32* @TCSANOW
%109 = call i64 @tcsetattr(i32 %107, i32 %108, %struct.termios* %7)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %115
111: ; preds = %106
%112 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%113 = load i32, i32* %6
%114 = call i32 @close(i32 %113)
store i32 -4, i32* %3
br label %117
115: ; preds = %106
%116 = load i32, i32* %6
store i32 %116, i32* %3
br label %117
117: ; preds = %115, %111, %102, %83, %23, %15
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"serial_open: \00"
@.str.1 = [20 x i8] c"serial_open: memset\00"
@B50 = global i32 0
@B75 = global i32 0
@B110 = global i32 0
@B134 = global i32 0
@B150 = global i32 0
@B200 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = 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
@B230400 = global i32 0
@.str.2 = [41 x i8] c"serial_open: baudrate %lu not supported\0A\00"
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@TCIOFLUSH = global i32 0
@.str.3 = [21 x i8] c"serial_open: tcflush\00"
@TCSANOW = global i32 0
@.str.4 = [23 x i8] c"serial_open: tcsetattr\00"
define i32 @serial_open(i8* nocapture %0, i64 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @perror(i8* %0)
br label %85
14: ; preds = %2
%15 = call %struct.termios* @memset(%struct.termios* %3, i32 0, i32 8)
%16 = icmp eq %struct.termios* %15, %3
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @close(i32 %8)
br label %85
20: ; preds = %14
switch i64 %1, label %58 [
i64 50, label %21
i64 75, label %23
i64 110, label %25
i64 134, label %27
i64 150, label %29
i64 200, label %31
i64 300, label %33
i64 600, label %35
i64 1200, label %37
i64 1800, label %39
i64 2400, label %41
i64 4800, label %43
i64 9600, label %45
i64 19200, label %47
i64 38400, label %49
i64 57600, label %51
i64 115200, label %53
i64 230400, label %55
]
21: ; preds = %20
%22 = load i32, i32* @B50
br label %61
23: ; preds = %20
%24 = load i32, i32* @B75
br label %61
25: ; preds = %20
%26 = load i32, i32* @B110
br label %61
27: ; preds = %20
%28 = load i32, i32* @B134
br label %61
29: ; preds = %20
%30 = load i32, i32* @B150
br label %61
31: ; preds = %20
%32 = load i32, i32* @B200
br label %61
33: ; preds = %20
%34 = load i32, i32* @B300
br label %61
35: ; preds = %20
%36 = load i32, i32* @B600
br label %61
37: ; preds = %20
%38 = load i32, i32* @B1200
br label %61
39: ; preds = %20
%40 = load i32, i32* @B1800
br label %61
41: ; preds = %20
%42 = load i32, i32* @B2400
br label %61
43: ; preds = %20
%44 = load i32, i32* @B4800
br label %61
45: ; preds = %20
%46 = load i32, i32* @B9600
br label %61
47: ; preds = %20
%48 = load i32, i32* @B19200
br label %61
49: ; preds = %20
%50 = load i32, i32* @B38400
br label %61
51: ; preds = %20
%52 = load i32, i32* @B57600
br label %61
53: ; preds = %20
%54 = load i32, i32* @B115200
br label %61
55: ; preds = %20
%56 = load i32, i32* @B230400
%57 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
store i32 %56, i32* %57
br label %61
58: ; preds = %20
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i64 %1)
br label %85
61: ; preds = %55, %53, %51, %49, %47, %45, %43, %41, %39, %37, %35, %33, %31, %29, %27, %25, %23, %21
%62 = phi i32 [ %56, %55 ], [ %54, %53 ], [ %52, %51 ], [ %50, %49 ], [ %48, %47 ], [ %46, %45 ], [ %44, %43 ], [ %42, %41 ], [ %40, %39 ], [ %38, %37 ], [ %36, %35 ], [ %34, %33 ], [ %32, %31 ], [ %30, %29 ], [ %28, %27 ], [ %26, %25 ], [ %24, %23 ], [ %22, %21 ]
%63 = load i32, i32* @CS8
%64 = load i32, i32* @CLOCAL
%65 = or i32 %64, %63
%66 = load i32, i32* @CREAD
%67 = or i32 %65, %66
%68 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%69 = or i32 %67, %62
store i32 %69, i32* %68
%70 = load i32, i32* @IGNPAR
%71 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
store i32 %70, i32* %71
%72 = load i32, i32* @TCIOFLUSH
%73 = call i64 @tcflush(i32 %8, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %61
%76 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @close(i32 %8)
br label %85
78: ; preds = %61
%79 = load i32, i32* @TCSANOW
%80 = call i64 @tcsetattr(i32 %8, i32 %79, %struct.termios* %3)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%84 = call i32 @close(i32 %8)
br label %85
85: ; preds = %78, %82, %75, %58, %17, %10
%86 = phi i32 [ -1, %10 ], [ -2, %17 ], [ -5, %58 ], [ -3, %75 ], [ -4, %82 ], [ %8, %78 ]
ret i32 %86
}