#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ itoa(int);
int /*<<< orphan*/ log_write(char *, char *, int /*<<< orphan*/, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(struct sockaddr *, int /*<<< orphan*/, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
struct sockaddr *getip(const char *domainName) {
  struct addrinfo *info, *temp;
  int ret, sockfd;
  struct sockaddr *saddr;
  int optval = 1;
  if ((ret = getaddrinfo(domainName, itoa(6543), NULL, &info)) != 0) {
    log_write("Communication Process", gai_strerror(ret), NULL);
    return NULL;
  }
  log_write("Communication Process",
            "Domain Name resolved. Testing returned addresses.", NULL);
  for (temp = info; temp != NULL; temp = temp->ai_next) {
    if ((sockfd = socket(temp->ai_family, temp->ai_socktype,
                         temp->ai_protocol)) < 0) {
      log_write("Communication Process", strerror(errno), NULL);
      continue;
    }
    if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) <
        0)
      log_write("Communication Process",
                "Couldn't set socket to re-use address.", NULL);
    else
      log_write("Communication Process",
                "Socket set to re-use address successfully.", NULL);
    if (connect(sockfd, temp->ai_addr, temp->ai_addrlen) < 0) {
      log_write("Communication Process", strerror(errno), NULL);
      close(sockfd);
      continue;
    }
    close(sockfd);
    break;
  }
  if (temp == NULL) {
    log_write("Communication Process", "No valid return addresses were found.",
              NULL);
    return NULL;
  }
  saddr = (struct sockaddr *)malloc(sizeof(struct sockaddr));
  memcpy(saddr, temp->ai_addr, sizeof(struct sockaddr));
  freeaddrinfo(info);
  log_write("Communication Process", "A valid address is found: ",
            inet_ntoa(((struct sockaddr_in *)saddr)->sin_addr), " .", NULL);
  return saddr;
}


