#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int NS_MAXDNAME;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ns_name_ntop(unsigned char const *, char *, int);
int /*<<< orphan*/ perror(char *);
char *strdup(char *);
char *target_name(const unsigned char *target) {
  char buf[NS_MAXDNAME];
  if (ns_name_ntop(target, buf, sizeof buf) == -1) {
    perror("ns_name_ntop");
    exit(EXIT_FAILURE);
  }
  return (strdup(buf));
}


x86 assembly (clang, -O0):
<target_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x20(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    %eax,%edx
call   1040 <ns_name_ntop@plt>
cmp    $0xffffffff,%eax
jne    11a6 <target_name+0x66>
lea    0xe6d(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strdup@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<target_name>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1040 <ns_name_ntop@plt>
cmp    $0xffffffff,%eax
je     117f <target_name+0x3f>
mov    %rbx,%rdi
call   1060 <strdup@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7a(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@NS_MAXDNAME = global i32 0
@.str = [13 x i8] c"ns_name_ntop\00"
@EXIT_FAILURE = global i32 0
define i8* @target_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i32, i32* @NS_MAXDNAME
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %3
%8 = alloca i8, i64 %6
store i64 %6, i64* %4
%9 = load i8*, i8** %2
%10 = trunc i64 %6 to i32
%11 = call i32 @ns_name_ntop(i8* %9, i8* %8, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = call i8* @strdup(i8* %8)
%19 = load i8*, i8** %3
ret i8* %18
}

LLVM IR (-O2):
@NS_MAXDNAME = global i32 0
@.str = [13 x i8] c"ns_name_ntop\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @target_name(i8* %0) {
%2 = load i32, i32* @NS_MAXDNAME
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @ns_name_ntop(i8* %0, i8* %4, i32 %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = call i8* @strdup(i8* %4)
ret i8* %12
}