#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 {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *pr_name(struct in_addr addr) {
  struct hostent *phe;
  static char buf[80];
  phe = gethostbyaddr((char *)&addr.s_addr, 4, AF_INET);
  if (phe == NULL)
    return (inet_ntoa(addr));
  snprintf(buf, sizeof(buf), "%s (%s)", phe->h_name, inet_ntoa(addr));
  return (buf);
}


x86 assembly (clang, -O0):
<pr_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1172 <pr_name+0x42>
mov    -0x10(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x8(%rbp)
jmp    11af <pr_name+0x7f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,%r8
lea    0x2ebd(%rip),%rdi
mov    $0x50,%esi
lea    0xe61(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2ea5(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_name>:
push   %r14
push   %rbx
push   %rax
mov    %edi,(%rsp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x4,%esi
call   1050 <gethostbyaddr@plt>
test   %rax,%rax
je     1180 <pr_name+0x50>
mov    (%rax),%r14
mov    (%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0x2eec(%rip),%rbx
lea    0xe95(%rip),%rdx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <snprintf@plt>
jmp    118b <pr_name+0x5b>
mov    (%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8* }
@pr_name.buf = internal global [80 x i8] zeroinitializer
@AF_INET = global i32 0
@.str = [8 x i8] c"%s (%s)\00"
define i8* @pr_name(i32 %0) {
%2 = alloca i8*
%3 = alloca %struct.in_addr
%4 = alloca %struct.hostent*
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%7 = bitcast i32* %6 to i8*
%8 = load i32, i32* @AF_INET
%9 = call %struct.hostent* @gethostbyaddr(i8* %7, i32 4, 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 %16
12: ; preds = %1
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i8* @inet_ntoa(i32 %14)
store i8* %15, i8** %2
br label %24
16: ; preds = %1
%17 = load %struct.hostent*, %struct.hostent** %4
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i8* @inet_ntoa(i32 %21)
%23 = call i32 @snprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @pr_name.buf, i64 0, i64 0), i32 80, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %22)
store i8* getelementptr inbounds ([80 x i8], [80 x i8]* @pr_name.buf, i64 0, i64 0), i8** %2
br label %24
24: ; preds = %16, %12
%25 = load i8*, i8** %2
ret i8* %25
}

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