#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 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 pollfd {
  int fd;
  int events;
  int revents;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ saddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EINPROGRESS;
int ENOTCONN;
int ETIMEDOUT;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int POLLERR;
int POLLHUP;
int POLLRDNORM;
int POLLWRNORM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int errno;
scalar_t__ fcntl(int, int /*<<< orphan*/, int);
scalar_t__ getpeername(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char const *);
int poll(struct pollfd *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int daemon_create_client_socket(const char *ip, int port, int to) {
  int i, n;
  struct pollfd fds[1];
  struct sockaddr_in saddr;
  int sfd, flags, errno_save;
  bzero((char *)&saddr, sizeof(saddr));
  saddr.sin_family = AF_INET;
  saddr.sin_addr.s_addr = inet_addr(ip);
  saddr.sin_port = htons(port);
  if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    return -1;
  }
  if ((flags = fcntl(sfd, F_GETFL, 0)) < 0) {
    errno_save = errno;
    close(sfd);
    errno = errno_save;
    return -1;
  }
  if (fcntl(sfd, F_SETFL, flags | O_NONBLOCK) < 0) {
    errno_save = errno;
    close(sfd);
    errno = errno_save;
    return -1;
  }
  n = connect(sfd, (struct sockaddr *)&saddr, sizeof(saddr));
  if (n < 0) {
    if (errno != EINPROGRESS) {
      errno_save = errno;
      close(sfd);
      errno = errno_save;
      return -1;
    }
  }
  if (n != 0) {
    fds[0].fd = sfd;
    fds[0].events = POLLRDNORM | POLLWRNORM;
    fds[0].revents = 0;
    i = poll(fds, 1, to > 0 ? to * 1000 : -1);
    if (i < 0) {
      errno_save = errno;
      close(sfd);
      errno = errno_save;
      return -1;
    } else if (i == 0) {
      close(sfd);
      errno = ETIMEDOUT;
      return -1;
    } else if (fds[0].revents & (POLLHUP | POLLERR)) {
      close(sfd);
      errno = ENOTCONN;
      return -1;
    }
  }
  i = sizeof(saddr);
  if (getpeername(sfd, (struct sockaddr *)&saddr, (socklen_t *)&i) < 0) {
    errno_save = errno;
    close(sfd);
    errno = errno_save;
    return -1;
  }
  if (fcntl(sfd, F_SETFL, flags) < 0) {
    errno_save = errno;
    close(sfd);
    errno = errno_save;
    return -1;
  }
  return sfd;
}


