#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 hostent {
  int **h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
char *getDNSToIP(char *HOST, char *host_name) {
  struct hostent *host_entry;
  host_entry = gethostbyname(host_name);
  if (host_entry != 0) {
    sprintf(HOST, "%d.%d.%d.%d", (host_entry->h_addr_list[0][0] & 0x00ff),
            (host_entry->h_addr_list[0][1] & 0x00ff),
            (host_entry->h_addr_list[0][2] & 0x00ff),
            (host_entry->h_addr_list[0][3] & 0x00ff));
  }
  return HOST;
}


x86 assembly (clang, -O0):
<getDNSToIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a7 <getDNSToIP+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edx
and    $0xff,%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x4(%rax),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x8(%rax),%r8d
and    $0xff,%r8d
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0xc(%rax),%r9d
and    $0xff,%r9d
lea    0xe5e(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDNSToIP>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1157 <getDNSToIP+0x37>
mov    (%rax),%rax
mov    (%rax),%rax
movzbl (%rax),%edx
movzbl 0x4(%rax),%ecx
movzbl 0x8(%rax),%r8d
movzbl 0xc(%rax),%r9d
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i32** }
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @getDNSToIP(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.hostent*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %5
%8 = load %struct.hostent*, %struct.hostent** %5
%9 = icmp ne %struct.hostent* %8, null
br i1 %9, label %10, label %45
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load %struct.hostent*, %struct.hostent** %5
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i32 0, i32 0
%14 = load i32**, i32*** %13
%15 = getelementptr inbounds i32*, i32** %14, i64 0
%16 = load i32*, i32** %15
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = and i32 %18, 255
%20 = load %struct.hostent*, %struct.hostent** %5
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 0
%22 = load i32**, i32*** %21
%23 = getelementptr inbounds i32*, i32** %22, i64 0
%24 = load i32*, i32** %23
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = and i32 %26, 255
%28 = load %struct.hostent*, %struct.hostent** %5
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 0
%30 = load i32**, i32*** %29
%31 = getelementptr inbounds i32*, i32** %30, i64 0
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32, i32* %32, i64 2
%34 = load i32, i32* %33
%35 = and i32 %34, 255
%36 = load %struct.hostent*, %struct.hostent** %5
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 0
%38 = load i32**, i32*** %37
%39 = getelementptr inbounds i32*, i32** %38, i64 0
%40 = load i32*, i32** %39
%41 = getelementptr inbounds i32, i32* %40, i64 3
%42 = load i32, i32* %41
%43 = and i32 %42, 255
%44 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %27, i32 %35, i32 %43)
br label %45
45: ; preds = %10, %2
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
%struct.hostent = type { i32** }
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @getDNSToIP(i8* returned writeonly %0, i8* %1) {
%3 = tail call %struct.hostent* @gethostbyname(i8* %1)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%7 = load i32**, i32*** %6
%8 = load i32*, i32** %7
%9 = load i32, i32* %8
%10 = and i32 %9, 255
%11 = getelementptr inbounds i32, i32* %8, i64 1
%12 = load i32, i32* %11
%13 = and i32 %12, 255
%14 = getelementptr inbounds i32, i32* %8, i64 2
%15 = load i32, i32* %14
%16 = and i32 %15, 255
%17 = getelementptr inbounds i32, i32* %8, i64 3
%18 = load i32, i32* %17
%19 = and i32 %18, 255
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %16, i32 %19)
br label %21
21: ; preds = %5, %2
ret i8* %0
}