#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 */
typedef int /*<<< orphan*/ uint16_t;
typedef int /*<<< orphan*/ tv;
struct timeval {
  int tv_sec;
  int /*<<< orphan*/ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EHOSTUNREACH;
int EX_DATAERR;
int EX_IOERR;
int EX_NOHOST;
int EX_OK;
int EX_UNAVAILABLE;
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
scalar_t__ connect(int, struct sockaddr const *, int);
int dataq_cmd(int, char *, ...);
scalar_t__ errno;
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ htons(int /*<<< orphan*/ const);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ recv(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
               struct timeval const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
int dataq_connect(const char *hostname, const uint16_t portno,
                  const int timerscaler, const int rate_divisor,
                  const char *scanlist, const int n_chans) {
  if (n_chans > 32) {
    ((void)0);
    return -EX_DATAERR;
  }
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    ((void)0);
    return -EX_UNAVAILABLE;
  }
  const struct timeval tv = {.tv_sec = 1, .tv_usec = 0};
  if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
    ((void)0);
    return -EX_UNAVAILABLE;
  }
  struct hostent *server;
  server = gethostbyname(hostname);
  if (server == NULL) {
    ((void)0);
    return -EX_NOHOST;
  }
  struct sockaddr_in serveraddr;
  memset(&serveraddr, 0, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_port = htons(portno);
  memcpy(&serveraddr.sin_addr.s_addr, server->h_addr, server->h_length);
  if (connect(sockfd, (const struct sockaddr *)&serveraddr,
              sizeof(serveraddr)) < 0) {
    if (errno == EHOSTUNREACH)
      ((void)0);
    else
      ((void)0);
    return -EX_UNAVAILABLE;
  }
  if (write(sockfd, "\0T0", 3) == -1) {
    ((void)0);
    return -EX_IOERR;
  }
  usleep(222222);
  uint16_t buf[16];
  while (recv(sockfd, buf, sizeof(buf), MSG_DONTWAIT) > 0)
    ;
  do {
    int res = dataq_cmd(sockfd, "X%02X", timerscaler);
    if (res != EX_OK)
      return res;
  } while (0);
  do {
    int res = dataq_cmd(sockfd, "M%04X", rate_divisor);
    if (res != EX_OK)
      return res;
  } while (0);
  do {
    int res = dataq_cmd(sockfd, "L00%s", scanlist);
    if (res != EX_OK)
      return res;
  } while (0);
  do {
    int res = dataq_cmd(sockfd, "C%02X", n_chans);
    if (res != EX_OK)
      return res;
  } while (0);
  do {
    int res = dataq_cmd(sockfd, "S3");
    if (res != EX_OK)
      return res;
  } while (0);
  return sockfd;
}


x86 assembly (clang, -O0):
<dataq_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0x20,-0x2c(%rbp)
jle    11ed <dataq_connect+0x3d>
xor    %eax,%eax
mov    0x2ddd(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1226 <dataq_connect+0x76>
xor    %eax,%eax
mov    0x2d6c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
mov    0xdd3(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1271 <dataq_connect+0xc1>
xor    %eax,%eax
mov    0x2d21(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
mov    -0x10(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    129c <dataq_connect+0xec>
xor    %eax,%eax
mov    0x2d46(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1090 <memcpy@plt>
mov    -0x30(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    132b <dataq_connect+0x17b>
mov    0x2ca5(%rip),%rax
mov    (%rax),%rax
mov    0x2cc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1313 <dataq_connect+0x163>
jmp    1318 <dataq_connect+0x168>
jmp    1318 <dataq_connect+0x168>
xor    %eax,%eax
mov    0x2c67(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
mov    -0x30(%rbp),%edi
lea    0xcd3(%rip),%rsi
mov    $0x3,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    135b <dataq_connect+0x1ab>
xor    %eax,%eax
mov    0x2c7f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
mov    $0x3640e,%edi
call   10c0 <usleep@plt>
mov    -0x30(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    0x2c22(%rip),%rax
mov    (%rax),%ecx
mov    $0x40,%edx
call   1030 <recv@plt>
cmp    $0x0,%rax
jle    1391 <dataq_connect+0x1e1>
jmp    1365 <dataq_connect+0x1b5>
jmp    1396 <dataq_connect+0x1e6>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%edx
lea    0xc69(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
mov    0x2bd3(%rip),%rcx
cmp    (%rcx),%eax
je     13d3 <dataq_connect+0x223>
mov    -0x94(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
jmp    13d8 <dataq_connect+0x228>
jmp    13dd <dataq_connect+0x22d>
mov    -0x30(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    0xc28(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%eax
mov    0x2b8c(%rip),%rcx
cmp    (%rcx),%eax
je     141a <dataq_connect+0x26a>
mov    -0x98(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
jmp    141f <dataq_connect+0x26f>
jmp    1424 <dataq_connect+0x274>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rdx
lea    0xbe6(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    0x2b44(%rip),%rcx
cmp    (%rcx),%eax
je     1462 <dataq_connect+0x2b2>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
jmp    1467 <dataq_connect+0x2b7>
jmp    146c <dataq_connect+0x2bc>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
lea    0xba5(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
mov    0x2afd(%rip),%rcx
cmp    (%rcx),%eax
je     14a9 <dataq_connect+0x2f9>
mov    -0xa0(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
jmp    14ae <dataq_connect+0x2fe>
jmp    14b3 <dataq_connect+0x303>
mov    -0x30(%rbp),%edi
lea    0xb67(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
mov    0x2ab9(%rip),%rcx
cmp    (%rcx),%eax
je     14ed <dataq_connect+0x33d>
mov    -0xa4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14f8 <dataq_connect+0x348>
jmp    14f2 <dataq_connect+0x342>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dataq_connect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x21,%r9d
jl     11d2 <dataq_connect+0x22>
mov    0x2dfd(%rip),%rax
xor    %ebx,%ebx
jmp    1393 <dataq_connect+0x1e3>
mov    %r9d,%r13d
mov    %esi,%r14d
mov    %rdi,%r15
mov    %edx,0xc(%rsp)
mov    %ecx,0x8(%rsp)
mov    %r8,0x20(%rsp)
mov    0x2df1(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     138c <dataq_connect+0x1dc>
mov    %eax,%r12d
movq   $0x1,0x28(%rsp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    0x2d90(%rip),%rax
mov    (%rax),%edx
lea    0x28(%rsp),%rcx
mov    %r12d,%edi
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     13a6 <dataq_connect+0x1f6>
mov    %r15,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     13b2 <dataq_connect+0x202>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%edx
mov    0x4(%r15),%esi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1090 <memcpy@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     138c <dataq_connect+0x1dc>
lea    0xd4c(%rip),%rsi
mov    %r12d,%edi
mov    $0x3,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
je     13be <dataq_connect+0x20e>
mov    $0x3640e,%edi
call   10c0 <usleep@plt>
mov    0x2ccd(%rip),%rbp
lea    0x30(%rsp),%rbx
mov    0x0(%rbp),%ecx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1030 <recv@plt>
test   %rax,%rax
jg     12e0 <dataq_connect+0x130>
lea    0xd05(%rip),%rsi
mov    %r12d,%edi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
mov    0x2c8a(%rip),%r14
cmp    (%r14),%eax
jne    1395 <dataq_connect+0x1e5>
lea    0xce8(%rip),%rsi
mov    %r12d,%edi
mov    0x8(%rsp),%edx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
jne    1395 <dataq_connect+0x1e5>
lea    0xcd2(%rip),%rsi
mov    %r12d,%edi
mov    0x20(%rsp),%rdx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
jne    1395 <dataq_connect+0x1e5>
lea    0xcbb(%rip),%rsi
mov    %r12d,%edi
mov    %r13d,%edx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
jne    1395 <dataq_connect+0x1e5>
lea    0xca6(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
cmp    (%r14),%eax
cmovne %eax,%r12d
mov    %r12d,%ebx
jmp    1395 <dataq_connect+0x1e5>
mov    0x2c05(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2beb(%rip),%rax
jmp    11cb <dataq_connect+0x1b>
mov    0x2c1f(%rip),%rax
jmp    11cb <dataq_connect+0x1b>
mov    0x2c0b(%rip),%rax
jmp    11cb <dataq_connect+0x1b>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EX_DATAERR = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@EX_UNAVAILABLE = global i32 0
@__const.dataq_connect.tv = %struct.timeval { i32 1, i32 0 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@EX_NOHOST = global i32 0
@errno = global i64 0
@EHOSTUNREACH = global i64 0
@.str = [4 x i8] c"\00T0\00"
@EX_IOERR = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.1 = [6 x i8] c"X%02X\00"
@EX_OK = global i32 0
@.str.2 = [6 x i8] c"M%04X\00"
@.str.3 = [6 x i8] c"L00%s\00"
@.str.4 = [6 x i8] c"C%02X\00"
@.str.5 = [3 x i8] c"S3\00"
define i32 @dataq_connect(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca %struct.hostent*
%17 = alloca %struct.sockaddr_in
%18 = alloca [16 x i32]
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%24 = load i32, i32* %13
%25 = icmp sgt i32 %24, 32
br i1 %25, label %26, label %29
26: ; preds = %6
%27 = load i32, i32* @EX_DATAERR
%28 = sub nsw i32 0, %27
store i32 %28, i32* %7
br label %157
29: ; preds = %6
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %14
%33 = load i32, i32* %14
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* @EX_UNAVAILABLE
%37 = sub nsw i32 0, %36
store i32 %37, i32* %7
br label %157
38: ; preds = %29
%39 = bitcast %struct.timeval* %15 to i8*
%40 = load i32, i32* %14
%41 = load i32, i32* @SOL_SOCKET
%42 = load i32, i32* @SO_RCVTIMEO
%43 = call i32 @setsockopt(i32 %40, i32 %41, i32 %42, %struct.timeval* %15, i32 8)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i32, i32* @EX_UNAVAILABLE
%47 = sub nsw i32 0, %46
store i32 %47, i32* %7
br label %157
48: ; preds = %38
%49 = load i8*, i8** %8
%50 = call %struct.hostent* @gethostbyname(i8* %49)
store %struct.hostent* %50, %struct.hostent** %16
%51 = load %struct.hostent*, %struct.hostent** %16
%52 = icmp eq %struct.hostent* %51, null
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32, i32* @EX_NOHOST
%55 = sub nsw i32 0, %54
store i32 %55, i32* %7
br label %157
56: ; preds = %48
%57 = call i32 @memset(%struct.sockaddr_in* %17, i32 0, i32 12)
%58 = load i32, i32* @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %58, i32* %59
%60 = load i32, i32* %9
%61 = call i32 @htons(i32 %60)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
store i32 %61, i32* %62
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%64 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i32 0, i32 0
%65 = load %struct.hostent*, %struct.hostent** %16
%66 = getelementptr inbounds %struct.hostent, %struct.hostent* %65, i32 0, i32 1
%67 = load i32, i32* %66
%68 = load %struct.hostent*, %struct.hostent** %16
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @memcpy(i32* %64, i32 %67, i32 %70)
%72 = load i32, i32* %14
%73 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%74 = call i64 @connect(i32 %72, %struct.sockaddr* %73, i32 12)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %85
76: ; preds = %56
%77 = load i64, i64* @errno
%78 = load i64, i64* @EHOSTUNREACH
%79 = icmp eq i64 %77, %78
br i1 %79, label %80, label %81
80: ; preds = %76
br label %82
81: ; preds = %76
br label %82
82: ; preds = %81, %80
%83 = load i32, i32* @EX_UNAVAILABLE
%84 = sub nsw i32 0, %83
store i32 %84, i32* %7
br label %157
85: ; preds = %56
%86 = load i32, i32* %14
%87 = call i32 @write(i32 %86, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %92
89: ; preds = %85
%90 = load i32, i32* @EX_IOERR
%91 = sub nsw i32 0, %90
store i32 %91, i32* %7
br label %157
92: ; preds = %85
%93 = call i32 @usleep(i32 222222)
br label %94
94: ; preds = %100, %92
%95 = load i32, i32* %14
%96 = getelementptr inbounds [16 x i32], [16 x i32]* %18, i64 0, i64 0
%97 = load i32, i32* @MSG_DONTWAIT
%98 = call i64 @recv(i32 %95, i32* %96, i32 64, i32 %97)
%99 = icmp sgt i64 %98, 0
br i1 %99, label %100, label %101
100: ; preds = %94
br label %94
101: ; preds = %94
br label %102
102: ; preds = %101
%103 = load i32, i32* %14
%104 = load i32, i32* %10
%105 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %103, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %104)
store i32 %105, i32* %19
%106 = load i32, i32* %19
%107 = load i32, i32* @EX_OK
%108 = icmp ne i32 %106, %107
br i1 %108, label %109, label %111
109: ; preds = %102
%110 = load i32, i32* %19
store i32 %110, i32* %7
br label %157
111: ; preds = %102
br label %112
112: ; preds = %111
br label %113
113: ; preds = %112
%114 = load i32, i32* %14
%115 = load i32, i32* %11
%116 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %114, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %115)
store i32 %116, i32* %20
%117 = load i32, i32* %20
%118 = load i32, i32* @EX_OK
%119 = icmp ne i32 %117, %118
br i1 %119, label %120, label %122
120: ; preds = %113
%121 = load i32, i32* %20
store i32 %121, i32* %7
br label %157
122: ; preds = %113
br label %123
123: ; preds = %122
br label %124
124: ; preds = %123
%125 = load i32, i32* %14
%126 = load i8*, i8** %12
%127 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %125, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %126)
store i32 %127, i32* %21
%128 = load i32, i32* %21
%129 = load i32, i32* @EX_OK
%130 = icmp ne i32 %128, %129
br i1 %130, label %131, label %133
131: ; preds = %124
%132 = load i32, i32* %21
store i32 %132, i32* %7
br label %157
133: ; preds = %124
br label %134
134: ; preds = %133
br label %135
135: ; preds = %134
%136 = load i32, i32* %14
%137 = load i32, i32* %13
%138 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %136, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %137)
store i32 %138, i32* %22
%139 = load i32, i32* %22
%140 = load i32, i32* @EX_OK
%141 = icmp ne i32 %139, %140
br i1 %141, label %142, label %144
142: ; preds = %135
%143 = load i32, i32* %22
store i32 %143, i32* %7
br label %157
144: ; preds = %135
br label %145
145: ; preds = %144
br label %146
146: ; preds = %145
%147 = load i32, i32* %14
%148 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %147, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32 %148, i32* %23
%149 = load i32, i32* %23
%150 = load i32, i32* @EX_OK
%151 = icmp ne i32 %149, %150
br i1 %151, label %152, label %154
152: ; preds = %146
%153 = load i32, i32* %23
store i32 %153, i32* %7
br label %157
154: ; preds = %146
br label %155
155: ; preds = %154
%156 = load i32, i32* %14
store i32 %156, i32* %7
br label %157
157: ; preds = %155, %152, %142, %131, %120, %109, %89, %82, %53, %45, %35, %26
%158 = load i32, i32* %7
ret i32 %158
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@EX_DATAERR = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@EX_UNAVAILABLE = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@EX_NOHOST = global i32 0
@errno = global i64 0
@EHOSTUNREACH = global i64 0
@.str = [4 x i8] c"\00T0\00"
@EX_IOERR = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.1 = [6 x i8] c"X%02X\00"
@EX_OK = global i32 0
@.str.2 = [6 x i8] c"M%04X\00"
@.str.3 = [6 x i8] c"L00%s\00"
@.str.4 = [6 x i8] c"C%02X\00"
@.str.5 = [3 x i8] c"S3\00"
define i32 @dataq_connect(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i64
%8 = bitcast i64* %7 to %struct.timeval*
%9 = alloca %struct.sockaddr_in
%10 = alloca [16 x i32]
%11 = icmp sgt i32 %5, 32
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i32, i32* @EX_DATAERR
%14 = sub nsw i32 0, %13
br label %98
15: ; preds = %6
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* @EX_UNAVAILABLE
%22 = sub nsw i32 0, %21
br label %98
23: ; preds = %15
%24 = bitcast i64* %7 to i8*
store i64 1, i64* %7
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_RCVTIMEO
%27 = call i32 @setsockopt(i32 %18, i32 %25, i32 %26, %struct.timeval* %8, i32 8)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* @EX_UNAVAILABLE
%31 = sub nsw i32 0, %30
br label %96
32: ; preds = %23
%33 = call %struct.hostent* @gethostbyname(i8* %0)
%34 = icmp eq %struct.hostent* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @EX_NOHOST
%37 = sub nsw i32 0, %36
br label %96
38: ; preds = %32
%39 = bitcast %struct.sockaddr_in* %9 to i8*
%40 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2
store i32 %41, i32* %42
%43 = call i32 @htons(i32 %1)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0, i32 0
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i64 0, i32 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i64 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @memcpy(i32* %45, i32 %47, i32 %49)
%51 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%52 = call i64 @connect(i32 %18, %struct.sockaddr* %51, i32 12)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %38
%55 = load i32, i32* @EX_UNAVAILABLE
%56 = sub nsw i32 0, %55
br label %94
57: ; preds = %38
%58 = call i32 @write(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32, i32* @EX_IOERR
%62 = sub nsw i32 0, %61
br label %94
63: ; preds = %57
%64 = call i32 @usleep(i32 222222)
%65 = bitcast [16 x i32]* %10 to i8*
%66 = getelementptr inbounds [16 x i32], [16 x i32]* %10, i64 0, i64 0
br label %67
67: ; preds = %67, %63
%68 = load i32, i32* @MSG_DONTWAIT
%69 = call i64 @recv(i32 %18, i32* %66, i32 64, i32 %68)
%70 = icmp sgt i64 %69, 0
br i1 %70, label %67, label %71
71: ; preds = %67
%72 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%73 = load i32, i32* @EX_OK
%74 = icmp eq i32 %72, %73
br i1 %74, label %75, label %92
75: ; preds = %71
%76 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%77 = load i32, i32* @EX_OK
%78 = icmp eq i32 %76, %77
br i1 %78, label %79, label %92
79: ; preds = %75
%80 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%81 = load i32, i32* @EX_OK
%82 = icmp eq i32 %80, %81
br i1 %82, label %83, label %92
83: ; preds = %79
%84 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %5)
%85 = load i32, i32* @EX_OK
%86 = icmp eq i32 %84, %85
br i1 %86, label %87, label %92
87: ; preds = %83
%88 = call i32 (i32, i8*, ...) @dataq_cmd(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%89 = load i32, i32* @EX_OK
%90 = icmp eq i32 %88, %89
%91 = select i1 %90, i32 %18, i32 %88
br label %92
92: ; preds = %87, %83, %79, %75, %71
%93 = phi i32 [ %84, %83 ], [ %80, %79 ], [ %76, %75 ], [ %72, %71 ], [ %91, %87 ]
br label %94
94: ; preds = %92, %60, %54
%95 = phi i32 [ %56, %54 ], [ %62, %60 ], [ %93, %92 ]
br label %96
96: ; preds = %35, %94, %29
%97 = phi i32 [ %31, %29 ], [ %37, %35 ], [ %95, %94 ]
br label %98
98: ; preds = %20, %96, %12
%99 = phi i32 [ %14, %12 ], [ %22, %20 ], [ %97, %96 ]
ret i32 %99
}