#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_lflag;
  int c_iflag;
  int c_cflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int B9600;
int BRKINT;
int CS8;
int CSIZE;
int ECHO;
int ICANON;
int ICRNL;
int IEXTEN;
int INPCK;
int ISIG;
int ISTRIP;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int O_SYNC;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int carmen_serial_connect(int *dev_fd, char *dev_name) {
  int BAUDRATE = B9600;
  struct termios newtio;
  *dev_fd = open(dev_name, O_RDWR | O_SYNC | O_NOCTTY, 0);
  if (*dev_fd < 0) {
    fprintf(stderr, "Serial I/O Error:  Could not open port %s\n", dev_name);
    return -1;
  }
  tcgetattr(*dev_fd, &newtio);
  cfsetispeed(&newtio, BAUDRATE);
  cfsetospeed(&newtio, BAUDRATE);
  newtio.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
  newtio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON | IXOFF);
  newtio.c_cflag &= ~(CSIZE | PARENB | PARODD);
  newtio.c_cflag |= (CS8);
  newtio.c_oflag &= ~(OPOST);
  newtio.c_cc[VTIME] = 1;
  newtio.c_cc[VMIN] = 0;
  tcflush(*dev_fd, TCIFLUSH);
  tcsetattr(*dev_fd, TCSANOW, &newtio);
  return 0;
}


