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

/* Variables and functions */
struct hostent *gethostbyname(char const *);
scalar_t__ inet_ntoa(struct in_addr);
char *LookupHostIP(const char *Host) {
  struct hostent *hostdata;
  hostdata = gethostbyname(Host);
  if (!hostdata) {
    return (NULL);
  }
  return ((char *)inet_ntoa(*(struct in_addr *)*hostdata->h_addr_list));
}


x86 assembly (clang, -O0):
<LookupHostIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1151 <LookupHostIP+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1166 <LookupHostIP+0x46>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LookupHostIP>:
push   %rax
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     113a <LookupHostIP+0x1a>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define i8* @LookupHostIP(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.hostent*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call %struct.hostent* @gethostbyname(i8* %5)
store %struct.hostent* %6, %struct.hostent** %4
%7 = load %struct.hostent*, %struct.hostent** %4
%8 = icmp ne %struct.hostent* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i8* null, i8** %2
br label %20
10: ; preds = %1
%11 = load %struct.hostent*, %struct.hostent** %4
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i32 0, i32 0
%13 = load i64*, i64** %12
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to %struct.in_addr*
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @inet_ntoa(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %2
br label %20
20: ; preds = %10, %9
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define i8* @LookupHostIP(i8* %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* %0)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%6 = load i64*, i64** %5
%7 = load i64, i64* %6
%8 = inttoptr i64 %7 to %struct.in_addr*
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @inet_ntoa(i32 %10)
%12 = inttoptr i64 %11 to i8*
br label %13
13: ; preds = %1, %4
%14 = phi i8* [ %12, %4 ], [ null, %1 ]
ret i8* %14
}