#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;
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(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) {
    herror("Can't get IP");
    exit(1);
  }
  if (inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL) {
    perror("Can't resolve host");
    exit(1);
  }
  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    11d0 <get_ip+0x60>
lea    0xe3f(%rip),%rdi
call   1070 <herror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e11(%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    120f <get_ip+0x9f>
lea    0xe0d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@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,%r14
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11cc <get_ip+0x5c>
mov    0x2e41(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%rax
mov    (%rax),%rsi
mov    %rbx,%rdx
mov    $0xf,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     11e2 <get_ip+0x72>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2d(%rip),%rdi
call   1070 <herror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe24(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
@.str = [13 x i8] c"Can't get IP\00"
@AF_INET = global i32 0
@.str.1 = [19 x i8] c"Can't resolve 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 %20
17: ; preds = %1
%18 = call i32 @herror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
%21 = load i32, i32* @AF_INET
%22 = load %struct.hostent*, %struct.hostent** %3
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i64*, i64** %23
%25 = getelementptr inbounds i64, i64* %24, i64 0
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to i8*
%28 = load i8*, i8** %5
%29 = load i32, i32* %4
%30 = call i32* @inet_ntop(i32 %21, i8* %27, i8* %28, i32 %29)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %20
%36 = load i8*, i8** %5
ret i8* %36
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
@.str = [13 x i8] c"Can't get IP\00"
@AF_INET = global i32 0
@.str.1 = [19 x i8] c"Can't resolve 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 %10
7: ; preds = %1
%8 = tail call i32 @herror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%13 = load i64*, i64** %12
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32* @inet_ntop(i32 %11, i8* %15, i8* %3, i32 15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
ret i8* %3
}