#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;
  int c_oflag;
  int c_lflag;
};

/* Variables and functions */
int BRKINT;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int INLCR;
int INPCK;
int ISIG;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
int OCRNL;
int ONLCR;
int OPOST;
int /*<<< orphan*/ O_RDWR;
int PARENB;
int PARMRK;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_open(char *port, int baud) {
  struct termios options;
  int fd;
  fd = open(port, O_RDWR);
  if (fd == -1) {
    return fd;
  }
  tcgetattr(fd, &options);
  cfsetispeed(&options, baud);
  cfsetospeed(&options, baud);
  options.c_cflag &= ~(PARENB | CSIZE | CSTOPB | CSIZE);
  options.c_cflag |= (CLOCAL | CREAD | CS8);
  options.c_iflag &= ~(ICRNL | INLCR | INPCK | IXON | IXOFF | IXANY | IGNBRK |
                       BRKINT | PARMRK | ISTRIP | IGNCR);
  options.c_oflag &= ~(ONLCR | OCRNL | OPOST);
  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  tcsetattr(fd, TCSANOW, &options);
  return fd;
}


x86 assembly (clang, -O0):
<serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1189 <serial_open+0x39>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12dc <serial_open+0x18c>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    0x2dab(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d99(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    0x2d8e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7d(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    0x2dbd(%rip),%rcx
or     (%rcx),%eax
mov    0x2d34(%rip),%rcx
or     (%rcx),%eax
mov    0x2d8b(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d21(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf8(%rip),%rcx
or     (%rcx),%eax
mov    0x2d3f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9e(%rip),%rcx
or     (%rcx),%eax
mov    0x2ced(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
mov    0x2d79(%rip),%rcx
or     (%rcx),%eax
mov    0x2d30(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    0x2c9d(%rip),%rcx
or     (%rcx),%eax
mov    0x2c7c(%rip),%rcx
or     (%rcx),%eax
mov    0x2cdb(%rip),%rcx
or     (%rcx),%eax
mov    0x2caa(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x2c(%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    %esi,%ebp
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12a2 <serial_open+0x152>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e05(%rip),%rcx
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2d63(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    0x2d4d(%rip),%rcx
mov    0x2db6(%rip),%rdx
or     (%rcx),%eax
or     (%rdx),%eax
mov    0x2da3(%rip),%rcx
or     (%rcx),%eax
mov    0x2dfa(%rip),%rdx
mov    0x2deb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rdx),%ecx
mov    0x2d60(%rip),%rdx
or     (%rdx),%ecx
mov    0x2db7(%rip),%rdx
or     (%rdx),%ecx
mov    0x2dc6(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d4d(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d24(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d6b(%rip),%rdx
or     (%rdx),%ecx
mov    0x2dca(%rip),%rdx
or     (%rdx),%ecx
mov    %eax,(%rsp)
mov    0x2d16(%rip),%rax
or     (%rax),%ecx
mov    0x2d85(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2ce6(%rip),%rax
mov    0x2da7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d5c(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d2d(%rip),%rax
mov    0x2cce(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cab(%rip),%rax
or     (%rax),%ecx
mov    0x2d0a(%rip),%rax
or     (%rax),%ecx
mov    0x2cd9(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@O_RDWR = global i32 0
@PARENB = global i32 0
@CSIZE = global i32 0
@CSTOPB = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@INPCK = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@IGNCR = global i32 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@TCSANOW = global i32 0
define i32 @serial_open(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %7
store i32 %14, i32* %3
br label %92
15: ; preds = %2
%16 = load i32, i32* %7
%17 = call i32 @tcgetattr(i32 %16, %struct.termios* %6)
%18 = load i32, i32* %5
%19 = call i32 @cfsetispeed(%struct.termios* %6, i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @cfsetospeed(%struct.termios* %6, i32 %20)
%22 = load i32, i32* @PARENB
%23 = load i32, i32* @CSIZE
%24 = or i32 %22, %23
%25 = load i32, i32* @CSTOPB
%26 = or i32 %24, %25
%27 = load i32, i32* @CSIZE
%28 = or i32 %26, %27
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @CLOCAL
%34 = load i32, i32* @CREAD
%35 = or i32 %33, %34
%36 = load i32, i32* @CS8
%37 = or i32 %35, %36
%38 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%39 = load i32, i32* %38
%40 = or i32 %39, %37
store i32 %40, i32* %38
%41 = load i32, i32* @ICRNL
%42 = load i32, i32* @INLCR
%43 = or i32 %41, %42
%44 = load i32, i32* @INPCK
%45 = or i32 %43, %44
%46 = load i32, i32* @IXON
%47 = or i32 %45, %46
%48 = load i32, i32* @IXOFF
%49 = or i32 %47, %48
%50 = load i32, i32* @IXANY
%51 = or i32 %49, %50
%52 = load i32, i32* @IGNBRK
%53 = or i32 %51, %52
%54 = load i32, i32* @BRKINT
%55 = or i32 %53, %54
%56 = load i32, i32* @PARMRK
%57 = or i32 %55, %56
%58 = load i32, i32* @ISTRIP
%59 = or i32 %57, %58
%60 = load i32, i32* @IGNCR
%61 = or i32 %59, %60
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @ONLCR
%67 = load i32, i32* @OCRNL
%68 = or i32 %66, %67
%69 = load i32, i32* @OPOST
%70 = or i32 %68, %69
%71 = xor i32 %70, -1
%72 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%73 = load i32, i32* %72
%74 = and i32 %73, %71
store i32 %74, i32* %72
%75 = load i32, i32* @ECHO
%76 = load i32, i32* @ECHONL
%77 = or i32 %75, %76
%78 = load i32, i32* @ICANON
%79 = or i32 %77, %78
%80 = load i32, i32* @ISIG
%81 = or i32 %79, %80
%82 = load i32, i32* @IEXTEN
%83 = or i32 %81, %82
%84 = xor i32 %83, -1
%85 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%86 = load i32, i32* %85
%87 = and i32 %86, %84
store i32 %87, i32* %85
%88 = load i32, i32* %7
%89 = load i32, i32* @TCSANOW
%90 = call i32 @tcsetattr(i32 %88, i32 %89, %struct.termios* %6)
%91 = load i32, i32* %7
store i32 %91, i32* %3
br label %92
92: ; preds = %15, %13
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@O_RDWR = global i32 0
@PARENB = global i32 0
@CSIZE = global i32 0
@CSTOPB = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@INPCK = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@IGNCR = global i32 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@TCSANOW = global i32 0
define i32 @serial_open(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %76, label %8
8: ; preds = %2
%9 = call i32 @tcgetattr(i32 %6, %struct.termios* %3)
%10 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%11 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%12 = load i32, i32* @PARENB
%13 = load i32, i32* @CSIZE
%14 = or i32 %13, %12
%15 = load i32, i32* @CSTOPB
%16 = or i32 %14, %15
%17 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
%21 = load i32, i32* @CLOCAL
%22 = load i32, i32* @CREAD
%23 = load i32, i32* @CS8
%24 = or i32 %21, %20
%25 = or i32 %24, %22
%26 = or i32 %25, %23
store i32 %26, i32* %18
%27 = load i32, i32* @ICRNL
%28 = load i32, i32* @INLCR
%29 = or i32 %28, %27
%30 = load i32, i32* @INPCK
%31 = or i32 %29, %30
%32 = load i32, i32* @IXON
%33 = or i32 %31, %32
%34 = load i32, i32* @IXOFF
%35 = or i32 %33, %34
%36 = load i32, i32* @IXANY
%37 = or i32 %35, %36
%38 = load i32, i32* @IGNBRK
%39 = or i32 %37, %38
%40 = load i32, i32* @BRKINT
%41 = or i32 %39, %40
%42 = load i32, i32* @PARMRK
%43 = or i32 %41, %42
%44 = load i32, i32* @ISTRIP
%45 = or i32 %43, %44
%46 = load i32, i32* @IGNCR
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @ONLCR
%53 = load i32, i32* @OCRNL
%54 = or i32 %53, %52
%55 = load i32, i32* @OPOST
%56 = or i32 %54, %55
%57 = xor i32 %56, -1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%59 = load i32, i32* %58
%60 = and i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @ECHO
%62 = load i32, i32* @ECHONL
%63 = or i32 %62, %61
%64 = load i32, i32* @ICANON
%65 = or i32 %63, %64
%66 = load i32, i32* @ISIG
%67 = or i32 %65, %66
%68 = load i32, i32* @IEXTEN
%69 = or i32 %67, %68
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @TCSANOW
%75 = call i32 @tcsetattr(i32 %6, i32 %74, %struct.termios* %3)
br label %76
76: ; preds = %2, %8
ret i32 %6
}