#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 */
typedef int /*<<< orphan*/ u_int32_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ h_addr;
};
struct ars_packet {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ars_set_error(struct ars_packet *, char *);
struct hostent *gethostbyname(char *);
scalar_t__ inet_aton(char *, TYPE_1__ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int ars_resolve(struct ars_packet *pkt, u_int32_t *dest, char *hostname) {
  struct sockaddr_in sa;
  if (inet_aton(hostname, &sa.sin_addr) == 0) {
    struct hostent *he;
    he = gethostbyname(hostname);
    if (he == NULL) {
      ars_set_error(pkt, "Can't resolve the hostname");
      return -1;
    }
    sa.sin_addr.s_addr = ((struct in_addr *)he->h_addr)->s_addr;
  }
  memcpy(dest, &sa.sin_addr.s_addr, sizeof(u_int32_t));
  return -0;
}


x86 assembly (clang, -O0):
<ars_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
jne    11ab <ars_resolve+0x6b>
mov    -0x20(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119f <ars_resolve+0x5f>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1030 <ars_set_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <ars_resolve+0x84>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ars_resolve>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rdx,%rdi
call   1060 <inet_aton@plt>
test   %rax,%rax
jne    117a <ars_resolve+0x3a>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1198 <ars_resolve+0x58>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe61(%rip),%rsi
mov    %r14,%rdi
call   1030 <ars_set_error@plt>
mov    $0xffffffff,%eax
jmp    118e <ars_resolve+0x4e>

LLVM IR (-O0):
%struct.ars_packet = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [27 x i8] c"Can't resolve the hostname\00"
define i32 @ars_resolve(%struct.ars_packet* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.ars_packet*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.hostent*
store %struct.ars_packet* %0, %struct.ars_packet** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%12 = call i64 @inet_aton(i8* %10, %struct.TYPE_2__* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %9
%17 = load %struct.hostent*, %struct.hostent** %9
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load %struct.ars_packet*, %struct.ars_packet** %5
%21 = call i32 @ars_set_error(%struct.ars_packet* %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %36
22: ; preds = %14
%23 = load %struct.hostent*, %struct.hostent** %9
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i64, i64* %24
%26 = inttoptr i64 %25 to %struct.in_addr*
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
br label %31
31: ; preds = %22, %3
%32 = load i32*, i32** %6
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = call i32 @memcpy(i32* %32, i32* %34, i32 4)
store i32 0, i32* %4
br label %36
36: ; preds = %31, %19
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.ars_packet = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [27 x i8] c"Can't resolve the hostname\00"
define i32 @ars_resolve(%struct.ars_packet* %0, i32* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%7 = call i64 @inet_aton(i8* %2, %struct.TYPE_2__* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %3
%10 = call %struct.hostent* @gethostbyname(i8* %2)
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @ars_set_error(%struct.ars_packet* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %24
14: ; preds = %9
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to %struct.in_addr*
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %17, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %19, i32* %20
br label %21
21: ; preds = %14, %3
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%23 = call i32 @memcpy(i32* %1, i32* %22, i32 4)
br label %24
24: ; preds = %12, %21
%25 = phi i32 [ 0, %21 ], [ -1, %12 ]
ret i32 %25
}