#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  char const *h_name;
};

/* Variables and functions */
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
char const *inet_ntoa(int /*<<< orphan*/);
const char *verifyhost(struct sockaddr_in *fromp) {
  struct hostent *hp;
  hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof(fromp->sin_addr),
                     fromp->sin_family);
  if (hp)
    return hp->h_name;
  else
    return inet_ntoa(fromp->sin_addr);
}


x86 assembly (clang, -O0):
<verifyhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    $0x4,%esi
call   1040 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1160 <verifyhost+0x40>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    116f <verifyhost+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verifyhost>:
push   %rbx
mov    %rdi,%rbx
mov    0x4(%rdi),%edx
mov    $0x4,%esi
call   1040 <gethostbyaddr@plt>
test   %rax,%rax
je     113b <verifyhost+0x1b>
mov    (%rax),%rax
pop    %rbx
ret
mov    (%rbx),%edi
pop    %rbx
jmp    1030 <inet_ntoa@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i8* }
define i8* @verifyhost(%struct.sockaddr_in* %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in*
%4 = alloca %struct.hostent*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
%5 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%7 = bitcast i32* %6 to i8*
%8 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%10 = load i32, i32* %9
%11 = call %struct.hostent* @gethostbyaddr(i8* %7, i32 4, i32 %10)
store %struct.hostent* %11, %struct.hostent** %4
%12 = load %struct.hostent*, %struct.hostent** %4
%13 = icmp ne %struct.hostent* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load %struct.hostent*, %struct.hostent** %4
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
store i8* %17, i8** %2
br label %23
18: ; preds = %1
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i8* @inet_ntoa(i32 %21)
store i8* %22, i8** %2
br label %23
23: ; preds = %18, %14
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i8* }
define i8* @verifyhost(%struct.sockaddr_in* %0) {
%2 = bitcast %struct.sockaddr_in* %0 to i8*
%3 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
%4 = load i32, i32* %3
%5 = tail call %struct.hostent* @gethostbyaddr(i8* %2, i32 4, i32 %4)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%9 = load i8*, i8** %8
br label %14
10: ; preds = %1
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i8* @inet_ntoa(i32 %12)
br label %14
14: ; preds = %10, %7
%15 = phi i8* [ %9, %7 ], [ %13, %10 ]
ret i8* %15
}