#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 in_addr {
  unsigned long s_addr;
};
struct hostent {
  int /*<<< orphan*/ h_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *hostlookup(unsigned long int in) {
  static char blah[1024];
  struct in_addr i;
  struct hostent *he;
  i.s_addr = in;
  he = gethostbyaddr((char *)&i, sizeof(struct in_addr), AF_INET);
  if (he == NULL)
    strcpy(blah, inet_ntoa(i));
  else
    strcpy(blah, he->h_name);
  return blah;
}


x86 assembly (clang, -O0):
<hostlookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <hostlookup+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    %eax,%esi
lea    0x2ed4(%rip),%rdi
call   1030 <strcpy@plt>
jmp    1198 <hostlookup+0x68>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0x2ebd(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2eb1(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hostlookup>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1050 <gethostbyaddr@plt>
test   %rax,%rax
je     115b <hostlookup+0x2b>
mov    (%rax),%esi
jmp    1167 <hostlookup+0x37>
mov    0x8(%rsp),%rdi
call   1040 <inet_ntoa@plt>
mov    %eax,%esi
lea    0x2ee2(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i64 }
%struct.hostent = type { i32 }
@hostlookup.blah = internal global [1024 x i8] zeroinitializer
@AF_INET = global i32 0
define i8* @hostlookup(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.in_addr
%4 = alloca %struct.hostent*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i64 %5, i64* %6
%7 = bitcast %struct.in_addr* %3 to i8*
%8 = load i32, i32* @AF_INET
%9 = call %struct.hostent* @gethostbyaddr(i8* %7, i32 8, i32 %8)
store %struct.hostent* %9, %struct.hostent** %4
%10 = load %struct.hostent*, %struct.hostent** %4
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%14 = load i64, i64* %13
%15 = call i32 @inet_ntoa(i64 %14)
%16 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hostlookup.blah, i64 0, i64 0), i32 %15)
br label %22
17: ; preds = %1
%18 = load %struct.hostent*, %struct.hostent** %4
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hostlookup.blah, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %17, %12
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hostlookup.blah, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.in_addr = type { i64 }
%struct.hostent = type { i32 }
@hostlookup.blah = internal global [1024 x i8] zeroinitializer
@AF_INET = global i32 0
define i8* @hostlookup(i64 %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i64 %0, i64* %4
%5 = load i32, i32* @AF_INET
%6 = call %struct.hostent* @gethostbyaddr(i8* %3, i32 8, i32 %5)
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i64, i64* %4
%10 = call i32 @inet_ntoa(i64 %9)
br label %14
11: ; preds = %1
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%13 = load i32, i32* %12
br label %14
14: ; preds = %11, %8
%15 = phi i32 [ %13, %11 ], [ %10, %8 ]
%16 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hostlookup.blah, i64 0, i64 0), i32 %15)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @hostlookup.blah, i64 0, i64 0)
}