#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 {
  char *h_name;
};

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


x86 assembly (clang, -O0):
<lookup>:
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   1040 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <lookup+0x57>
mov    -0x10(%rbp),%rdi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0x2ed3(%rip),%rdi
call   1050 <sprintf@plt>
jmp    119a <lookup+0x6a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0x2ebb(%rip),%rdi
call   1050 <sprintf@plt>
lea    0x2eaf(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1040 <gethostbyaddr@plt>
test   %rax,%rax
je     115c <lookup+0x2c>
mov    (%rax),%rsi
jmp    1169 <lookup+0x39>
mov    0x8(%rsp),%rdi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0x2ee0(%rip),%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i64 }
%struct.hostent = type { i8* }
@lookup.buf = internal global [1024 x i8] zeroinitializer
@AF_INET = global i32 0
define i8* @lookup(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 i8* @inet_ntoa(i64 %14)
%16 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lookup.buf, i64 0, i64 0), i8* %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 i8*, i8** %19
%21 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lookup.buf, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %17, %12
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lookup.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.in_addr = type { i64 }
%struct.hostent = type { i8* }
@lookup.buf = internal global [1024 x i8] zeroinitializer
@AF_INET = global i32 0
define i8* @lookup(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 i8* @inet_ntoa(i64 %9)
br label %14
11: ; preds = %1
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%13 = load i8*, i8** %12
br label %14
14: ; preds = %11, %8
%15 = phi i8* [ %13, %11 ], [ %10, %8 ]
%16 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @lookup.buf, i64 0, i64 0), i8* dereferenceable(1) %15)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @lookup.buf, i64 0, i64 0)
}