#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_int32_t;
struct hostent {
  char *h_name;
};
typedef int int32_t;
typedef int /*<<< orphan*/ a;
struct TYPE_2__ {
  int options;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int RES_AAONLY;
int RES_DEFNAMES;
int RES_DNSRCH;
TYPE_1__ _res;
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
char *intoa(int /*<<< orphan*/);
char *gethname(u_int32_t a) {
  int32_t options;
  struct hostent *hp;
  options = _res.options;
  _res.options |= RES_AAONLY;
  _res.options &= ~(RES_DEFNAMES | RES_DNSRCH);
  hp = gethostbyaddr((char *)&a, sizeof(a), AF_INET);
  _res.options = options;
  if (hp == NULL)
    return (intoa(a));
  return (hp->h_name);
}


x86 assembly (clang, -O0):
<gethname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
mov    0x2ea1(%rip),%rax
or     (%rax),%ecx
mov    0x2e98(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
mov    0x2e66(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    0x2e7a(%rip),%rax
and    (%rax),%ecx
mov    0x2e71(%rip),%rax
mov    %ecx,(%rax)
lea    -0xc(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%ecx
mov    0x2e4a(%rip),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <gethname+0x9c>
mov    -0xc(%rbp),%edi
call   1030 <intoa@plt>
mov    %rax,-0x8(%rbp)
jmp    11c7 <gethname+0xa7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethname>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,0x4(%rsp)
mov    0x2eba(%rip),%rbx
mov    (%rbx),%ebp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
or     %ebp,%eax
mov    0x2e7e(%rip),%rcx
mov    0x2e7f(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
not    %edx
and    %eax,%edx
mov    %edx,(%rbx)
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
call   1040 <gethostbyaddr@plt>
mov    %ebp,(%rbx)
test   %rax,%rax
je     1177 <gethname+0x57>
mov    (%rax),%rax
jmp    1180 <gethname+0x60>
mov    0x4(%rsp),%edi
call   1030 <intoa@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8* }
@_res = global %struct.TYPE_2__ zeroinitializer
@RES_AAONLY = global i32 0
@RES_DEFNAMES = global i32 0
@RES_DNSRCH = global i32 0
@AF_INET = global i32 0
define i8* @gethname(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.hostent*
store i32 %0, i32* %3
%6 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
store i32 %6, i32* %4
%7 = load i32, i32* @RES_AAONLY
%8 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
%9 = or i32 %8, %7
store i32 %9, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
%10 = load i32, i32* @RES_DEFNAMES
%11 = load i32, i32* @RES_DNSRCH
%12 = or i32 %10, %11
%13 = xor i32 %12, -1
%14 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
%15 = and i32 %14, %13
store i32 %15, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
%16 = bitcast i32* %3 to i8*
%17 = load i32, i32* @AF_INET
%18 = call %struct.hostent* @gethostbyaddr(i8* %16, i32 4, i32 %17)
store %struct.hostent* %18, %struct.hostent** %5
%19 = load i32, i32* %4
store i32 %19, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
%20 = load %struct.hostent*, %struct.hostent** %5
%21 = icmp eq %struct.hostent* %20, null
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i32, i32* %3
%24 = call i8* @intoa(i32 %23)
store i8* %24, i8** %2
br label %29
25: ; preds = %1
%26 = load %struct.hostent*, %struct.hostent** %5
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
store i8* %28, i8** %2
br label %29
29: ; preds = %25, %22
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8* }
@_res = global %struct.TYPE_2__ zeroinitializer
@RES_AAONLY = global i32 0
@RES_DEFNAMES = global i32 0
@RES_DNSRCH = global i32 0
@AF_INET = global i32 0
define i8* @gethname(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i64 0, i32 0)
%4 = load i32, i32* @RES_AAONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @RES_DEFNAMES
%7 = load i32, i32* @RES_DNSRCH
%8 = or i32 %7, %6
%9 = xor i32 %8, -1
%10 = and i32 %5, %9
store i32 %10, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i64 0, i32 0)
%11 = bitcast i32* %2 to i8*
%12 = load i32, i32* @AF_INET
%13 = call %struct.hostent* @gethostbyaddr(i8* %11, i32 4, i32 %12)
store i32 %3, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i64 0, i32 0)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i32, i32* %2
%17 = call i8* @intoa(i32 %16)
br label %21
18: ; preds = %1
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%20 = load i8*, i8** %19
br label %21
21: ; preds = %18, %15
%22 = phi i8* [ %17, %15 ], [ %20, %18 ]
ret i8* %22
}