#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);
int /*<<< orphan*/ perror(char *);
char *get_ip(char *host) {
  struct hostent *hent;
  static char ip[15 + 1];
  if ((hent = gethostbyname(host)) == NULL) {
    herror("Can't get IP");
    exit(3);
  }
  if (inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, 15) == NULL) {
    perror("Can't resolve host");
    exit(4);
  }
  return ip;
}


x86 assembly (clang, -O0):
<get_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1189 <get_ip+0x39>
lea    0xe86(%rip),%rdi
call   1050 <herror@plt>
mov    $0x3,%edi
call   1070 <exit@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rsi
lea    0x2ebd(%rip),%rdx
mov    $0xf,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    11cd <get_ip+0x7d>
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
lea    0x2e8c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip>:
push   %rax
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1189 <get_ip+0x39>
mov    0x2e86(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%rax
mov    (%rax),%rsi
lea    0x2eef(%rip),%rdx
mov    $0xf,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     119f <get_ip+0x4f>
lea    0x2ed9(%rip),%rax
pop    %rcx
ret
lea    0xe70(%rip),%rdi
call   1050 <herror@plt>
mov    $0x3,%edi
call   1070 <exit@plt>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
mov    $0x4,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
@get_ip.ip = internal global [16 x i8] zeroinitializer
@.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*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call %struct.hostent* @gethostbyname(i8* %4)
store %struct.hostent* %5, %struct.hostent** %3
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @herror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 3)
unreachable
10: ; preds = %1
%11 = load i32, i32* @AF_INET
%12 = load %struct.hostent*, %struct.hostent** %3
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i32 0, i32 0
%14 = load i64*, i64** %13
%15 = getelementptr inbounds i64, i64* %14, i64 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i8*
%18 = call i32* @inet_ntop(i32 %11, i8* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @get_ip.ip, i64 0, i64 0), i32 15)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 4)
unreachable
23: ; preds = %10
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @get_ip.ip, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
@get_ip.ip = internal global [16 x i8] zeroinitializer
@.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 %struct.hostent* @gethostbyname(i8* %0)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @herror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 3)
unreachable
7: ; preds = %1
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, 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* getelementptr inbounds ([16 x i8], [16 x i8]* @get_ip.ip, i64 0, i64 0), i32 15)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 4)
unreachable
18: ; preds = %7
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @get_ip.ip, i64 0, i64 0)
}