#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 */
typedef int /*<<< orphan*/ entries;

/* Variables and functions */
scalar_t__ strcmp(char const *, char const *);
const char *dns_lookup_ptr(const char ptr_name[]) {
  typedef struct {
    const char *ptr_name;
    const char *hostname;
  } Entry;
  static const Entry entries[] = {{"1.0.0.127.in-addr.arpa", "localhost"},
                                  {"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0."
                                   "0.0.0.0.0.0.0.0.0.0.0.ip6.arpa",
                                   "localhost"}};
  size_t i;
  for (i = 0; i < (sizeof(entries) / sizeof((entries)[0])); i++) {
    if (strcmp(ptr_name, entries[i].ptr_name) == 0) {
      return entries[i].hostname;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<dns_lookup_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x2,-0x18(%rbp)
jae    118c <dns_lookup_ptr+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0x2cc2(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1176 <dns_lookup_ptr+0x66>
mov    -0x18(%rbp),%rcx
lea    0x2c9e(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1194 <dns_lookup_ptr+0x84>
jmp    117b <dns_lookup_ptr+0x6b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <dns_lookup_ptr+0x14>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dns_lookup_ptr>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     113d <dns_lookup_ptr+0x2d>
lea    0xef5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1141 <dns_lookup_ptr+0x31>
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
jmp    1146 <dns_lookup_ptr+0x36>
mov    $0x1,%eax
shl    $0x4,%rax
lea    0x2caf(%rip),%rcx
mov    0x8(%rax,%rcx,1),%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.Entry = type { i8*, i8* }
@dns_lookup_ptr.entries = internal constant [2 x %struct.Entry] [%struct.Entry { i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0) }, %struct.Entry { i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0) }]
@.str = [23 x i8] c"1.0.0.127.in-addr.arpa\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [73 x i8] c"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa\00"
define i8* @dns_lookup_ptr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %4
br label %5
5: ; preds = %22, %1
%6 = load i64, i64* %4
%7 = icmp ult i64 %6, 2
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = getelementptr inbounds [2 x %struct.Entry], [2 x %struct.Entry]* @dns_lookup_ptr.entries, i64 0, i64 %10
%12 = getelementptr inbounds %struct.Entry, %struct.Entry* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %9, i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %8
%17 = load i64, i64* %4
%18 = getelementptr inbounds [2 x %struct.Entry], [2 x %struct.Entry]* @dns_lookup_ptr.entries, i64 0, i64 %17
%19 = getelementptr inbounds %struct.Entry, %struct.Entry* %18, i32 0, i32 1
%20 = load i8*, i8** %19
store i8* %20, i8** %2
br label %26
21: ; preds = %8
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = add i64 %23, 1
store i64 %24, i64* %4
br label %5
25: ; preds = %5
store i8* null, i8** %2
br label %26
26: ; preds = %25, %16
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
%struct.Entry = type { i8*, i8* }
@dns_lookup_ptr.entries = internal unnamed_addr constant [2 x %struct.Entry] [%struct.Entry { i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0) }, %struct.Entry { i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0) }]
@.str = [23 x i8] c"1.0.0.127.in-addr.arpa\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [73 x i8] c"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa\00"
define i8* @dns_lookup_ptr(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %8, %1
%5 = phi i64 [ 0, %1 ], [ 1, %8 ]
%6 = getelementptr inbounds [2 x %struct.Entry], [2 x %struct.Entry]* @dns_lookup_ptr.entries, i64 0, i64 %5, i32 1
%7 = load i8*, i8** %6
br label %11
8: ; preds = %1
%9 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %4, label %11
11: ; preds = %8, %4
%12 = phi i8* [ %7, %4 ], [ null, %8 ]
ret i8* %12
}