#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 node_socket {
  int dummy;
};
struct addrinfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ connect;
struct node_socket *socket_from_addrinfo(struct addrinfo *const,
                                         int /*<<< orphan*/, char *,
                                         char const *const, int /*<<< orphan*/);
struct addrinfo *socket_get_addrinfo1(char const *const);
struct node_socket *node_socket_connect(const char *const addr_str) {
  struct addrinfo *const info = socket_get_addrinfo1(addr_str);
  if (!info)
    return NULL;
  return socket_from_addrinfo(info, connect, "connect", addr_str, 0);
}


x86 assembly (clang, -O0):
<node_socket_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <socket_get_addrinfo1@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1151 <node_socket_connect+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1175 <node_socket_connect+0x55>
mov    -0x18(%rbp),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe97(%rip),%rdx
xor    %r8d,%r8d
call   1040 <socket_from_addrinfo@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<node_socket_connect>:
push   %rbx
mov    %rdi,%rbx
call   1030 <socket_get_addrinfo1@plt>
test   %rax,%rax
je     114d <node_socket_connect+0x2d>
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%esi
lea    0xec2(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rcx
xor    %r8d,%r8d
pop    %rbx
jmp    1040 <socket_from_addrinfo@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.node_socket = type { i32 }
%struct.addrinfo = type { i32 }
@connect = global i32 0
@.str = [8 x i8] c"connect\00"
define %struct.node_socket* @node_socket_connect(i8* %0) {
%2 = alloca %struct.node_socket*
%3 = alloca i8*
%4 = alloca %struct.addrinfo*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call %struct.addrinfo* @socket_get_addrinfo1(i8* %5)
store %struct.addrinfo* %6, %struct.addrinfo** %4
%7 = load %struct.addrinfo*, %struct.addrinfo** %4
%8 = icmp ne %struct.addrinfo* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store %struct.node_socket* null, %struct.node_socket** %2
br label %15
10: ; preds = %1
%11 = load %struct.addrinfo*, %struct.addrinfo** %4
%12 = load i32, i32* @connect
%13 = load i8*, i8** %3
%14 = call %struct.node_socket* @socket_from_addrinfo(%struct.addrinfo* %11, i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %13, i32 0)
store %struct.node_socket* %14, %struct.node_socket** %2
br label %15
15: ; preds = %10, %9
%16 = load %struct.node_socket*, %struct.node_socket** %2
ret %struct.node_socket* %16
}

LLVM IR (-O2):
%struct.node_socket = type { i32 }
%struct.addrinfo = type { i32 }
@connect = global i32 0
@.str = [8 x i8] c"connect\00"
define %struct.node_socket* @node_socket_connect(i8* %0) {
%2 = tail call %struct.addrinfo* @socket_get_addrinfo1(i8* %0)
%3 = icmp eq %struct.addrinfo* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i32, i32* @connect
%6 = tail call %struct.node_socket* @socket_from_addrinfo(%struct.addrinfo* %2, i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i32 0)
br label %7
7: ; preds = %1, %4
%8 = phi %struct.node_socket* [ %6, %4 ], [ null, %1 ]
ret %struct.node_socket* %8
}