#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  scalar_t__ ai_family;
  TYPE_1__ sin_addr;
  scalar_t__ ai_addr;
  struct sockaddr_in *ai_next;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ sin_port;
  scalar_t__ sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_family;
  TYPE_1__ sin_addr;
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ sin_port;
  scalar_t__ sin_family;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ server_address;
typedef scalar_t__ in_addr_t;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ EALREADY;
scalar_t__ EINPROGRESS;
scalar_t__ INADDR_NONE;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct sockaddr_in *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct sockaddr_in *, struct sockaddr_in **);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, scalar_t__, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int sendMessage(char *addr, int port, char *command, char *buffer, int bsize) {
  ssize_t z;
  int com_socket;
  struct sockaddr_in server_address;
  struct timeval timeout;
  in_addr_t address = inet_addr(addr);
  memset(&server_address, 0, sizeof(server_address));
  server_address.sin_family = AF_INET;
  server_address.sin_port = htons(port);
  server_address.sin_addr.s_addr = address;
  if (server_address.sin_addr.s_addr == INADDR_NONE) {
    char portstr[10];
    sprintf(portstr, "%d", port);
    struct addrinfo hints, *p, *servinfo;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    if ((z = getaddrinfo(addr, portstr, &hints, &servinfo)) != 0) {
      fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(z));
      return 0;
    }
    for (p = servinfo; p != NULL; p = p->ai_next) {
      if (p->ai_family == AF_INET) {
        struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
        server_address.sin_addr = ipv4->sin_addr;
        z = 1;
      } else {
        printf("no ipv6 support");
        z = 0;
      }
    }
    freeaddrinfo(servinfo);
    if (z == 0) {
      fprintf(stderr, "No DNS found\n");
      return 0;
    }
  }
  if (strlen(command) <= 0) {
    fprintf(stderr, "No command given\n");
    return 0;
  }
  com_socket = socket(PF_INET, SOCK_STREAM, 0);
  if (com_socket == -1) {
    fprintf(stderr, "Socket failed\n");
    return 0;
  }
  timeout.tv_sec = 2;
  timeout.tv_usec = 0;
  z = connect(com_socket, (struct sockaddr *)&server_address,
              sizeof(server_address));
  if (z == -1) {
    if (errno == EINPROGRESS) {
      fprintf(stderr, "EINPROGRESS non block start\n");
    }
    if (errno == EALREADY) {
      fprintf(stderr, "EALREADY non block subsequent request\n");
    }
    fprintf(stderr, "Connect failed\n");
    return 0;
  }
  z = send(com_socket, command, strlen(command) + 1, 0);
  if (z < 0) {
    fprintf(stderr, "send failure\n");
    return 0;
  }
  z = recv(com_socket, buffer, bsize, 0);
  if (z < 0) {
    fprintf(stderr, "receive failure\n");
    return 0;
  }
  close(com_socket);
  return 1;
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,-0x80(%rbp)
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x44(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%rax
jne    13dd <sendMessage+0x1ed>
lea    -0x8a(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd8f(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2d17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8a(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
lea    -0xd0(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     130d <sendMessage+0x11d>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdc(%rbp)
mov    -0x30(%rbp),%edi
call   1080 <gai_strerror@plt>
mov    -0xdc(%rbp),%edi
mov    %rax,%rdx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
mov    -0xd0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     139f <sendMessage+0x1af>
mov    -0xc8(%rbp),%rax
mov    (%rax),%rax
mov    0x2cae(%rip),%rcx
cmp    (%rcx),%rax
jne    1370 <sendMessage+0x180>
mov    -0xc8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1383 <sendMessage+0x193>
lea    0xca3(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x30(%rbp)
jmp    1388 <sendMessage+0x198>
mov    -0xc8(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0xc8(%rbp)
jmp    131b <sendMessage+0x12b>
mov    -0xd0(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
cmpl   $0x0,-0x30(%rbp)
jne    13d8 <sendMessage+0x1e8>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
lea    0xc65(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
jmp    13dd <sendMessage+0x1ed>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jg     1413 <sendMessage+0x223>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xc38(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
mov    0x2b95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    145c <sendMessage+0x26c>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
lea    0xc01(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
movl   $0x2,-0x78(%rbp)
movq   $0x0,-0x70(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x30,%edx
call   10e0 <connect@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    150e <sendMessage+0x31e>
mov    0x2b20(%rip),%rax
mov    (%rax),%rax
mov    0x2b46(%rip),%rcx
cmp    (%rcx),%rax
jne    14ba <sendMessage+0x2ca>
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
lea    0xba6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2aef(%rip),%rax
mov    (%rax),%rax
mov    0x2af5(%rip),%rcx
cmp    (%rcx),%rax
jne    14eb <sendMessage+0x2fb>
mov    0x2aed(%rip),%rax
mov    (%rax),%edi
lea    0xb92(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2ad6(%rip),%rax
mov    (%rax),%edi
lea    0xba2(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
mov    -0x34(%rbp),%eax
mov    %eax,-0xec(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xec(%rbp),%edi
mov    -0xe8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1576 <sendMessage+0x386>
mov    0x2a6e(%rip),%rax
mov    (%rax),%edi
lea    0xb4a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    15b7 <sendMessage+0x3c7>
mov    0x2a2d(%rip),%rax
mov    (%rax),%edi
lea    0xb17(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15c6 <sendMessage+0x3d6>
mov    -0x34(%rbp),%edi
call   10a0 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8d,%r14d
mov    %rcx,0x10(%rsp)
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,%r13
call   10b0 <inet_addr@plt>
mov    %rax,%rbp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
mov    0x2db7(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x40(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x3c(%rsp)
mov    %rbp,0x20(%rsp)
mov    0x2d88(%rip),%rax
cmp    (%rax),%rbp
jne    1349 <sendMessage+0x159>
mov    %r14d,0x4(%rsp)
lea    0xd9b(%rip),%rsi
lea    0x4e(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   10d0 <sprintf@plt>
lea    0x58(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x58(%rsp)
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x78(%rsp)
lea    0x8(%rsp),%rcx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
je     12de <sendMessage+0xee>
mov    0x2d0b(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   1080 <gai_strerror@plt>
lea    0xd36(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    148d <sendMessage+0x29d>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     146c <sendMessage+0x27c>
mov    (%r15),%rax
lea    0xd24(%rip),%r14
jmp    1314 <sendMessage+0x124>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <printf@plt>
mov    (%r15),%rax
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1331 <sendMessage+0x141>
mov    %rax,%rbp
mov    (%rbx),%r13
cmp    %rax,%r13
jne    1300 <sendMessage+0x110>
mov    0x10(%rbx),%rax
mov    0x8(%rax),%rax
mov    %rax,0x20(%rsp)
mov    %rbp,%rax
jmp    130b <sendMessage+0x11b>
mov    0x8(%rsp),%rdi
call   1100 <freeaddrinfo@plt>
cmp    %rbp,%r13
jne    1474 <sendMessage+0x284>
mov    0x4(%rsp),%r14d
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    13e0 <sendMessage+0x1f0>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
mov    0x2c4e(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     13f5 <sendMessage+0x205>
mov    %eax,%ebp
lea    0x18(%rsp),%rsi
mov    %eax,%edi
mov    $0x30,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     1407 <sendMessage+0x217>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     14a1 <sendMessage+0x2b1>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    0x10(%rsp),%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     14b3 <sendMessage+0x2c3>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    $0x1,%ebx
jmp    148d <sendMessage+0x29d>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
lea    0xc48(%rip),%rsi
jmp    1484 <sendMessage+0x294>
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
lea    0xc45(%rip),%rsi
jmp    1486 <sendMessage+0x296>
mov    0x2ba2(%rip),%rbx
mov    (%rbx),%rax
mov    0x2bc8(%rip),%rcx
cmp    (%rcx),%rax
jne    1437 <sendMessage+0x247>
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
lea    0xc2c(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%rax
mov    0x2b82(%rip),%rcx
cmp    (%rcx),%rax
jne    145a <sendMessage+0x26a>
mov    0x2b7e(%rip),%rax
mov    (%rax),%edi
lea    0xc23(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
lea    0xc33(%rip),%rsi
jmp    1484 <sendMessage+0x294>
mov    %rbx,%rdi
call   1100 <freeaddrinfo@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%edi
lea    0xba6(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b20(%rip),%rax
mov    (%rax),%edi
lea    0xbfc(%rip),%rsi
jmp    1486 <sendMessage+0x296>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
lea    0xbf8(%rip),%rsi
jmp    1486 <sendMessage+0x296>

LLVM IR (-O0):
%struct.sockaddr_in = type { i64, %struct.TYPE_2__, i64, %struct.sockaddr_in*, i32, i32, i64 }
%struct.TYPE_2__ = type { i64 }
%struct.timeval = type { i32, i64 }
%struct.addrinfo = type { i64, %struct.TYPE_2__, i64, %struct.addrinfo*, i32, i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i64 0
@INADDR_NONE = global i64 0
@.str = [3 x i8] c"%d\00"
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"getaddrinfo error: %s\0A\00"
@.str.2 = [16 x i8] c"no ipv6 support\00"
@.str.3 = [14 x i8] c"No DNS found\0A\00"
@.str.4 = [18 x i8] c"No command given\0A\00"
@PF_INET = global i32 0
@.str.5 = [15 x i8] c"Socket failed\0A\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.6 = [29 x i8] c"EINPROGRESS non block start\0A\00"
@EALREADY = global i64 0
@.str.7 = [39 x i8] c"EALREADY non block subsequent request\0A\00"
@.str.8 = [16 x i8] c"Connect failed\0A\00"
@.str.9 = [14 x i8] c"send failure\0A\00"
@.str.10 = [17 x i8] c"receive failure\0A\00"
define i32 @sendMessage(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.sockaddr_in
%15 = alloca %struct.timeval
%16 = alloca i64
%17 = alloca [10 x i8]
%18 = alloca %struct.addrinfo
%19 = alloca %struct.addrinfo*
%20 = alloca %struct.addrinfo*
%21 = alloca %struct.sockaddr_in*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%22 = load i8*, i8** %7
%23 = call i64 @inet_addr(i8* %22)
store i64 %23, i64* %16
%24 = call i32 @memset(%struct.sockaddr_in* %14, i32 0, i32 48)
%25 = load i64, i64* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 6
store i64 %25, i64* %26
%27 = load i32, i32* %8
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 5
store i32 %28, i32* %29
%30 = load i64, i64* %16
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i64 %30, i64* %32
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = load i64, i64* @INADDR_NONE
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %97
38: ; preds = %5
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %17, i64 0, i64 0
%40 = load i32, i32* %8
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = bitcast %struct.addrinfo* %18 to %struct.sockaddr_in*
%43 = call i32 @memset(%struct.sockaddr_in* %42, i32 0, i32 48)
%44 = load i64, i64* @AF_INET
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i32 0, i32 0
store i64 %44, i64* %45
%46 = load i32, i32* @SOCK_STREAM
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i32 0, i32 4
store i32 %46, i32* %47
%48 = load i8*, i8** %7
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %17, i64 0, i64 0
%50 = bitcast %struct.addrinfo* %18 to %struct.sockaddr_in*
%51 = bitcast %struct.addrinfo** %20 to %struct.sockaddr_in**
%52 = call i32 @getaddrinfo(i8* %48, i8* %49, %struct.sockaddr_in* %50, %struct.sockaddr_in** %51)
store i32 %52, i32* %12
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %38
%55 = load i32, i32* @stderr
%56 = load i32, i32* %12
%57 = call i8* @gai_strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %57)
store i32 0, i32* %6
br label %163
59: ; preds = %38
%60 = load %struct.addrinfo*, %struct.addrinfo** %20
store %struct.addrinfo* %60, %struct.addrinfo** %19
br label %61
61: ; preds = %83, %59
%62 = load %struct.addrinfo*, %struct.addrinfo** %19
%63 = icmp ne %struct.addrinfo* %62, null
br i1 %63, label %64, label %87
64: ; preds = %61
%65 = load %struct.addrinfo*, %struct.addrinfo** %19
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = load i64, i64* @AF_INET
%69 = icmp eq i64 %67, %68
br i1 %69, label %70, label %80
70: ; preds = %64
%71 = load %struct.addrinfo*, %struct.addrinfo** %19
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i32 0, i32 2
%73 = load i64, i64* %72
%74 = inttoptr i64 %73 to %struct.sockaddr_in*
store %struct.sockaddr_in* %74, %struct.sockaddr_in** %21
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%76 = load %struct.sockaddr_in*, %struct.sockaddr_in** %21
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %76, i32 0, i32 1
%78 = bitcast %struct.TYPE_2__* %75 to i8*
%79 = bitcast %struct.TYPE_2__* %77 to i8*
store i32 1, i32* %12
br label %82
80: ; preds = %64
%81 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %12
br label %82
82: ; preds = %80, %70
br label %83
83: ; preds = %82
%84 = load %struct.addrinfo*, %struct.addrinfo** %19
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i32 0, i32 3
%86 = load %struct.addrinfo*, %struct.addrinfo** %85
store %struct.addrinfo* %86, %struct.addrinfo** %19
br label %61
87: ; preds = %61
%88 = load %struct.addrinfo*, %struct.addrinfo** %20
%89 = bitcast %struct.addrinfo* %88 to %struct.sockaddr_in*
%90 = call i32 @freeaddrinfo(%struct.sockaddr_in* %89)
%91 = load i32, i32* %12
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %87
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %163
96: ; preds = %87
br label %97
97: ; preds = %96, %5
%98 = load i8*, i8** %9
%99 = call i64 @strlen(i8* %98)
%100 = icmp sle i64 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %97
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %163
104: ; preds = %97
%105 = load i32, i32* @PF_INET
%106 = load i32, i32* @SOCK_STREAM
%107 = call i32 @socket(i32 %105, i32 %106, i32 0)
store i32 %107, i32* %13
%108 = load i32, i32* %13
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %104
%111 = load i32, i32* @stderr
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %6
br label %163
113: ; preds = %104
%114 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i32 2, i32* %114
%115 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i64 0, i64* %115
%116 = load i32, i32* %13
%117 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%118 = call i32 @connect(i32 %116, %struct.sockaddr* %117, i32 48)
store i32 %118, i32* %12
%119 = load i32, i32* %12
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %138
121: ; preds = %113
%122 = load i64, i64* @errno
%123 = load i64, i64* @EINPROGRESS
%124 = icmp eq i64 %122, %123
br i1 %124, label %125, label %128
125: ; preds = %121
%126 = load i32, i32* @stderr
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %128
128: ; preds = %125, %121
%129 = load i64, i64* @errno
%130 = load i64, i64* @EALREADY
%131 = icmp eq i64 %129, %130
br i1 %131, label %132, label %135
132: ; preds = %128
%133 = load i32, i32* @stderr
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %135
135: ; preds = %132, %128
%136 = load i32, i32* @stderr
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %6
br label %163
138: ; preds = %113
%139 = load i32, i32* %13
%140 = load i8*, i8** %9
%141 = load i8*, i8** %9
%142 = call i64 @strlen(i8* %141)
%143 = add nsw i64 %142, 1
%144 = call i32 @send(i32 %139, i8* %140, i64 %143, i32 0)
store i32 %144, i32* %12
%145 = load i32, i32* %12
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %150
147: ; preds = %138
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %6
br label %163
150: ; preds = %138
%151 = load i32, i32* %13
%152 = load i8*, i8** %10
%153 = load i32, i32* %11
%154 = call i32 @recv(i32 %151, i8* %152, i32 %153, i32 0)
store i32 %154, i32* %12
%155 = load i32, i32* %12
%156 = icmp slt i32 %155, 0
br i1 %156, label %157, label %160
157: ; preds = %150
%158 = load i32, i32* @stderr
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %6
br label %163
160: ; preds = %150
%161 = load i32, i32* %13
%162 = call i32 @close(i32 %161)
store i32 1, i32* %6
br label %163
163: ; preds = %160, %157, %147, %135, %110, %101, %93, %54
%164 = load i32, i32* %6
ret i32 %164
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64, %struct.TYPE_2__, i64, %struct.sockaddr_in*, i32, i32, i64 }
%struct.TYPE_2__ = type { i64 }
%struct.addrinfo = type { i64, %struct.TYPE_2__, i64, %struct.addrinfo*, i32, i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i64 0
@INADDR_NONE = global i64 0
@.str = [3 x i8] c"%d\00"
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"getaddrinfo error: %s\0A\00"
@.str.2 = [16 x i8] c"no ipv6 support\00"
@.str.3 = [14 x i8] c"No DNS found\0A\00"
@.str.4 = [18 x i8] c"No command given\0A\00"
@PF_INET = global i32 0
@.str.5 = [15 x i8] c"Socket failed\0A\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.6 = [29 x i8] c"EINPROGRESS non block start\0A\00"
@EALREADY = global i64 0
@.str.7 = [39 x i8] c"EALREADY non block subsequent request\0A\00"
@.str.8 = [16 x i8] c"Connect failed\0A\00"
@.str.9 = [14 x i8] c"send failure\0A\00"
@.str.10 = [17 x i8] c"receive failure\0A\00"
define i32 @sendMessage(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca %struct.sockaddr_in
%7 = alloca [10 x i8]
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = tail call i64 @inet_addr(i8* %0)
%12 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 48)
%13 = load i64, i64* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 6
store i64 %13, i64* %14
%15 = call i32 @htons(i32 %1)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 5
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
store i64 %11, i64* %17
%18 = load i64, i64* @INADDR_NONE
%19 = icmp eq i64 %11, %18
br i1 %19, label %20, label %73
20: ; preds = %5
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%22 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%23 = bitcast %struct.addrinfo* %8 to i8*
%24 = bitcast %struct.addrinfo** %9 to i8*
%25 = bitcast %struct.addrinfo* %8 to %struct.sockaddr_in*
%26 = call i32 @memset(%struct.sockaddr_in* %25, i32 0, i32 48)
%27 = load i64, i64* @AF_INET
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i64 0, i32 0
store i64 %27, i64* %28
%29 = load i32, i32* @SOCK_STREAM
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i64 0, i32 4
store i32 %29, i32* %30
%31 = bitcast %struct.addrinfo** %9 to %struct.sockaddr_in**
%32 = call i32 @getaddrinfo(i8* %0, i8* %21, %struct.sockaddr_in* %25, %struct.sockaddr_in** %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %20
%35 = load %struct.addrinfo*, %struct.addrinfo** %9
%36 = icmp eq %struct.addrinfo* %35, null
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = bitcast %struct.addrinfo* %35 to %struct.sockaddr_in*
%39 = call i32 @freeaddrinfo(%struct.sockaddr_in* %38)
br label %69
40: ; preds = %34
%41 = load i64, i64* @AF_INET
br label %46
42: ; preds = %20
%43 = load i32, i32* @stderr
%44 = call i8* @gai_strerror(i32 %32)
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %125
46: ; preds = %40, %61
%47 = phi i64 [ %62, %61 ], [ %41, %40 ]
%48 = phi %struct.addrinfo* [ %64, %61 ], [ %35, %40 ]
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 0
%50 = load i64, i64* %49
%51 = icmp eq i64 %50, %47
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 2
%54 = load i64, i64* %53
%55 = inttoptr i64 %54 to %struct.sockaddr_in*
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %55, i64 0, i32 1, i32 0
%57 = load i64, i64* %56
store i64 %57, i64* %17
br label %61
58: ; preds = %46
%59 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%60 = load i64, i64* @AF_INET
br label %61
61: ; preds = %52, %58
%62 = phi i64 [ %47, %52 ], [ %60, %58 ]
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 3
%64 = load %struct.addrinfo*, %struct.addrinfo** %63
%65 = icmp eq %struct.addrinfo* %64, null
br i1 %65, label %66, label %46
66: ; preds = %61
%67 = load %struct.sockaddr_in*, %struct.sockaddr_in** %31
%68 = call i32 @freeaddrinfo(%struct.sockaddr_in* %67)
br i1 %51, label %72, label %69
69: ; preds = %37, %66
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %125
72: ; preds = %66
br label %73
73: ; preds = %72, %5
%74 = call i64 @strlen(i8* dereferenceable(1) %2)
%75 = icmp slt i64 %74, 1
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %125
79: ; preds = %73
%80 = load i32, i32* @PF_INET
%81 = load i32, i32* @SOCK_STREAM
%82 = call i32 @socket(i32 %80, i32 %81, i32 0)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %125
87: ; preds = %79
%88 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%89 = call i32 @connect(i32 %82, %struct.sockaddr* %88, i32 48)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %109
91: ; preds = %87
%92 = load i64, i64* @errno
%93 = load i64, i64* @EINPROGRESS
%94 = icmp eq i64 %92, %93
br i1 %94, label %95, label %99
95: ; preds = %91
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%98 = load i64, i64* @errno
br label %99
99: ; preds = %95, %91
%100 = phi i64 [ %98, %95 ], [ %92, %91 ]
%101 = load i64, i64* @EALREADY
%102 = icmp eq i64 %100, %101
br i1 %102, label %103, label %106
103: ; preds = %99
%104 = load i32, i32* @stderr
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %106
106: ; preds = %103, %99
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %125
109: ; preds = %87
%110 = call i64 @strlen(i8* dereferenceable(1) %2)
%111 = add nsw i64 %110, 1
%112 = call i32 @send(i32 %82, i8* %2, i64 %111, i32 0)
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %109
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %125
117: ; preds = %109
%118 = call i32 @recv(i32 %82, i8* %3, i32 %4, i32 0)
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %117
%121 = load i32, i32* @stderr
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %125
123: ; preds = %117
%124 = call i32 @close(i32 %82)
br label %125
125: ; preds = %42, %69, %123, %120, %114, %106, %84, %76
%126 = phi i32 [ 0, %76 ], [ 0, %84 ], [ 0, %106 ], [ 0, %114 ], [ 0, %120 ], [ 1, %123 ], [ 0, %69 ], [ 0, %42 ]
ret i32 %126
}