x86 assembly (clang, -O0):
<carmen_serial_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e38(%rip),%rax
or     (%rax),%esi
mov    0x2da7(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11ec <carmen_serial_connect+0x7c>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1321 <carmen_serial_connect+0x1b1>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x1c(%rbp),%esi
lea    -0x40(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    -0x1c(%rbp),%esi
lea    -0x40(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    0x2d05(%rip),%rcx
or     (%rcx),%eax
mov    0x2d3c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d63(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    0x2d90(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce7(%rip),%rcx
or     (%rcx),%eax
mov    0x2cd6(%rip),%rcx
or     (%rcx),%eax
mov    0x2d55(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
mov    0x2d29(%rip),%rcx
or     (%rcx),%eax
mov    0x2d08(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2c61(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    0x2c94(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2c5d(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2ca1(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1070 <tcsetattr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<carmen_serial_connect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbp
mov    %rdi,%r12
mov    0x2e07(%rip),%rax
mov    0x2e58(%rip),%rcx
mov    0x2e41(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    (%rax),%ebx
mov    0x2dac(%rip),%rax
or     (%rax),%esi
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,(%r12)
test   %eax,%eax
js     12d2 <carmen_serial_connect+0x162>
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <cfsetospeed@plt>
mov    0x2dc1(%rip),%rax
mov    0x2d3a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d6f(%rip),%rax
or     (%rax),%ecx
mov    0x2d96(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2d78(%rip),%rax
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d1e(%rip),%rax
or     (%rax),%ecx
mov    0x2d0d(%rip),%rax
or     (%rax),%ecx
mov    0x2d8c(%rip),%rax
or     (%rax),%ecx
mov    0x2d93(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d24(%rip),%rax
mov    0x2d65(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d42(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x8(%rsp),%ecx
mov    0x2d13(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2ca2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2cd9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    (%r12),%edi
mov    0x2ca4(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    (%r12),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
jmp    12f0 <carmen_serial_connect+0x180>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
lea    0xd1e(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@B9600 = global i32 0
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@O_NOCTTY = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Serial I/O Error: Could not open port %s\0A\00"
@ECHO = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ISIG = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CS8 = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @carmen_serial_connect(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.termios
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32, i32* @B9600
store i32 %8, i32* %6
%9 = load i8*, i8** %5
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_SYNC
%12 = or i32 %10, %11
%13 = load i32, i32* @O_NOCTTY
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %9, i32 %14, i32 0)
%16 = load i32*, i32** %4
store i32 %15, i32* %16
%17 = load i32*, i32** %4
%18 = load i32, i32* %17
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %92
24: ; preds = %2
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = call i32 @tcgetattr(i32 %26, %struct.termios* %7)
%28 = load i32, i32* %6
%29 = call i32 @cfsetispeed(%struct.termios* %7, i32 %28)
%30 = load i32, i32* %6
%31 = call i32 @cfsetospeed(%struct.termios* %7, i32 %30)
%32 = load i32, i32* @ECHO
%33 = load i32, i32* @ICANON
%34 = or i32 %32, %33
%35 = load i32, i32* @IEXTEN
%36 = or i32 %34, %35
%37 = load i32, i32* @ISIG
%38 = or i32 %36, %37
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @BRKINT
%44 = load i32, i32* @ICRNL
%45 = or i32 %43, %44
%46 = load i32, i32* @INPCK
%47 = or i32 %45, %46
%48 = load i32, i32* @ISTRIP
%49 = or i32 %47, %48
%50 = load i32, i32* @IXON
%51 = or i32 %49, %50
%52 = load i32, i32* @IXOFF
%53 = or i32 %51, %52
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @CSIZE
%59 = load i32, i32* @PARENB
%60 = or i32 %58, %59
%61 = load i32, i32* @PARODD
%62 = or i32 %60, %61
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @CS8
%68 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%69 = load i32, i32* %68
%70 = or i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @OPOST
%72 = xor i32 %71, -1
%73 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 4
%74 = load i32, i32* %73
%75 = and i32 %74, %72
store i32 %75, i32* %73
%76 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%77 = load i32*, i32** %76
%78 = load i64, i64* @VTIME
%79 = getelementptr inbounds i32, i32* %77, i64 %78
store i32 1, i32* %79
%80 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%81 = load i32*, i32** %80
%82 = load i64, i64* @VMIN
%83 = getelementptr inbounds i32, i32* %81, i64 %82
store i32 0, i32* %83
%84 = load i32*, i32** %4
%85 = load i32, i32* %84
%86 = load i32, i32* @TCIFLUSH
%87 = call i32 @tcflush(i32 %85, i32 %86)
%88 = load i32*, i32** %4
%89 = load i32, i32* %88
%90 = load i32, i32* @TCSANOW
%91 = call i32 @tcsetattr(i32 %89, i32 %90, %struct.termios* %7)
store i32 0, i32* %3
br label %92
92: ; preds = %24, %20
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@B9600 = global i32 0
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@O_NOCTTY = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Serial I/O Error: Could not open port %s\0A\00"
@ECHO = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ISIG = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CS8 = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @carmen_serial_connect(i32* nocapture %0, i8* %1) {
%3 = alloca %struct.termios
%4 = load i32, i32* @B9600
%5 = bitcast %struct.termios* %3 to i8*
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_SYNC
%8 = or i32 %7, %6
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %1, i32 %10, i32 0)
store i32 %11, i32* %0
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %74
16: ; preds = %2
%17 = call i32 @tcgetattr(i32 %11, %struct.termios* %3)
%18 = call i32 @cfsetispeed(%struct.termios* %3, i32 %4)
%19 = call i32 @cfsetospeed(%struct.termios* %3, i32 %4)
%20 = load i32, i32* @ECHO
%21 = load i32, i32* @ICANON
%22 = or i32 %21, %20
%23 = load i32, i32* @IEXTEN
%24 = or i32 %22, %23
%25 = load i32, i32* @ISIG
%26 = or i32 %24, %25
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @BRKINT
%32 = load i32, i32* @ICRNL
%33 = or i32 %32, %31
%34 = load i32, i32* @INPCK
%35 = or i32 %33, %34
%36 = load i32, i32* @ISTRIP
%37 = or i32 %35, %36
%38 = load i32, i32* @IXON
%39 = or i32 %37, %38
%40 = load i32, i32* @IXOFF
%41 = or i32 %39, %40
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @CSIZE
%47 = load i32, i32* @PARENB
%48 = or i32 %47, %46
%49 = load i32, i32* @PARODD
%50 = or i32 %48, %49
%51 = xor i32 %50, -1
%52 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%53 = load i32, i32* %52
%54 = and i32 %53, %51
%55 = load i32, i32* @CS8
%56 = or i32 %55, %54
store i32 %56, i32* %52
%57 = load i32, i32* @OPOST
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%63 = load i32*, i32** %62
%64 = load i64, i64* @VTIME
%65 = getelementptr inbounds i32, i32* %63, i64 %64
store i32 1, i32* %65
%66 = load i64, i64* @VMIN
%67 = getelementptr inbounds i32, i32* %63, i64 %66
store i32 0, i32* %67
%68 = load i32, i32* %0
%69 = load i32, i32* @TCIFLUSH
%70 = call i32 @tcflush(i32 %68, i32 %69)
%71 = load i32, i32* %0
%72 = load i32, i32* @TCSANOW
%73 = call i32 @tcsetattr(i32 %71, i32 %72, %struct.termios* %3)
br label %74
74: ; preds = %16, %13
%75 = phi i32 [ -1, %13 ], [ 0, %16 ]
ret i32 %75
}