#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 h_length;
  void **h_addr_list;
};
typedef int /*<<< orphan*/ hostnamebuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char *);
char *hostnameFromAddress(char *, int, void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int getHostnameFromAddress() {
  struct hostent *hostent;
  void *addr;
  int addrlen;
  char hostnamebuf[100];
  char *result;
  hostent = gethostbyname("178.63.16.170");
  addr = hostent->h_addr_list[0];
  addrlen = hostent->h_length;
  result = hostnameFromAddress(hostnamebuf, sizeof(hostnamebuf), addr, addrlen,
                               AF_INET);
  if (result) {
    return 0;
  } else {
    printf("result: %s\n", result);
    return 1;
  }
}


x86 assembly (clang, -O0):
<getHostnameFromAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xebe(%rip),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    0x2e73(%rip),%rax
mov    (%rax),%r8d
mov    $0x64,%esi
call   1050 <hostnameFromAddress@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     11a3 <getHostnameFromAddress+0x73>
movl   $0x0,-0x4(%rbp)
jmp    11bd <getHostnameFromAddress+0x8d>
mov    -0x88(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHostnameFromAddress>:
sub    $0x68,%rsp
lea    0xec5(%rip),%rdi
call   1040 <gethostbyname@plt>
mov    0x8(%rax),%rcx
mov    (%rcx),%rdx
mov    (%rax),%ecx
mov    0x2e98(%rip),%rax
mov    (%rax),%r8d
mov    %rsp,%rdi
mov    $0x64,%esi
call   1050 <hostnameFromAddress@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     116f <getHostnameFromAddress+0x3f>
add    $0x68,%rsp
ret
lea    0xe98(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i8** }
@.str = [14 x i8] c"178.63.16.170\00"
@AF_INET = global i32 0
@.str.1 = [12 x i8] c"result: %s\0A\00"
define i32 @getHostnameFromAddress() {
%1 = alloca i32
%2 = alloca %struct.hostent*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i8*
%7 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %7, %struct.hostent** %2
%8 = load %struct.hostent*, %struct.hostent** %2
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i32 0, i32 1
%10 = load i8**, i8*** %9
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
store i8* %12, i8** %3
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %4
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = load i32, i32* @AF_INET
%20 = call i8* @hostnameFromAddress(i8* %16, i32 100, i8* %17, i32 %18, i32 %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %0
store i32 0, i32* %1
br label %27
24: ; preds = %0
%25 = load i8*, i8** %6
%26 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 1, i32* %1
br label %27
27: ; preds = %24, %23
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
%struct.hostent = type { i32, i8** }
@.str = [14 x i8] c"178.63.16.170\00"
@AF_INET = global i32 0
@.str.1 = [12 x i8] c"result: %s\0A\00"
define i32 @getHostnameFromAddress() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%5 = load i8**, i8*** %4
%6 = load i8*, i8** %5
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @AF_INET
%10 = call i8* @hostnameFromAddress(i8* %2, i32 100, i8* %6, i32 %8, i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %14
14: ; preds = %0, %12
%15 = phi i32 [ 1, %12 ], [ 0, %0 ]
ret i32 %15
}