#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*/ uint32_t;
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_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 uint32_t timerscaler, const uint32_t rate_divisor,
                  const char *scanlist, const uint32_t n_chans) {
  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)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1209 <dataq_connect+0x59>
xor    %eax,%eax
mov    0x2d91(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
mov    0xdf0(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1254 <dataq_connect+0xa4>
xor    %eax,%eax
mov    0x2d46(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
mov    -0x10(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    127f <dataq_connect+0xcf>
xor    %eax,%eax
mov    0x2d63(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d4a(%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    130e <dataq_connect+0x15e>
mov    0x2cca(%rip),%rax
mov    (%rax),%rax
mov    0x2ce0(%rip),%rcx
cmp    (%rcx),%rax
jne    12f6 <dataq_connect+0x146>
jmp    12fb <dataq_connect+0x14b>
jmp    12fb <dataq_connect+0x14b>
xor    %eax,%eax
mov    0x2c8c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
mov    -0x30(%rbp),%edi
lea    0xcf0(%rip),%rsi
mov    $0x3,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    133e <dataq_connect+0x18e>
xor    %eax,%eax
mov    0x2c9c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
mov    $0x3640e,%edi
call   10c0 <usleep@plt>
mov    -0x30(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    0x2c47(%rip),%rax
mov    (%rax),%ecx
mov    $0x40,%edx
call   1030 <recv@plt>
cmp    $0x0,%rax
jle    1374 <dataq_connect+0x1c4>
jmp    1348 <dataq_connect+0x198>
jmp    1379 <dataq_connect+0x1c9>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%edx
lea    0xc86(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
mov    0x2bf8(%rip),%rcx
cmp    (%rcx),%eax
je     13b6 <dataq_connect+0x206>
mov    -0x94(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
jmp    13bb <dataq_connect+0x20b>
jmp    13c0 <dataq_connect+0x210>
mov    -0x30(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    0xc45(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%eax
mov    0x2bb1(%rip),%rcx
cmp    (%rcx),%eax
je     13fd <dataq_connect+0x24d>
mov    -0x98(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
jmp    1402 <dataq_connect+0x252>
jmp    1407 <dataq_connect+0x257>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rdx
lea    0xc03(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    0x2b69(%rip),%rcx
cmp    (%rcx),%eax
je     1445 <dataq_connect+0x295>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
jmp    144a <dataq_connect+0x29a>
jmp    144f <dataq_connect+0x29f>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
lea    0xbc2(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
mov    0x2b22(%rip),%rcx
cmp    (%rcx),%eax
je     148c <dataq_connect+0x2dc>
mov    -0xa0(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
jmp    1491 <dataq_connect+0x2e1>
jmp    1496 <dataq_connect+0x2e6>
mov    -0x30(%rbp),%edi
lea    0xb84(%rip),%rsi
mov    $0x0,%al
call   10a0 <dataq_cmd@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
mov    0x2ade(%rip),%rcx
cmp    (%rcx),%eax
je     14d0 <dataq_connect+0x320>
mov    -0xa4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14db <dataq_connect+0x32b>
jmp    14d5 <dataq_connect+0x325>
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
mov    %r9d,%ebp
mov    %r8,0x10(%rsp)
mov    %ecx,0x8(%rsp)
mov    %edx,0xc(%rsp)
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2e05(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     1381 <dataq_connect+0x1d1>
mov    %eax,%r12d
movq   $0x1,0x28(%rsp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
lea    0x28(%rsp),%rcx
mov    %r12d,%edi
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     138a <dataq_connect+0x1da>
mov    %r15,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     1393 <dataq_connect+0x1e3>
mov    %rax,%r15
mov    %ebp,0x4(%rsp)
lea    0x18(%rsp),%rbp
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%r13),%eax
mov    %eax,0x20(%rsp)
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,0x1c(%rsp)
mov    (%r15),%edx
mov    0x4(%r15),%esi
mov    %rbp,%rdi
call   1090 <memcpy@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     1381 <dataq_connect+0x1d1>
lea    0xd5c(%rip),%rsi
mov    %r12d,%edi
mov    $0x3,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
je     139c <dataq_connect+0x1ec>
mov    $0x3640e,%edi
call   10c0 <usleep@plt>
mov    0x2ce5(%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     12d0 <dataq_connect+0x120>
lea    0xd15(%rip),%rsi
mov    %r12d,%edi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
mov    0x2ca2(%rip),%r14
cmp    (%r14),%eax
jne    13a7 <dataq_connect+0x1f7>
lea    0xcf4(%rip),%rsi
mov    %r12d,%edi
mov    0x8(%rsp),%edx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
jne    13a7 <dataq_connect+0x1f7>
lea    0xcde(%rip),%rsi
mov    %r12d,%edi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
jne    13a7 <dataq_connect+0x1f7>
lea    0xcc7(%rip),%rsi
mov    %r12d,%edi
mov    0x4(%rsp),%edx
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
jne    13a7 <dataq_connect+0x1f7>
lea    0xcb1(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   10a0 <dataq_cmd@plt>
cmp    (%r14),%eax
cmovne %eax,%r12d
mov    %r12d,%ebx
jmp    13a7 <dataq_connect+0x1f7>
mov    0x2c18(%rip),%rax
jmp    13a5 <dataq_connect+0x1f5>
mov    0x2c0f(%rip),%rax
jmp    13a3 <dataq_connect+0x1f3>
mov    0x2c3e(%rip),%rax
jmp    13a3 <dataq_connect+0x1f3>
mov    0x2c2d(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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