#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int openClientDataSocket(struct addrinfo *client_ai) {
  int sockConnect;
  0 && fprintf(stdout, "Entering openClientDataSocket\n");
  if ((sockConnect = socket(client_ai->ai_family, client_ai->ai_socktype,
                            client_ai->ai_protocol)) == -1) {
    fprintf(stderr, "socket: %s\n", strerror(errno));
    return (0);
  }
  if ((connect(sockConnect, client_ai->ai_addr, client_ai->ai_addrlen)) == -1) {
    fprintf(stderr, "connect: %s\n", strerror(errno));
    return (0);
  }
  0 && fprintf(stdout, "Exiting openClientDataSocket\n");
  return (sockConnect);
}


x86 assembly (clang, -O0):
<openClientDataSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ac <openClientDataSocket+0x6c>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120a <openClientDataSocket+0xca>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <connect@plt>
cmp    $0xffffffff,%eax
jne    1204 <openClientDataSocket+0xc4>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120a <openClientDataSocket+0xca>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openClientDataSocket>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x10(%rdi),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   1060 <socket@plt>
cmp    $0xffffffff,%eax
je     1176 <openClientDataSocket+0x36>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1040 <connect@plt>
cmp    $0xffffffff,%eax
jne    11a5 <openClientDataSocket+0x65>
lea    0xe98(%rip),%r14
jmp    117d <openClientDataSocket+0x3d>
lea    0xe83(%rip),%r14
mov    0x2e5c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"connect: %s\0A\00"
@stdout = global i32 0
define i32 @openClientDataSocket(%struct.addrinfo* %0) {
%2 = alloca i32
%3 = alloca %struct.addrinfo*
%4 = alloca i32
store %struct.addrinfo* %0, %struct.addrinfo** %3
%5 = load %struct.addrinfo*, %struct.addrinfo** %3
%6 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 4
%7 = load i32, i32* %6
%8 = load %struct.addrinfo*, %struct.addrinfo** %3
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
%10 = load i32, i32* %9
%11 = load %struct.addrinfo*, %struct.addrinfo** %3
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 2
%13 = load i32, i32* %12
%14 = call i32 @socket(i32 %7, i32 %10, i32 %13)
store i32 %14, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i64 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 0, i32* %2
br label %38
21: ; preds = %1
%22 = load i32, i32* %4
%23 = load %struct.addrinfo*, %struct.addrinfo** %3
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load %struct.addrinfo*, %struct.addrinfo** %3
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @connect(i32 %22, i32 %25, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i64 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %34)
store i32 0, i32* %2
br label %38
36: ; preds = %21
%37 = load i32, i32* %4
store i32 %37, i32* %2
br label %38
38: ; preds = %36, %31, %16
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"connect: %s\0A\00"
@stdout = global i32 0
define i32 @openClientDataSocket(%struct.addrinfo* nocapture %0) {
%2 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 4
%3 = load i32, i32* %2
%4 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 3
%5 = load i32, i32* %4
%6 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 2
%7 = load i32, i32* %6
%8 = tail call i32 @socket(i32 %3, i32 %5, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i32 @connect(i32 %8, i32 %12, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %10, %1
%18 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %10 ]
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i64 (i32, i8*, ...) @fprintf(i32 %19, i8* %18, i8* %21)
br label %23
23: ; preds = %17, %10
%24 = phi i32 [ %8, %10 ], [ 0, %17 ]
ret i32 %24
}