#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *getUserInput(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ perror(char *);
struct hostent *getDestination(void) {
  char *userAddr = getUserInput("Enter the destination address: ");
  struct hostent *addr = gethostbyname(userAddr);
  if (addr == NULL) {
    perror("gethostbyname");
    exit(EXIT_FAILURE);
  }
  free(userAddr);
  return addr;
}


x86 assembly (clang, -O0):
<getDestination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1050 <getUserInput@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <getDestination+0x4a>
lea    0xe99(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDestination>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1050 <getUserInput@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1186 <getDestination+0x36>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe93(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@.str = [32 x i8] c"Enter the destination address: \00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@EXIT_FAILURE = global i32 0
define %struct.hostent* @getDestination() {
%1 = alloca i8*
%2 = alloca %struct.hostent*
%3 = call i8* @getUserInput(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call %struct.hostent* @gethostbyname(i8* %4)
store %struct.hostent* %5, %struct.hostent** %2
%6 = load %struct.hostent*, %struct.hostent** %2
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i32 @free(i8* %13)
%15 = load %struct.hostent*, %struct.hostent** %2
ret %struct.hostent* %15
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@.str = [32 x i8] c"Enter the destination address: \00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@EXIT_FAILURE = global i32 0
define %struct.hostent* @getDestination() {
%1 = tail call i8* @getUserInput(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%2 = tail call %struct.hostent* @gethostbyname(i8* %1)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = tail call i32 @free(i8* %1)
ret %struct.hostent* %2
}