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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ memcpy(struct sockaddr *, int /*<<< orphan*/, int);
struct sockaddr *dn_to_sockaddr(char const *dn) {
  static struct sockaddr ret;
  struct addrinfo hints;
  struct addrinfo *results;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = 0;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  ;
  if (getaddrinfo(dn, NULL, &hints, &results) < 0) {
    return NULL;
  }
  memcpy(&ret, results->ai_addr, sizeof(struct sockaddr));
  freeaddrinfo(results);
  return &ret;
}


x86 assembly (clang, -O0):
<dn_to_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x28,%esi
call   1040 <bzero@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1050 <getaddrinfo@plt>
cmp    $0x0,%rax
jge    11aa <dn_to_sockaddr+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <dn_to_sockaddr+0x95>
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
lea    0x2e8d(%rip),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x40(%rbp),%rdi
call   1060 <freeaddrinfo@plt>
lea    0x2e73(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dn_to_sockaddr>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x28,%esi
call   1040 <bzero@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
xor    %ebx,%ebx
mov    %rsp,%rcx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <getaddrinfo@plt>
test   %rax,%rax
js     11b6 <dn_to_sockaddr+0x76>
mov    (%rsp),%rax
mov    (%rax),%esi
lea    0x2ea4(%rip),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    (%rsp),%rdi
call   1060 <freeaddrinfo@plt>
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, i64, i64, i64, i32 }
@dn_to_sockaddr.ret = internal global %struct.sockaddr zeroinitializer
@AF_INET = global i32 0
define %struct.sockaddr* @dn_to_sockaddr(i8* %0) {
%2 = alloca %struct.sockaddr*
%3 = alloca i8*
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
store i8* %0, i8** %3
%6 = call i32 @bzero(%struct.addrinfo* %4, i32 40)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 4
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 3
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 2
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 1
store i64 0, i64* %11
%12 = load i8*, i8** %3
%13 = call i64 @getaddrinfo(i8* %12, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %5)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store %struct.sockaddr* null, %struct.sockaddr** %2
br label %23
16: ; preds = %1
%17 = load %struct.addrinfo*, %struct.addrinfo** %5
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @memcpy(%struct.sockaddr* @dn_to_sockaddr.ret, i32 %19, i32 4)
%21 = load %struct.addrinfo*, %struct.addrinfo** %5
%22 = call i32 @freeaddrinfo(%struct.addrinfo* %21)
store %struct.sockaddr* @dn_to_sockaddr.ret, %struct.sockaddr** %2
br label %23
23: ; preds = %16, %15
%24 = load %struct.sockaddr*, %struct.sockaddr** %2
ret %struct.sockaddr* %24
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.addrinfo = type { i32, i64, i64, i64, i32 }
@dn_to_sockaddr.ret = internal global %struct.sockaddr zeroinitializer
@AF_INET = global i32 0
define %struct.sockaddr* @dn_to_sockaddr(i8* %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo* %2 to i8*
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = call i32 @bzero(%struct.addrinfo* %2, i32 40)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 4
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
%10 = bitcast i64* %9 to i8*
%11 = call i64 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %2, %struct.addrinfo** %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %1
%14 = load %struct.addrinfo*, %struct.addrinfo** %3
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @memcpy(%struct.sockaddr* @dn_to_sockaddr.ret, i32 %16, i32 4)
%18 = load %struct.addrinfo*, %struct.addrinfo** %3
%19 = call i32 @freeaddrinfo(%struct.addrinfo* %18)
br label %20
20: ; preds = %1, %13
%21 = phi %struct.sockaddr* [ @dn_to_sockaddr.ret, %13 ], [ null, %1 ]
ret %struct.sockaddr* %21
}