x86 assembly (clang, -O0):
<daemon_create_client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    1204 <daemon_create_client_socket+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
mov    -0x44(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    124f <daemon_create_client_socket+0xbf>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    -0x4c(%rbp),%ecx
mov    0x2d4f(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
mov    -0x44(%rbp),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
mov    -0x48(%rbp),%edx
mov    0x2d6b(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    12a2 <daemon_create_client_socket+0x112>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    -0x4c(%rbp),%ecx
mov    0x2cfc(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1309 <daemon_create_client_socket+0x179>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    0x2cf8(%rip),%rcx
cmp    (%rcx),%eax
je     1304 <daemon_create_client_socket+0x174>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    -0x4c(%rbp),%ecx
mov    0x2c9a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
jmp    1309 <daemon_create_client_socket+0x179>
cmpl   $0x0,-0x20(%rbp)
je     1432 <daemon_create_client_socket+0x2a2>
mov    -0x44(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    0x2cc7(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1356 <daemon_create_client_socket+0x1c6>
imul   $0x3e8,-0x18(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1363 <daemon_create_client_socket+0x1d3>
mov    $0xffffffff,%eax
mov    %eax,-0x5c(%rbp)
jmp    1363 <daemon_create_client_socket+0x1d3>
mov    -0x58(%rbp),%rdi
mov    -0x5c(%rbp),%edx
mov    $0x1,%esi
call   1080 <poll@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    13ad <daemon_create_client_socket+0x21d>
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    -0x4c(%rbp),%ecx
mov    0x2bf1(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
cmpl   $0x0,-0x1c(%rbp)
jne    13dd <daemon_create_client_socket+0x24d>
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    0x2bba(%rip),%rax
mov    (%rax),%ecx
mov    0x2bc1(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
mov    -0x28(%rbp),%eax
mov    0x2bf9(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bc8(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1423 <daemon_create_client_socket+0x293>
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    0x2ba4(%rip),%rax
mov    (%rax),%ecx
mov    0x2b7b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
jmp    1428 <daemon_create_client_socket+0x298>
jmp    142d <daemon_create_client_socket+0x29d>
jmp    1432 <daemon_create_client_socket+0x2a2>
movl   $0xc,-0x1c(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <getpeername@plt>
cmp    $0x0,%rax
jge    147f <daemon_create_client_socket+0x2ef>
mov    0x2b36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    -0x4c(%rbp),%ecx
mov    0x2b1f(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
mov    -0x44(%rbp),%edi
mov    0x2b17(%rip),%rax
mov    (%rax),%esi
mov    -0x48(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    14c9 <daemon_create_client_socket+0x339>
mov    0x2aec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
mov    -0x4c(%rbp),%ecx
mov    0x2ad5(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14cf <daemon_create_client_socket+0x33f>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemon_create_client_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%rbp
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e1c(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    %rbp,%rdi
call   1070 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%r14),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     133c <daemon_create_client_socket+0x1ac>
mov    %eax,%ebp
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rax,%r13
test   %r13d,%r13d
js     1323 <daemon_create_client_socket+0x193>
mov    0x2d7e(%rip),%r12
mov    (%r12),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
or     %r13d,%edx
mov    %ebp,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
js     1323 <daemon_create_client_socket+0x193>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %eax,%eax
js     125e <daemon_create_client_socket+0xce>
jne    1276 <daemon_create_client_socket+0xe6>
jmp    12ed <daemon_create_client_socket+0x15d>
mov    0x2d2b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d5a(%rip),%rax
cmp    (%rax),%ebx
jne    132c <daemon_create_client_socket+0x19c>
mov    0x2d43(%rip),%rax
mov    0x2d6c(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ebp,0x18(%rsp)
mov    %ecx,0x1c(%rsp)
movl   $0x0,0x20(%rsp)
imul   $0x3e8,%r15d,%eax
test   %r15d,%r15d
mov    $0xffffffff,%edx
cmovg  %eax,%edx
lea    0x18(%rsp),%rdi
mov    $0x1,%esi
call   1080 <poll@plt>
test   %eax,%eax
js     1323 <daemon_create_client_socket+0x193>
je     134e <daemon_create_client_socket+0x1be>
mov    0x2d16(%rip),%rax
mov    0x2ce7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
test   %ecx,0x20(%rsp)
je     12ed <daemon_create_client_socket+0x15d>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%ebx
jmp    1333 <daemon_create_client_socket+0x1a3>
movl   $0xc,0x14(%rsp)
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    %ebp,%edi
call   1040 <getpeername@plt>
test   %rax,%rax
js     1323 <daemon_create_client_socket+0x193>
mov    (%r12),%esi
mov    %ebp,%edi
mov    %r13d,%edx
call   1030 <fcntl@plt>
test   %rax,%rax
js     1323 <daemon_create_client_socket+0x193>
mov    %ebp,%r14d
jmp    133c <daemon_create_client_socket+0x1ac>
mov    0x2c66(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2c56(%rip),%rax
mov    %ebx,(%rax)
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%ebx
jmp    1333 <daemon_create_client_socket+0x1a3>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@EINPROGRESS = global i32 0
@POLLRDNORM = global i32 0
@POLLWRNORM = global i32 0
@ETIMEDOUT = global i32 0
@POLLHUP = global i32 0
@POLLERR = global i32 0
@ENOTCONN = global i32 0
define i32 @daemon_create_client_socket(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1 x %struct.pollfd]
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%15 = bitcast %struct.sockaddr_in* %11 to i8*
%16 = call i32 @bzero(i8* %15, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i8*, i8** %5
%20 = call i32 @inet_addr(i8* %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %6
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
store i32 %28, i32* %12
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %3
store i32 -1, i32* %4
br label %148
31: ; preds = %3
%32 = load i32, i32* %12
%33 = load i32, i32* @F_GETFL
%34 = call i64 @fcntl(i32 %32, i32 %33, i32 0)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %13
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* @errno
store i32 %38, i32* %14
%39 = load i32, i32* %12
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %14
store i32 %41, i32* @errno
store i32 -1, i32* %4
br label %148
42: ; preds = %31
%43 = load i32, i32* %12
%44 = load i32, i32* @F_SETFL
%45 = load i32, i32* %13
%46 = load i32, i32* @O_NONBLOCK
%47 = or i32 %45, %46
%48 = call i64 @fcntl(i32 %43, i32 %44, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %42
%51 = load i32, i32* @errno
store i32 %51, i32* %14
%52 = load i32, i32* %12
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %14
store i32 %54, i32* @errno
store i32 -1, i32* %4
br label %148
55: ; preds = %42
%56 = load i32, i32* %12
%57 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%58 = call i32 @connect(i32 %56, %struct.sockaddr* %57, i32 12)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %55
%62 = load i32, i32* @errno
%63 = load i32, i32* @EINPROGRESS
%64 = icmp ne i32 %62, %63
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load i32, i32* @errno
store i32 %66, i32* %14
%67 = load i32, i32* %12
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* %14
store i32 %69, i32* @errno
store i32 -1, i32* %4
br label %148
70: ; preds = %61
br label %71
71: ; preds = %70, %55
%72 = load i32, i32* %9
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %125
74: ; preds = %71
%75 = load i32, i32* %12
%76 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %10, i64 0, i64 0
%77 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %76, i32 0, i32 0
store i32 %75, i32* %77
%78 = load i32, i32* @POLLRDNORM
%79 = load i32, i32* @POLLWRNORM
%80 = or i32 %78, %79
%81 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %10, i64 0, i64 0
%82 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %81, i32 0, i32 1
store i32 %80, i32* %82
%83 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %10, i64 0, i64 0
%84 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %83, i32 0, i32 2
store i32 0, i32* %84
%85 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %10, i64 0, i64 0
%86 = load i32, i32* %7
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %74
%89 = load i32, i32* %7
%90 = mul nsw i32 %89, 1000
br label %92
91: ; preds = %74
br label %92
92: ; preds = %91, %88
%93 = phi i32 [ %90, %88 ], [ -1, %91 ]
%94 = call i32 @poll(%struct.pollfd* %85, i32 1, i32 %93)
store i32 %94, i32* %8
%95 = load i32, i32* %8
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %102
97: ; preds = %92
%98 = load i32, i32* @errno
store i32 %98, i32* %14
%99 = load i32, i32* %12
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* %14
store i32 %101, i32* @errno
store i32 -1, i32* %4
br label %148
102: ; preds = %92
%103 = load i32, i32* %8
%104 = icmp eq i32 %103, 0
br i1 %104, label %105, label %109
105: ; preds = %102
%106 = load i32, i32* %12
%107 = call i32 @close(i32 %106)
%108 = load i32, i32* @ETIMEDOUT
store i32 %108, i32* @errno
store i32 -1, i32* %4
br label %148
109: ; preds = %102
%110 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %10, i64 0, i64 0
%111 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %110, i32 0, i32 2
%112 = load i32, i32* %111
%113 = load i32, i32* @POLLHUP
%114 = load i32, i32* @POLLERR
%115 = or i32 %113, %114
%116 = and i32 %112, %115
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %122
118: ; preds = %109
%119 = load i32, i32* %12
%120 = call i32 @close(i32 %119)
%121 = load i32, i32* @ENOTCONN
store i32 %121, i32* @errno
store i32 -1, i32* %4
br label %148
122: ; preds = %109
br label %123
123: ; preds = %122
br label %124
124: ; preds = %123
br label %125
125: ; preds = %124, %71
store i32 12, i32* %8
%126 = load i32, i32* %12
%127 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%128 = call i64 @getpeername(i32 %126, %struct.sockaddr* %127, i32* %8)
%129 = icmp slt i64 %128, 0
br i1 %129, label %130, label %135
130: ; preds = %125
%131 = load i32, i32* @errno
store i32 %131, i32* %14
%132 = load i32, i32* %12
%133 = call i32 @close(i32 %132)
%134 = load i32, i32* %14
store i32 %134, i32* @errno
store i32 -1, i32* %4
br label %148
135: ; preds = %125
%136 = load i32, i32* %12
%137 = load i32, i32* @F_SETFL
%138 = load i32, i32* %13
%139 = call i64 @fcntl(i32 %136, i32 %137, i32 %138)
%140 = icmp slt i64 %139, 0
br i1 %140, label %141, label %146
141: ; preds = %135
%142 = load i32, i32* @errno
store i32 %142, i32* %14
%143 = load i32, i32* %12
%144 = call i32 @close(i32 %143)
%145 = load i32, i32* %14
store i32 %145, i32* @errno
store i32 -1, i32* %4
br label %148
146: ; preds = %135
%147 = load i32, i32* %12
store i32 %147, i32* %4
br label %148
148: ; preds = %146, %141, %130, %118, %105, %97, %65, %50, %37, %30
%149 = load i32, i32* %4
ret i32 %149
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@EINPROGRESS = global i32 0
@POLLRDNORM = global i32 0
@POLLWRNORM = global i32 0
@ETIMEDOUT = global i32 0
@POLLHUP = global i32 0
@POLLERR = global i32 0
@ENOTCONN = global i32 0
define i32 @daemon_create_client_socket(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca [1 x %struct.pollfd]
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %4 to i8*
%8 = bitcast [1 x %struct.pollfd]* %5 to i8*
%9 = bitcast %struct.sockaddr_in* %6 to i8*
%10 = call i32 @bzero(i8* %9, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @inet_addr(i8* %0)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 %1)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %96, label %21
21: ; preds = %3
%22 = load i32, i32* @F_GETFL
%23 = tail call i64 @fcntl(i32 %19, i32 %22, i32 0)
%24 = trunc i64 %23 to i32
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = tail call i32 @close(i32 %19)
br label %94
29: ; preds = %21
%30 = load i32, i32* @F_SETFL
%31 = load i32, i32* @O_NONBLOCK
%32 = or i32 %31, %24
%33 = tail call i64 @fcntl(i32 %19, i32 %30, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* @errno
%37 = tail call i32 @close(i32 %19)
br label %94
38: ; preds = %29
%39 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%40 = call i32 @connect(i32 %19, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = load i32, i32* @EINPROGRESS
%45 = icmp eq i32 %43, %44
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = call i32 @close(i32 %19)
br label %94
48: ; preds = %38
%49 = icmp eq i32 %40, 0
br i1 %49, label %81, label %50
50: ; preds = %42, %48
%51 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%52 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 0
store i32 %19, i32* %52
%53 = load i32, i32* @POLLRDNORM
%54 = load i32, i32* @POLLWRNORM
%55 = or i32 %54, %53
%56 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 1
store i32 %55, i32* %56
%57 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 2
store i32 0, i32* %57
%58 = icmp sgt i32 %2, 0
%59 = mul nsw i32 %2, 1000
%60 = select i1 %58, i32 %59, i32 -1
%61 = call i32 @poll(%struct.pollfd* %51, i32 1, i32 %60)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %50
%64 = load i32, i32* @errno
%65 = call i32 @close(i32 %19)
br label %94
66: ; preds = %50
%67 = icmp eq i32 %61, 0
br i1 %67, label %68, label %71
68: ; preds = %66
%69 = call i32 @close(i32 %19)
%70 = load i32, i32* @ETIMEDOUT
br label %94
71: ; preds = %66
%72 = load i32, i32* %57
%73 = load i32, i32* @POLLHUP
%74 = load i32, i32* @POLLERR
%75 = or i32 %74, %73
%76 = and i32 %75, %72
%77 = icmp eq i32 %76, 0
br i1 %77, label %81, label %78
78: ; preds = %71
%79 = call i32 @close(i32 %19)
%80 = load i32, i32* @ENOTCONN
br label %94
81: ; preds = %71, %48
store i32 12, i32* %4
%82 = call i64 @getpeername(i32 %19, %struct.sockaddr* %39, i32* %4)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32, i32* @errno
%86 = call i32 @close(i32 %19)
br label %94
87: ; preds = %81
%88 = load i32, i32* @F_SETFL
%89 = call i64 @fcntl(i32 %19, i32 %88, i32 %24)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %87
%92 = load i32, i32* @errno
%93 = call i32 @close(i32 %19)
br label %94
94: ; preds = %26, %35, %46, %63, %68, %78, %84, %91
%95 = phi i32 [ %92, %91 ], [ %85, %84 ], [ %80, %78 ], [ %70, %68 ], [ %64, %63 ], [ %43, %46 ], [ %36, %35 ], [ %27, %26 ]
store i32 %95, i32* @errno
br label %96
96: ; preds = %94, %87, %3
%97 = phi i32 [ -1, %3 ], [ %19, %87 ], [ -1, %94 ]
ret i32 %97
}