#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 {
  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);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
char *get_ip(char *host) {
  struct hostent *hent;
  int iplen = 15;
  char *ip = (char *)malloc(iplen + 1);
  memset(ip, 0, iplen + 1);
  if ((hent = gethostbyname(host)) == NULL) {
    perror("can not get ip");
  }
  if (inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL) {
    perror("can not reslove host");
  }
  return ip;
}


x86 assembly (clang, -O0):
<get_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xf,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a6 <get_ip+0x56>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    11db <get_ip+0x8b>
lea    0xe39(%rip),%rdi
call   1070 <perror@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11af <get_ip+0x5f>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rax
mov    (%rax),%rsi
mov    %r14,%rdx
mov    $0xf,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     11bd <get_ip+0x6d>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4a(%rip),%rdi
call   1070 <perror@plt>
jmp    1183 <get_ip+0x33>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
jmp    11a4 <get_ip+0x54>

LLVM IR (-O0):
%struct.hostent = type { i64* }
@.str = [15 x i8] c"can not get ip\00"
@AF_INET = global i32 0
@.str.1 = [21 x i8] c"can not reslove host\00"
define i8* @get_ip(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hostent*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 15, i32* %4
%6 = load i32, i32* %4
%7 = add nsw i32 %6, 1
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = call i32 @memset(i8* %10, i32 0, i32 %12)
%14 = load i8*, i8** %2
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %3
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %1
%20 = load i32, i32* @AF_INET
%21 = load %struct.hostent*, %struct.hostent** %3
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i64*, i64** %22
%24 = getelementptr inbounds i64, i64* %23, i64 0
%25 = load i64, i64* %24
%26 = inttoptr i64 %25 to i8*
%27 = load i8*, i8** %5
%28 = load i32, i32* %4
%29 = call i32* @inet_ntop(i32 %20, i8* %26, i8* %27, i32 %28)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
@.str = [15 x i8] c"can not get ip\00"
@AF_INET = global i32 0
@.str.1 = [21 x i8] c"can not reslove host\00"
define i8* @get_ip(i8* %0) {
%2 = tail call i64 @malloc(i32 16)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @memset(i8* %3, i32 0, i32 16)
%5 = tail call %struct.hostent* @gethostbyname(i8* %0)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%12 = load i64*, i64** %11
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32* @inet_ntop(i32 %10, i8* %14, i8* %3, i32 15)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %9
ret i8* %3
}