#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 *, 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 *strtok(char *, char *);
long strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int elCommInit(char *portName, int baud) {
  struct termios options;
  int fd;
  char *ip;
  char *tcpPortNumString;
  long int tcpPortNum;
  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 {
    ip = strtok(portName, ":");
    tcpPortNumString = strtok(NULL, ":");
    tcpPortNum = 0;
    if (tcpPortNumString != NULL) {
      tcpPortNum = strtol(tcpPortNumString, NULL, 10);
    }
    if (tcpPortNum == 0) {
      tcpPortNum = 11411;
    }
    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    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    13ff <elCommInit+0x1af>
mov    -0x10(%rbp),%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
mov    0x2cc3(%rip),%rax
or     (%rax),%esi
mov    0x2c9a(%rip),%rax
or     (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12c3 <elCommInit+0x73>
lea    0xd5f(%rip),%rdi
call   1120 <perror@plt>
jmp    13f4 <elCommInit+0x1a4>
mov    -0x2c(%rbp),%edi
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
mov    0x2c5a(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10e0 <tcgetattr@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1110 <cfsetispeed@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1050 <cfsetospeed@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%eax
mov    0x2c6b(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2bd2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c1e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ba7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ba5(%rip),%rax
mov    (%rax),%eax
mov    0x2c1c(%rip),%rcx
or     (%rcx),%eax
mov    0x2c0b(%rip),%rcx
or     (%rcx),%eax
mov    0x2bf2(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2c10(%rip),%rax
mov    (%rax),%eax
mov    0x2c1f(%rip),%rcx
or     (%rcx),%eax
mov    0x2b9e(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2bf4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2bc7(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   10f0 <tcsetattr@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15bd <elCommInit+0x36d>
mov    -0x10(%rbp),%rdi
lea    0xc34(%rip),%rsi
call   1130 <strtok@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc20(%rip),%rsi
call   1130 <strtok@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1450 <elCommInit+0x200>
mov    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtol@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1463 <elCommInit+0x213>
movq   $0x2c93,-0x48(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xbce(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
mov    0x2ab7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    14b5 <elCommInit+0x265>
lea    0xbc2(%rip),%rdi
call   10d0 <error@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
movl   $0x1,-0x68(%rbp)
mov    -0x4c(%rbp),%edi
mov    0x2ad2(%rip),%rax
mov    (%rax),%esi
mov    0x2b11(%rip),%rax
mov    (%rax),%edx
lea    -0x68(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1505 <elCommInit+0x2b5>
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1539 <elCommInit+0x2e9>
mov    0x2a2c(%rip),%rax
mov    (%rax),%edi
lea    0xb72(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
lea    -0x58(%rbp),%rdi
mov    $0xc,%esi
call   1140 <bzero@plt>
mov    0x2a82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x58(%rbp),%rsi
add    $0x4,%rsi
mov    -0x60(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bcopy@plt>
mov    -0x48(%rbp),%rdi
call   1060 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
cmp    $0x0,%rax
jge    15a1 <elCommInit+0x351>
lea    0xb18(%rip),%rdi
call   10d0 <error@plt>
mov    -0x4c(%rbp),%edi
call   10b0 <set_nonblock@plt>
lea    0xb15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elCommInit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
jne    23bb <elCommInit+0x15b>
lea    0xd81(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   2080 <printf@plt>
mov    0x2d58(%rip),%rax
mov    0x2cc1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c96(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   2110 <open@plt>
cmp    $0xffffffff,%eax
je     24f6 <elCommInit+0x296>
mov    %eax,%ebp
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
mov    0x2c69(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   2050 <fcntl@plt>
lea    0x8(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   20f0 <tcgetattr@plt>
mov    0x2c8a(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   2120 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   2060 <cfsetospeed@plt>
mov    0x2c07(%rip),%rax
mov    0x2c80(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
mov    0x2bf0(%rip),%rdx
or     (%rdx),%eax
mov    0x2c4f(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2c4a(%rip),%rcx
or     (%rcx),%eax
mov    0x2bd9(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2bdc(%rip),%rax
mov    0x2c55(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    %ecx,0x8(%rsp)
mov    0x2c3e(%rip),%rax
or     (%rax),%edx
mov    0x2c25(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0xc(%rsp)
mov    0x2c46(%rip),%rax
mov    0x2c57(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2bd4(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x2c2d(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x14(%rsp)
mov    0x2c06(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   2100 <tcsetattr@plt>
jmp    24e7 <elCommInit+0x287>
lea    0xc7c(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   2140 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %rbp,%rsi
call   2140 <strtok@plt>
test   %rax,%rax
je     23f6 <elCommInit+0x196>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   20b0 <strtol@plt>
mov    %rax,%r14
test   %rax,%rax
jne    23fc <elCommInit+0x19c>
mov    $0x2c93,%r14d
lea    0xc3d(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   2080 <printf@plt>
mov    0x2bb9(%rip),%r12
mov    (%r12),%edi
mov    0x2b1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   2180 <socket@plt>
test   %eax,%eax
js     2509 <elCommInit+0x2a9>
mov    %eax,%ebp
movl   $0x1,0x1c(%rsp)
mov    0x2b54(%rip),%rax
mov    (%rax),%esi
mov    0x2b93(%rip),%rax
mov    (%rax),%edx
lea    0x1c(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   2040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     251f <elCommInit+0x2bf>
mov    %r15,%rdi
call   2090 <gethostbyname@plt>
test   %rax,%rax
je     2535 <elCommInit+0x2d5>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   2150 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rbx),%rsi
lea    0xc(%rsp),%rdi
mov    (%rbx),%edx
call   20d0 <memmove@plt>
mov    %r14,%rdi
call   2070 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   2170 <connect@plt>
test   %rax,%rax
jns    24d4 <elCommInit+0x274>
lea    0xbc3(%rip),%rdi
call   20e0 <error@plt>
mov    %ebp,%edi
call   20c0 <set_nonblock@plt>
lea    0xbc1(%rip),%rdi
call   2030 <puts@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb1b(%rip),%rdi
call   2130 <perror@plt>
mov    $0xffffffff,%ebp
jmp    24e7 <elCommInit+0x287>
lea    0xb58(%rip),%rdi
call   20e0 <error@plt>
mov    $0xffffffff,%edi
call   2160 <exit@plt>
lea    0xb91(%rip),%rdi
call   2030 <puts@plt>
mov    $0xffffffff,%edi
call   2160 <exit@plt>
mov    0x2a14(%rip),%rax
mov    (%rax),%edi
lea    0xb38(%rip),%rsi
call   20a0 <fprintf@plt>
xor    %edi,%edi
call   2160 <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 = [2 x i8] c":\00"
@.str.3 = [40 x i8] c"Connecting to TCP server at %s:%ld....\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [21 x i8] c"ERROR opening socket\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.5 = [34 x i8] c"Couldn't setsockopt(TCP_NODELAY)\0A\00"
@stderr = global i32 0
@.str.6 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.7 = [17 x i8] c"ERROR connecting\00"
@.str.8 = [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 i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
%14 = alloca i32
%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 %180
105: ; preds = %2
%106 = load i8*, i8** %4
%107 = call i8* @strtok(i8* %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %107, i8** %8
%108 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %108, i8** %9
store i64 0, i64* %10
%109 = load i8*, i8** %9
%110 = icmp ne i8* %109, null
br i1 %110, label %111, label %114
111: ; preds = %105
%112 = load i8*, i8** %9
%113 = call i64 @strtol(i8* %112, i32* null, i32 10)
store i64 %113, i64* %10
br label %114
114: ; preds = %111, %105
%115 = load i64, i64* %10
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %114
store i64 11411, i64* %10
br label %118
118: ; preds = %117, %114
%119 = load i8*, i8** %8
%120 = load i64, i64* %10
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %119, i64 %120)
%122 = load i32, i32* @AF_INET
%123 = load i32, i32* @SOCK_STREAM
%124 = call i32 @socket(i32 %122, i32 %123, i32 0)
store i32 %124, i32* %11
%125 = load i32, i32* %11
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %130
127: ; preds = %118
%128 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%129 = call i32 @exit(i32 -1)
unreachable
130: ; preds = %118
store i32 1, i32* %15
%131 = load i32, i32* %11
%132 = load i32, i32* @IPPROTO_TCP
%133 = load i32, i32* @TCP_NODELAY
%134 = bitcast i32* %15 to i8*
%135 = call i32 @setsockopt(i32 %131, i32 %132, i32 %133, i8* %134, i32 4)
store i32 %135, i32* %14
%136 = load i32, i32* %14
%137 = icmp eq i32 %136, -1
br i1 %137, label %138, label %141
138: ; preds = %130
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%140 = call i32 @exit(i32 -1)
unreachable
141: ; preds = %130
%142 = load i8*, i8** %8
%143 = call %struct.hostent* @gethostbyname(i8* %142)
store %struct.hostent* %143, %struct.hostent** %13
%144 = load %struct.hostent*, %struct.hostent** %13
%145 = icmp eq %struct.hostent* %144, null
br i1 %145, label %146, label %150
146: ; preds = %141
%147 = load i32, i32* @stderr
%148 = call i32 @fprintf(i32 %147, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%149 = call i32 @exit(i32 0)
unreachable
150: ; preds = %141
%151 = bitcast %struct.sockaddr_in* %12 to i8*
%152 = call i32 @bzero(i8* %151, i32 12)
%153 = load i32, i32* @AF_INET
%154 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %153, i32* %154
%155 = load %struct.hostent*, %struct.hostent** %13
%156 = getelementptr inbounds %struct.hostent, %struct.hostent* %155, i32 0, i32 1
%157 = load i64, i64* %156
%158 = inttoptr i64 %157 to i8*
%159 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%160 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %159, i32 0, i32 0
%161 = bitcast i32* %160 to i8*
%162 = load %struct.hostent*, %struct.hostent** %13
%163 = getelementptr inbounds %struct.hostent, %struct.hostent* %162, i32 0, i32 0
%164 = load i32, i32* %163
%165 = call i32 @bcopy(i8* %158, i8* %161, i32 %164)
%166 = load i64, i64* %10
%167 = call i32 @htons(i64 %166)
%168 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %167, i32* %168
%169 = load i32, i32* %11
%170 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%171 = call i64 @connect(i32 %169, %struct.sockaddr* %170, i32 12)
%172 = icmp slt i64 %171, 0
br i1 %172, label %173, label %175
173: ; preds = %150
%174 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %175
175: ; preds = %173, %150
%176 = load i32, i32* %11
%177 = call i32 @set_nonblock(i32 %176)
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%179 = load i32, i32* %11
store i32 %179, i32* %3
br label %180
180: ; preds = %175, %103
%181 = load i32, i32* %3
ret i32 %181
}

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