#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 */
typedef int /*<<< orphan*/ u_int;
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, void *, char *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
char *get_ip(char *host, char *ip, u_int ip_len) {
  struct hostent *hent;
  memset(ip, 0, ip_len);
  if ((hent = gethostbyname(host)) == NULL) {
    return (NULL);
  }
  if (inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, ip_len) == NULL) {
    return (NULL);
  }
  return ip;
}


x86 assembly (clang, -O0):
<get_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1175 <get_ip+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <get_ip+0x83>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    11ab <get_ip+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    11b3 <get_ip+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %r15d,%r15d
mov    %rsi,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbp,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     117e <get_ip+0x4e>
mov    0x2e87(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%rax
mov    (%rax),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
cmove  %rax,%rbx
mov    %rbx,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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