#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 /*<<< orphan*/ *h_addr_list;
  int /*<<< orphan*/ h_addrtype;
};

/* Variables and functions */
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
scalar_t__ malloc(int);
char *gethostip(const char *hostname) {
  struct hostent *h = NULL;
  char *buf = (char *)malloc(100);
  h = gethostbyname(hostname);
  if (h == NULL) {
    return NULL;
  } else {
    inet_ntop(h->h_addrtype, *h->h_addr_list, buf, 100);
    return buf;
  }
}


x86 assembly (clang, -O0):
<gethostip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <gethostip+0x47>
movq   $0x0,-0x8(%rbp)
jmp    119d <gethostip+0x6d>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostip>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1168 <gethostip+0x38>
mov    0x8(%rax),%edi
mov    (%rax),%rax
mov    (%rax),%esi
mov    %r14,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
jmp    116b <gethostip+0x3b>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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