#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct termios {
  int c_cflag;
  int c_lflag;
  int c_iflag;
  int /*<<< orphan*/ c_oflag;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ flag;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ B57600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int /*<<< orphan*/ IPPROTO_TCP;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ TCP_NODELAY;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(long);
int open(char const *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ set_nonblock(int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
long strtol(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int elCommInit(const char *portName, int baud) {
  struct termios options;
  int fd;
  int sockfd;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  int rv;
  if (*portName == '/') {
    printf("Opening serial port %s\n", portName);
    fd = open(portName, O_RDWR | O_NOCTTY | O_NDELAY);
    if (fd == -1) {
      perror("init(): Unable to open serial port - ");
    } else {
      fcntl(fd, F_SETFL, FNDELAY);
      tcgetattr(fd, &options);
      cfsetispeed(&options, B57600);
      cfsetospeed(&options, B57600);
      options.c_cflag |= (CLOCAL | CREAD);
      options.c_cflag &= ~PARENB;
      options.c_cflag &= ~CSTOPB;
      options.c_cflag &= ~CSIZE;
      options.c_cflag |= CS8;
      options.c_cflag &= ~CRTSCTS;
      options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
      options.c_iflag &= ~(IXON | IXOFF | IXANY);
      options.c_oflag &= ~OPOST;
      tcsetattr(fd, TCSANOW, &options);
    }
    return fd;
  } else {
    const char *tcpPortNumString = strchr(portName, ':');
    long int tcpPortNum;
    char ip[16];
    if (!tcpPortNumString) {
      tcpPortNum = 11411;
      strncpy(ip, portName, 16);
    } else {
      tcpPortNum = strtol(tcpPortNumString + 1, NULL, 10);
      strncpy(ip, portName, tcpPortNumString - portName);
    }
    printf("Connecting to TCP server at %s:%ld....\n", ip, tcpPortNum);
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) {
      error("ERROR opening socket");
      exit(-1);
    }
    int flag = 1;
    rv = setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
                    sizeof(flag));
    if (rv == -1) {
      printf("Couldn't setsockopt(TCP_NODELAY)\n");
      exit(-1);
    }
    server = gethostbyname(ip);
    if (server == NULL) {
      fprintf(stderr, "ERROR, no such host\n");
      exit(0);
    }
    bzero((char *)&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
          server->h_length);
    serv_addr.sin_port = htons(tcpPortNum);
    if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
      error("ERROR connecting");
    set_nonblock(sockfd);
    printf("connected to server\n");
    return sockfd;
  }
  return -1;
}


x86 assembly (clang, -O0):
<elCommInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    2412 <elCommInit+0x1b2>
mov    -0x10(%rbp),%rsi
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   2090 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
mov    0x2cb0(%rip),%rax
or     (%rax),%esi
mov    0x2c87(%rip),%rax
or     (%rax),%esi
call   2120 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    22d6 <elCommInit+0x76>
lea    0xd4c(%rip),%rdi
call   2140 <perror@plt>
jmp    2407 <elCommInit+0x1a7>
mov    -0x2c(%rbp),%edi
mov    0x2c68(%rip),%rax
mov    (%rax),%esi
mov    0x2c47(%rip),%rax
mov    (%rax),%edx
call   2050 <fcntl@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   2100 <tcgetattr@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   2130 <cfsetispeed@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   2060 <cfsetospeed@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%eax
mov    0x2c58(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c79(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2bbf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c15(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c0b(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2b94(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2b92(%rip),%rax
mov    (%rax),%eax
mov    0x2c09(%rip),%rcx
or     (%rcx),%eax
mov    0x2bf8(%rip),%rcx
or     (%rcx),%eax
mov    0x2bdf(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2bfd(%rip),%rax
mov    (%rax),%eax
mov    0x2c0c(%rip),%rcx
or     (%rcx),%eax
mov    0x2b8b(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2be1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2bb4(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   2110 <tcsetattr@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    25dc <elCommInit+0x37c>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   2080 <strchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    244e <elCommInit+0x1ee>
movq   $0x2c93,-0x60(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   2030 <strncpy@plt>
jmp    2482 <elCommInit+0x222>
mov    -0x58(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   20c0 <strtol@plt>
mov    %rax,-0x60(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   2030 <strncpy@plt>
lea    -0x70(%rbp),%rsi
mov    -0x60(%rbp),%rdx
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   2090 <printf@plt>
mov    0x2b31(%rip),%rax
mov    (%rax),%edi
mov    0x2a98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   2180 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    24d4 <elCommInit+0x274>
lea    0xba1(%rip),%rdi
call   20f0 <error@plt>
mov    $0xffffffff,%edi
call   2160 <exit@plt>
movl   $0x1,-0x74(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2ab3(%rip),%rax
mov    (%rax),%esi
mov    0x2af2(%rip),%rax
mov    (%rax),%edx
lea    -0x74(%rbp),%rcx
mov    $0x4,%r8d
call   2040 <setsockopt@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    2524 <elCommInit+0x2c4>
lea    0xb68(%rip),%rdi
mov    $0x0,%al
call   2090 <printf@plt>
mov    $0xffffffff,%edi
call   2160 <exit@plt>
lea    -0x70(%rbp),%rdi
call   20a0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    2558 <elCommInit+0x2f8>
mov    0x2a0d(%rip),%rax
mov    (%rax),%edi
lea    0xb51(%rip),%rsi
call   20b0 <fprintf@plt>
xor    %edi,%edi
call   2160 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   2150 <bzero@plt>
mov    0x2a63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
add    $0x4,%rsi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   20e0 <bcopy@plt>
mov    -0x60(%rbp),%rdi
call   2070 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   2170 <connect@plt>
cmp    $0x0,%rax
jge    25c0 <elCommInit+0x360>
lea    0xaf7(%rip),%rdi
call   20f0 <error@plt>
mov    -0x30(%rbp),%edi
call   20d0 <set_nonblock@plt>
lea    0xaf4(%rip),%rdi
mov    $0x0,%al
call   2090 <printf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elCommInit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
jne    23c7 <elCommInit+0x157>
lea    0xd71(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   20a0 <printf@plt>
mov    0x2d48(%rip),%rax
mov    0x2cb1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c86(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   2130 <open@plt>
cmp    $0xffffffff,%eax
je     250e <elCommInit+0x29e>
mov    %eax,%ebp
mov    0x2c7a(%rip),%rax
mov    (%rax),%esi
mov    0x2c59(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   2060 <fcntl@plt>
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   2110 <tcgetattr@plt>
mov    0x2c7c(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   2140 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   2070 <cfsetospeed@plt>
mov    0x2bf9(%rip),%rax
mov    0x2c72(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
mov    0x2be3(%rip),%rdx
or     (%rdx),%eax
mov    0x2c42(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2c3d(%rip),%rcx
or     (%rcx),%eax
mov    0x2bcc(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2bcf(%rip),%rax
mov    0x2c48(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    %ecx,(%rsp)
mov    0x2c32(%rip),%rax
or     (%rax),%edx
mov    0x2c19(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2c3a(%rip),%rax
mov    0x2c4b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2bc8(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2bfa(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   2120 <tcsetattr@plt>
jmp    24ff <elCommInit+0x28f>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   2090 <strchr@plt>
test   %rax,%rax
je     23f7 <elCommInit+0x187>
mov    %rax,%r15
mov    %rax,%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   20d0 <strtol@plt>
mov    %rax,%r14
sub    %ebx,%r15d
jmp    2403 <elCommInit+0x193>
mov    $0x2c93,%r14d
mov    $0x10,%r15d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   2030 <strncpy@plt>
lea    0xc23(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   20a0 <printf@plt>
mov    0x2ba1(%rip),%r12
mov    (%r12),%edi
mov    0x2b06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   2190 <socket@plt>
test   %eax,%eax
js     2521 <elCommInit+0x2b1>
mov    %eax,%ebp
movl   $0x1,0x1c(%rsp)
mov    0x2b3c(%rip),%rax
mov    (%rax),%esi
mov    0x2b7b(%rip),%rax
mov    (%rax),%edx
lea    0x1c(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   2050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     2537 <elCommInit+0x2c7>
mov    %rsp,%rdi
call   20b0 <gethostbyname@plt>
test   %rax,%rax
je     254d <elCommInit+0x2dd>
mov    %rax,%rbx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   2160 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x28(%rsp)
mov    0x8(%rbx),%rsi
lea    0x24(%rsp),%rdi
mov    (%rbx),%edx
call   20f0 <memmove@plt>
mov    %r14,%rdi
call   2080 <htons@plt>
mov    %eax,0x20(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   2180 <connect@plt>
test   %rax,%rax
jns    24ec <elCommInit+0x27c>
lea    0xba9(%rip),%rdi
call   2100 <error@plt>
mov    %ebp,%edi
call   20e0 <set_nonblock@plt>
lea    0xba7(%rip),%rdi
call   2040 <puts@plt>
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb03(%rip),%rdi
call   2150 <perror@plt>
mov    $0xffffffff,%ebp
jmp    24ff <elCommInit+0x28f>
lea    0xb3e(%rip),%rdi
call   2100 <error@plt>
mov    $0xffffffff,%edi
call   2170 <exit@plt>
lea    0xb77(%rip),%rdi
call   2040 <puts@plt>
mov    $0xffffffff,%edi
call   2170 <exit@plt>
mov    0x29fc(%rip),%rax
mov    (%rax),%edi
lea    0xb1e(%rip),%rsi
call   20c0 <fprintf@plt>
xor    %edi,%edi
call   2170 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Opening serial port %s\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [38 x i8] c"init(): Unable to open serial port - \00"
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@B57600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = 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"Connecting to TCP server at %s:%ld....\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [21 x i8] c"ERROR opening socket\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.4 = [34 x i8] c"Couldn't setsockopt(TCP_NODELAY)\0A\00"
@stderr = global i32 0
@.str.5 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.6 = [17 x i8] c"ERROR connecting\00"
@.str.7 = [21 x i8] c"connected to server\0A\00"
define i32 @elCommInit(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.hostent*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca [16 x i8]
%15 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %105
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %4
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_NOCTTY
%26 = or i32 %24, %25
%27 = load i32, i32* @O_NDELAY
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %23, i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %103
34: ; preds = %20
%35 = load i32, i32* %7
%36 = load i32, i32* @F_SETFL
%37 = load i32, i32* @FNDELAY
%38 = call i32 @fcntl(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* %7
%40 = call i32 @tcgetattr(i32 %39, %struct.termios* %6)
%41 = load i32, i32* @B57600
%42 = call i32 @cfsetispeed(%struct.termios* %6, i32 %41)
%43 = load i32, i32* @B57600
%44 = call i32 @cfsetospeed(%struct.termios* %6, i32 %43)
%45 = load i32, i32* @CLOCAL
%46 = load i32, i32* @CREAD
%47 = or i32 %45, %46
%48 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @PARENB
%52 = xor i32 %51, -1
%53 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%54 = load i32, i32* %53
%55 = and i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @CSTOPB
%57 = xor i32 %56, -1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%59 = load i32, i32* %58
%60 = and i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @CSIZE
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @CS8
%67 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%68 = load i32, i32* %67
%69 = or i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* @CRTSCTS
%71 = xor i32 %70, -1
%72 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%73 = load i32, i32* %72
%74 = and i32 %73, %71
store i32 %74, i32* %72
%75 = load i32, i32* @ICANON
%76 = load i32, i32* @ECHO
%77 = or i32 %75, %76
%78 = load i32, i32* @ECHOE
%79 = or i32 %77, %78
%80 = load i32, i32* @ISIG
%81 = or i32 %79, %80
%82 = xor i32 %81, -1
%83 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%84 = load i32, i32* %83
%85 = and i32 %84, %82
store i32 %85, i32* %83
%86 = load i32, i32* @IXON
%87 = load i32, i32* @IXOFF
%88 = or i32 %86, %87
%89 = load i32, i32* @IXANY
%90 = or i32 %88, %89
%91 = xor i32 %90, -1
%92 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%93 = load i32, i32* %92
%94 = and i32 %93, %91
store i32 %94, i32* %92
%95 = load i32, i32* @OPOST
%96 = xor i32 %95, -1
%97 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%98 = load i32, i32* %97
%99 = and i32 %98, %96
store i32 %99, i32* %97
%100 = load i32, i32* %7
%101 = load i32, i32* @TCSANOW
%102 = call i32 @tcsetattr(i32 %100, i32 %101, %struct.termios* %6)
br label %103
103: ; preds = %34, %32
%104 = load i32, i32* %7
store i32 %104, i32* %3
br label %189
105: ; preds = %2
%106 = load i8*, i8** %4
%107 = call i8* @strchr(i8* %106, i8 signext 58)
store i8* %107, i8** %12
%108 = load i8*, i8** %12
%109 = icmp ne i8* %108, null
br i1 %109, label %114, label %110
110: ; preds = %105
store i64 11411, i64* %13
%111 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%112 = load i8*, i8** %4
%113 = call i32 @strncpy(i8* %111, i8* %112, i32 16)
br label %127
114: ; preds = %105
%115 = load i8*, i8** %12
%116 = getelementptr inbounds i8, i8* %115, i64 1
%117 = call i64 @strtol(i8* %116, i32* null, i32 10)
store i64 %117, i64* %13
%118 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%119 = load i8*, i8** %4
%120 = load i8*, i8** %12
%121 = load i8*, i8** %4
%122 = ptrtoint i8* %120 to i64
%123 = ptrtoint i8* %121 to i64
%124 = sub i64 %122, %123
%125 = trunc i64 %124 to i32
%126 = call i32 @strncpy(i8* %118, i8* %119, i32 %125)
br label %127
127: ; preds = %114, %110
%128 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%129 = load i64, i64* %13
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %128, i64 %129)
%131 = load i32, i32* @AF_INET
%132 = load i32, i32* @SOCK_STREAM
%133 = call i32 @socket(i32 %131, i32 %132, i32 0)
store i32 %133, i32* %8
%134 = load i32, i32* %8
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %139
136: ; preds = %127
%137 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%138 = call i32 @exit(i32 -1)
unreachable
139: ; preds = %127
store i32 1, i32* %15
%140 = load i32, i32* %8
%141 = load i32, i32* @IPPROTO_TCP
%142 = load i32, i32* @TCP_NODELAY
%143 = bitcast i32* %15 to i8*
%144 = call i32 @setsockopt(i32 %140, i32 %141, i32 %142, i8* %143, i32 4)
store i32 %144, i32* %11
%145 = load i32, i32* %11
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %150
147: ; preds = %139
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%149 = call i32 @exit(i32 -1)
unreachable
150: ; preds = %139
%151 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%152 = call %struct.hostent* @gethostbyname(i8* %151)
store %struct.hostent* %152, %struct.hostent** %10
%153 = load %struct.hostent*, %struct.hostent** %10
%154 = icmp eq %struct.hostent* %153, null
br i1 %154, label %155, label %159
155: ; preds = %150
%156 = load i32, i32* @stderr
%157 = call i32 @fprintf(i32 %156, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%158 = call i32 @exit(i32 0)
unreachable
159: ; preds = %150
%160 = bitcast %struct.sockaddr_in* %9 to i8*
%161 = call i32 @bzero(i8* %160, i32 12)
%162 = load i32, i32* @AF_INET
%163 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %162, i32* %163
%164 = load %struct.hostent*, %struct.hostent** %10
%165 = getelementptr inbounds %struct.hostent, %struct.hostent* %164, i32 0, i32 1
%166 = load i64, i64* %165
%167 = inttoptr i64 %166 to i8*
%168 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%169 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %168, i32 0, i32 0
%170 = bitcast i32* %169 to i8*
%171 = load %struct.hostent*, %struct.hostent** %10
%172 = getelementptr inbounds %struct.hostent, %struct.hostent* %171, i32 0, i32 0
%173 = load i32, i32* %172
%174 = call i32 @bcopy(i8* %167, i8* %170, i32 %173)
%175 = load i64, i64* %13
%176 = call i32 @htons(i64 %175)
%177 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %176, i32* %177
%178 = load i32, i32* %8
%179 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%180 = call i64 @connect(i32 %178, %struct.sockaddr* %179, i32 12)
%181 = icmp slt i64 %180, 0
br i1 %181, label %182, label %184
182: ; preds = %159
%183 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %184
184: ; preds = %182, %159
%185 = load i32, i32* %8
%186 = call i32 @set_nonblock(i32 %185)
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%188 = load i32, i32* %8
store i32 %188, i32* %3
br label %189
189: ; preds = %184, %103
%190 = load i32, i32* %3
ret i32 %190
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Opening serial port %s\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [38 x i8] c"init(): Unable to open serial port - \00"
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@B57600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = 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"Connecting to TCP server at %s:%ld....\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [21 x i8] c"ERROR opening socket\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@stderr = global i32 0
@.str.5 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.6 = [17 x i8] c"ERROR connecting\00"
@str = [20 x i8] c"connected to server\00"
@str.8 = [33 x i8] c"Couldn't setsockopt(TCP_NODELAY)\00"
define i32 @elCommInit(i8* %0, i32 %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.sockaddr_in
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 47
br i1 %10, label %11, label %76
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NOCTTY
%15 = or i32 %14, %13
%16 = load i32, i32* @O_NDELAY
%17 = or i32 %15, %16
%18 = tail call i32 @open(i8* %0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %136
22: ; preds = %11
%23 = load i32, i32* @F_SETFL
%24 = load i32, i32* @FNDELAY
%25 = tail call i32 @fcntl(i32 %18, i32 %23, i32 %24)
%26 = call i32 @tcgetattr(i32 %18, %struct.termios* %3)
%27 = load i32, i32* @B57600
%28 = call i32 @cfsetispeed(%struct.termios* %3, i32 %27)
%29 = load i32, i32* @B57600
%30 = call i32 @cfsetospeed(%struct.termios* %3, i32 %29)
%31 = load i32, i32* @CLOCAL
%32 = load i32, i32* @CREAD
%33 = or i32 %32, %31
%34 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%35 = load i32, i32* %34
%36 = or i32 %33, %35
%37 = load i32, i32* @PARENB
%38 = load i32, i32* @CSTOPB
%39 = or i32 %37, %38
%40 = load i32, i32* @CSIZE
%41 = or i32 %39, %40
%42 = xor i32 %41, -1
%43 = and i32 %36, %42
%44 = load i32, i32* @CS8
%45 = or i32 %44, %43
%46 = load i32, i32* @CRTSCTS
%47 = xor i32 %46, -1
%48 = and i32 %45, %47
store i32 %48, i32* %34
%49 = load i32, i32* @ICANON
%50 = load i32, i32* @ECHO
%51 = or i32 %50, %49
%52 = load i32, i32* @ECHOE
%53 = or i32 %51, %52
%54 = load i32, i32* @ISIG
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @IXON
%61 = load i32, i32* @IXOFF
%62 = or i32 %61, %60
%63 = load i32, i32* @IXANY
%64 = or i32 %62, %63
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @OPOST
%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 %18, i32 %74, %struct.termios* %3)
br label %136
76: ; preds = %2
%77 = tail call i8* @strchr(i8* %0, i8 signext 58)
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%79 = icmp eq i8* %77, null
br i1 %79, label %87, label %80
80: ; preds = %76
%81 = getelementptr inbounds i8, i8* %77, i64 1
%82 = tail call i64 @strtol(i8* nocapture %81, i32* null, i32 10)
%83 = ptrtoint i8* %77 to i64
%84 = ptrtoint i8* %0 to i64
%85 = sub i64 %83, %84
%86 = trunc i64 %85 to i32
br label %87
87: ; preds = %76, %80
%88 = phi i32 [ %86, %80 ], [ 16, %76 ]
%89 = phi i64 [ %82, %80 ], [ 11411, %76 ]
%90 = call i32 @strncpy(i8* %78, i8* %0, i32 %88)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %78, i64 %89)
%92 = load i32, i32* @AF_INET
%93 = load i32, i32* @SOCK_STREAM
%94 = call i32 @socket(i32 %92, i32 %93, i32 0)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %87
%97 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%98 = call i32 @exit(i32 -1)
unreachable
99: ; preds = %87
%100 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%101 = load i32, i32* @IPPROTO_TCP
%102 = load i32, i32* @TCP_NODELAY
%103 = call i32 @setsockopt(i32 %94, i32 %101, i32 %102, i8* %100, i32 4)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %108
105: ; preds = %99
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
%107 = call i32 @exit(i32 -1)
unreachable
108: ; preds = %99
%109 = call %struct.hostent* @gethostbyname(i8* %78)
%110 = icmp eq %struct.hostent* %109, null
br i1 %110, label %111, label %115
111: ; preds = %108
%112 = load i32, i32* @stderr
%113 = call i32 @fprintf(i32 %112, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%114 = call i32 @exit(i32 0)
unreachable
115: ; preds = %108
%116 = call i32 @bzero(i8* %8, i32 12)
%117 = load i32, i32* @AF_INET
%118 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %117, i32* %118
%119 = getelementptr inbounds %struct.hostent, %struct.hostent* %109, i64 0, i32 1
%120 = load i64, i64* %119
%121 = inttoptr i64 %120 to i8*
%122 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%123 = bitcast i32* %122 to i8*
%124 = getelementptr inbounds %struct.hostent, %struct.hostent* %109, i64 0, i32 0
%125 = load i32, i32* %124
%126 = call i32 @htons(i64 %89)
%127 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %126, i32* %127
%128 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%129 = call i64 @connect(i32 %94, %struct.sockaddr* %128, i32 12)
%130 = icmp slt i64 %129, 0
br i1 %130, label %131, label %133
131: ; preds = %115
%132 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %133
133: ; preds = %131, %115
%134 = call i32 @set_nonblock(i32 %94)
%135 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %136
136: ; preds = %20, %22, %133
%137 = phi i32 [ %94, %133 ], [ %18, %22 ], [ -1, %20 ]
ret i32 %137
}