x86 assembly (clang, -O0):
<getip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x198f,%edi
call   10b0 <itoa@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     123c <getip+0x6c>
mov    -0x24(%rbp),%edi
call   1050 <gai_strerror@plt>
movslq %eax,%rsi
lea    0xdda(%rip),%rdi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    140e <getip+0x23e>
lea    0xdbd(%rip),%rdi
lea    0xdcc(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     137e <getip+0x1ae>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    12b2 <getip+0xe2>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
movslq %eax,%rsi
lea    0xd5c(%rip),%rdi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
jmp    136d <getip+0x19d>
mov    -0x28(%rbp),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
mov    0x2d0b(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12fc <getip+0x12c>
lea    0xd19(%rip),%rdi
lea    0xd5a(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
jmp    1313 <getip+0x143>
lea    0xcfd(%rip),%rdi
lea    0xd65(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1360 <getip+0x190>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
movslq %eax,%rsi
lea    0xcb6(%rip),%rdi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
mov    -0x28(%rbp),%edi
call   1060 <close@plt>
jmp    136d <getip+0x19d>
mov    -0x28(%rbp),%edi
call   1060 <close@plt>
jmp    137e <getip+0x1ae>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    125b <getip+0x8b>
cmpq   $0x0,-0x20(%rbp)
jne    13ad <getip+0x1dd>
lea    0xc70(%rip),%rdi
lea    0xd03(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1090 <log_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    140e <getip+0x23e>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%edx
lea    0xc14(%rip),%rdi
lea    0xccd(%rip),%rsi
lea    0xce1(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1090 <log_write@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movl   $0x1,0xc(%rsp)
mov    $0x198f,%edi
call   10b0 <itoa@plt>
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     121e <getip+0x4e>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
movslq %eax,%rsi
lea    0xde7(%rip),%rdi
jmp    1326 <getip+0x156>
lea    0xddb(%rip),%rdi
lea    0xdea(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <log_write@plt>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     1318 <getip+0x148>
mov    0x2d8e(%rip),%r12
lea    0xdaf(%rip),%r15
lea    0xdf0(%rip),%r13
lea    0xe10(%rip),%r14
jmp    1295 <getip+0xc5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
call   10d0 <strerror@plt>
movslq %eax,%rsi
mov    %r15,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <log_write@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1318 <getip+0x148>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10f0 <socket@plt>
test   %eax,%eax
js     1270 <getip+0xa0>
mov    %eax,%ebp
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
mov    0x2d17(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
mov    %r14,%rsi
cmovs  %r13,%rsi
mov    %r15,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <log_write@plt>
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    %ebp,%edi
call   10a0 <connect@plt>
test   %rax,%rax
jns    1343 <getip+0x173>
mov    (%r12),%edi
call   10d0 <strerror@plt>
movslq %eax,%rsi
mov    %r15,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <log_write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1288 <getip+0xb8>
lea    0xce1(%rip),%rdi
lea    0xd74(%rip),%rsi
xor    %ebp,%ebp
xor    %edx,%edx
xor    %eax,%eax
call   1090 <log_write@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    (%rbx),%esi
mov    %rax,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    0x10(%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x0(%rbp),%edi
call   1040 <inet_ntoa@plt>
lea    0xc81(%rip),%rdi
lea    0xd3a(%rip),%rsi
lea    0xd4e(%rip),%rcx
mov    %eax,%edx
xor    %r8d,%r8d
xor    %eax,%eax
call   1090 <log_write@plt>
jmp    1331 <getip+0x161>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr_in = type { i32 }
@.str = [22 x i8] c"Communication Process\00"
@.str.1 = [50 x i8] c"Domain Name resolved. Testing returned addresses.\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [39 x i8] c"Couldn't set socket to re-use address.\00"
@.str.3 = [43 x i8] c"Socket set to re-use address successfully.\00"
@.str.4 = [38 x i8] c"No valid return addresses were found.\00"
@.str.5 = [27 x i8] c"A valid address is found: \00"
@.str.6 = [3 x i8] c" .\00"
define %struct.sockaddr* @getip(i8* %0) {
%2 = alloca %struct.sockaddr*
%3 = alloca i8*
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr*
%9 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %9
%10 = load i8*, i8** %3
%11 = call i32 @itoa(i32 6543)
%12 = call i32 @getaddrinfo(i8* %10, i32 %11, i32* null, %struct.addrinfo** %4)
store i32 %12, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i32, i32* %6
%16 = call i32 @gai_strerror(i32 %15)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18, i32 0)
store %struct.sockaddr* null, %struct.sockaddr** %2
br label %101
20: ; preds = %1
%21 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 0)
%22 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %22, %struct.addrinfo** %5
br label %23
23: ; preds = %75, %20
%24 = load %struct.addrinfo*, %struct.addrinfo** %5
%25 = icmp ne %struct.addrinfo* %24, null
br i1 %25, label %26, label %79
26: ; preds = %23
%27 = load %struct.addrinfo*, %struct.addrinfo** %5
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 4
%29 = load i32, i32* %28
%30 = load %struct.addrinfo*, %struct.addrinfo** %5
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 3
%32 = load i32, i32* %31
%33 = load %struct.addrinfo*, %struct.addrinfo** %5
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 @socket(i32 %29, i32 %32, i32 %35)
store i32 %36, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %26
%39 = load i32, i32* @errno
%40 = call i32 @strerror(i32 %39)
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i8*
%43 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %42, i32 0)
br label %75
44: ; preds = %26
%45 = load i32, i32* %7
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_REUSEADDR
%48 = call i64 @setsockopt(i32 %45, i32 %46, i32 %47, i32* %9, i32 4)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %54
52: ; preds = %44
%53 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %54
54: ; preds = %52, %50
%55 = load i32, i32* %7
%56 = load %struct.addrinfo*, %struct.addrinfo** %5
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load %struct.addrinfo*, %struct.addrinfo** %5
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = call i64 @connect(i32 %55, i32 %58, i32 %61)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %54
%65 = load i32, i32* @errno
%66 = call i32 @strerror(i32 %65)
%67 = sext i32 %66 to i64
%68 = inttoptr i64 %67 to i8*
%69 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %68, i32 0)
%70 = load i32, i32* %7
%71 = call i32 @close(i32 %70)
br label %75
72: ; preds = %54
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
br label %79
75: ; preds = %64, %38
%76 = load %struct.addrinfo*, %struct.addrinfo** %5
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 5
%78 = load %struct.addrinfo*, %struct.addrinfo** %77
store %struct.addrinfo* %78, %struct.addrinfo** %5
br label %23
79: ; preds = %72, %23
%80 = load %struct.addrinfo*, %struct.addrinfo** %5
%81 = icmp eq %struct.addrinfo* %80, null
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 0)
store %struct.sockaddr* null, %struct.sockaddr** %2
br label %101
84: ; preds = %79
%85 = call i64 @malloc(i32 4)
%86 = inttoptr i64 %85 to %struct.sockaddr*
store %struct.sockaddr* %86, %struct.sockaddr** %8
%87 = load %struct.sockaddr*, %struct.sockaddr** %8
%88 = load %struct.addrinfo*, %struct.addrinfo** %5
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = call i32 @memcpy(%struct.sockaddr* %87, i32 %90, i32 4)
%92 = load %struct.addrinfo*, %struct.addrinfo** %4
%93 = call i32 @freeaddrinfo(%struct.addrinfo* %92)
%94 = load %struct.sockaddr*, %struct.sockaddr** %8
%95 = bitcast %struct.sockaddr* %94 to %struct.sockaddr_in*
%96 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %95, i32 0, i32 0
%97 = load i32, i32* %96
%98 = call i32 @inet_ntoa(i32 %97)
%99 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %98, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* null)
%100 = load %struct.sockaddr*, %struct.sockaddr** %8
store %struct.sockaddr* %100, %struct.sockaddr** %2
br label %101
101: ; preds = %84, %82, %14
%102 = load %struct.sockaddr*, %struct.sockaddr** %2
ret %struct.sockaddr* %102
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr_in = type { i32 }
@.str = [22 x i8] c"Communication Process\00"
@.str.1 = [50 x i8] c"Domain Name resolved. Testing returned addresses.\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [39 x i8] c"Couldn't set socket to re-use address.\00"
@.str.3 = [43 x i8] c"Socket set to re-use address successfully.\00"
@.str.4 = [38 x i8] c"No valid return addresses were found.\00"
@.str.5 = [27 x i8] c"A valid address is found: \00"
@.str.6 = [3 x i8] c" .\00"
define %struct.sockaddr* @getip(i8* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i32
%4 = bitcast %struct.addrinfo** %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%6 = tail call i32 @itoa(i32 6543)
%7 = call i32 @getaddrinfo(i8* %0, i32 %6, i32* null, %struct.addrinfo** %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = call i32 @gai_strerror(i32 %7)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
%13 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %12, i32 0)
br label %74
14: ; preds = %1
%15 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 0)
%16 = load %struct.addrinfo*, %struct.addrinfo** %2
%17 = icmp eq %struct.addrinfo* %16, null
br i1 %17, label %58, label %18
18: ; preds = %14, %54
%19 = phi %struct.addrinfo* [ %56, %54 ], [ %16, %14 ]
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 2
%25 = load i32, i32* %24
%26 = call i32 @socket(i32 %21, i32 %23, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %18
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
%33 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %32, i32 0)
br label %54
34: ; preds = %18
%35 = load i32, i32* @SOL_SOCKET
%36 = load i32, i32* @SO_REUSEADDR
%37 = call i64 @setsockopt(i32 %26, i32 %35, i32 %36, i32* %3, i32 4)
%38 = icmp slt i64 %37, 0
%39 = select i1 %38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0)
%40 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %39, i32 0)
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 1
%44 = load i32, i32* %43
%45 = call i64 @connect(i32 %26, i32 %42, i32 %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %60
47: ; preds = %34
%48 = load i32, i32* @errno
%49 = call i32 @strerror(i32 %48)
%50 = sext i32 %49 to i64
%51 = inttoptr i64 %50 to i8*
%52 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %51, i32 0)
%53 = call i32 @close(i32 %26)
br label %54
54: ; preds = %47, %28
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 5
%56 = load %struct.addrinfo*, %struct.addrinfo** %55
%57 = icmp eq %struct.addrinfo* %56, null
br i1 %57, label %58, label %18
58: ; preds = %54, %14
%59 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 0)
br label %74
60: ; preds = %34
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 0
%62 = call i32 @close(i32 %26)
%63 = call i64 @malloc(i32 4)
%64 = inttoptr i64 %63 to %struct.sockaddr*
%65 = load i32, i32* %61
%66 = call i32 @memcpy(%struct.sockaddr* %64, i32 %65, i32 4)
%67 = load %struct.addrinfo*, %struct.addrinfo** %2
%68 = call i32 @freeaddrinfo(%struct.addrinfo* %67)
%69 = inttoptr i64 %63 to %struct.sockaddr_in*
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %69, i64 0, i32 0
%71 = load i32, i32* %70
%72 = call i32 @inet_ntoa(i32 %71)
%73 = call i32 (i8*, i8*, i32, ...) @log_write(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* null)
br label %74
74: ; preds = %60, %58, %9
%75 = phi %struct.sockaddr* [ null, %9 ], [ null, %58 ], [ %64, %60 ]
ret %struct.sockaddr* %75
}