#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 struct hostent_list const hostent_list;
struct hostent {
  int dummy;
};
typedef int /*<<< orphan*/ ip;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ config_get_bool(char *);
scalar_t__ config_host_valid(struct hostent_list const *);
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ hostent_delete(struct hostent_list const *,
                                  struct hostent_list const *);
struct hostent_list const *hostent_get(struct hostent_list const *,
                                       unsigned long, char *);
struct hostent_list const *hostent_init(struct hostent *, unsigned long,
                                        char *);
int /*<<< orphan*/ hostent_push(struct hostent_list const *, struct hostent *,
                                unsigned long, char *);
const struct hostent_list *config_reverse_lookup(struct hostent_list **hl,
                                                 unsigned long int ip) {
  const struct hostent_list *h;
  struct hostent *he;
  if (config_get_bool("reverselookups") == 0 ||
      config_get_bool("dnslookups") == 0) {
    return (struct hostent_list *)0;
  }
  if (!hl) {
    return (struct hostent_list *)0;
  }
  if (*hl) {
    h = hostent_get(*hl, ip, (char *)0);
    if (config_host_valid(h)) {
      return h;
    } else {
      hostent_delete(*hl, h);
    }
  }
  he = gethostbyaddr((char *)&ip, sizeof(ip), AF_INET);
  if (*hl) {
    hostent_push(*hl, he, ip, (char *)0);
  } else {
    *hl = hostent_init(he, ip, (char *)0);
  }
  return hostent_get(*hl, ip, (char *)0);
}


x86 assembly (clang, -O0):
<config_reverse_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe79(%rip),%rdi
call   1060 <config_get_bool@plt>
cmp    $0x0,%rax
je     11ac <config_reverse_lookup+0x3c>
lea    0xe72(%rip),%rdi
call   1060 <config_get_bool@plt>
cmp    $0x0,%rax
jne    11b9 <config_reverse_lookup+0x49>
movq   $0x0,-0x8(%rbp)
jmp    12a5 <config_reverse_lookup+0x135>
cmpq   $0x0,-0x10(%rbp)
jne    11d1 <config_reverse_lookup+0x61>
movq   $0x0,-0x8(%rbp)
jmp    12a5 <config_reverse_lookup+0x135>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     122c <config_reverse_lookup+0xbc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <hostent_get@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <config_host_valid@plt>
cmp    $0x0,%rax
je     1217 <config_reverse_lookup+0xa7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <config_reverse_lookup+0x135>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <hostent_delete@plt>
jmp    122c <config_reverse_lookup+0xbc>
lea    -0x18(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1090 <gethostbyaddr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1272 <config_reverse_lookup+0x102>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <hostent_push@plt>
jmp    128d <config_reverse_lookup+0x11d>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <hostent_init@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <hostent_get@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_reverse_lookup>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,0x8(%rsp)
lea    0xe75(%rip),%rdi
call   1060 <config_get_bool@plt>
test   %rax,%rax
je     121a <config_reverse_lookup+0xaa>
lea    0xe6f(%rip),%rdi
call   1060 <config_get_bool@plt>
xor    %ebx,%ebx
test   %r14,%r14
je     1240 <config_reverse_lookup+0xd0>
test   %rax,%rax
je     1240 <config_reverse_lookup+0xd0>
mov    (%r14),%rdi
test   %rdi,%rdi
je     11e6 <config_reverse_lookup+0x76>
mov    %r15,%rsi
xor    %edx,%edx
call   1080 <hostent_get@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <config_host_valid@plt>
test   %rax,%rax
jne    1240 <config_reverse_lookup+0xd0>
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1040 <hostent_delete@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1090 <gethostbyaddr@plt>
mov    (%r14),%rdi
mov    0x8(%rsp),%rdx
test   %rdi,%rdi
je     121e <config_reverse_lookup+0xae>
mov    %rax,%rsi
xor    %ecx,%ecx
call   1050 <hostent_push@plt>
mov    (%r14),%rdi
jmp    1231 <config_reverse_lookup+0xc1>
xor    %ebx,%ebx
jmp    1240 <config_reverse_lookup+0xd0>
mov    %rax,%rdi
mov    %rdx,%rsi
xor    %edx,%edx
call   1030 <hostent_init@plt>
mov    %rax,%rdi
mov    %rax,(%r14)
mov    0x8(%rsp),%rsi
xor    %edx,%edx
call   1080 <hostent_get@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hostent_list = type opaque
%struct.hostent = type { i32 }
@.str = [15 x i8] c"reverselookups\00"
@.str.1 = [11 x i8] c"dnslookups\00"
@AF_INET = global i32 0
define %struct.hostent_list* @config_reverse_lookup(%struct.hostent_list** %0, i64 %1) {
%3 = alloca %struct.hostent_list*
%4 = alloca %struct.hostent_list**
%5 = alloca i64
%6 = alloca %struct.hostent_list*
%7 = alloca %struct.hostent*
store %struct.hostent_list** %0, %struct.hostent_list*** %4
store i64 %1, i64* %5
%8 = call i64 @config_get_bool(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i64 @config_get_bool(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store %struct.hostent_list* null, %struct.hostent_list** %3
br label %61
14: ; preds = %10
%15 = load %struct.hostent_list**, %struct.hostent_list*** %4
%16 = icmp ne %struct.hostent_list** %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store %struct.hostent_list* null, %struct.hostent_list** %3
br label %61
18: ; preds = %14
%19 = load %struct.hostent_list**, %struct.hostent_list*** %4
%20 = load %struct.hostent_list*, %struct.hostent_list** %19
%21 = icmp ne %struct.hostent_list* %20, null
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load %struct.hostent_list**, %struct.hostent_list*** %4
%24 = load %struct.hostent_list*, %struct.hostent_list** %23
%25 = load i64, i64* %5
%26 = call %struct.hostent_list* @hostent_get(%struct.hostent_list* %24, i64 %25, i8* null)
store %struct.hostent_list* %26, %struct.hostent_list** %6
%27 = load %struct.hostent_list*, %struct.hostent_list** %6
%28 = call i64 @config_host_valid(%struct.hostent_list* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = load %struct.hostent_list*, %struct.hostent_list** %6
store %struct.hostent_list* %31, %struct.hostent_list** %3
br label %61
32: ; preds = %22
%33 = load %struct.hostent_list**, %struct.hostent_list*** %4
%34 = load %struct.hostent_list*, %struct.hostent_list** %33
%35 = load %struct.hostent_list*, %struct.hostent_list** %6
%36 = call i32 @hostent_delete(%struct.hostent_list* %34, %struct.hostent_list* %35)
br label %37
37: ; preds = %32
br label %38
38: ; preds = %37, %18
%39 = bitcast i64* %5 to i8*
%40 = load i32, i32* @AF_INET
%41 = call %struct.hostent* @gethostbyaddr(i8* %39, i32 8, i32 %40)
store %struct.hostent* %41, %struct.hostent** %7
%42 = load %struct.hostent_list**, %struct.hostent_list*** %4
%43 = load %struct.hostent_list*, %struct.hostent_list** %42
%44 = icmp ne %struct.hostent_list* %43, null
br i1 %44, label %45, label %51
45: ; preds = %38
%46 = load %struct.hostent_list**, %struct.hostent_list*** %4
%47 = load %struct.hostent_list*, %struct.hostent_list** %46
%48 = load %struct.hostent*, %struct.hostent** %7
%49 = load i64, i64* %5
%50 = call i32 @hostent_push(%struct.hostent_list* %47, %struct.hostent* %48, i64 %49, i8* null)
br label %56
51: ; preds = %38
%52 = load %struct.hostent*, %struct.hostent** %7
%53 = load i64, i64* %5
%54 = call %struct.hostent_list* @hostent_init(%struct.hostent* %52, i64 %53, i8* null)
%55 = load %struct.hostent_list**, %struct.hostent_list*** %4
store %struct.hostent_list* %54, %struct.hostent_list** %55
br label %56
56: ; preds = %51, %45
%57 = load %struct.hostent_list**, %struct.hostent_list*** %4
%58 = load %struct.hostent_list*, %struct.hostent_list** %57
%59 = load i64, i64* %5
%60 = call %struct.hostent_list* @hostent_get(%struct.hostent_list* %58, i64 %59, i8* null)
store %struct.hostent_list* %60, %struct.hostent_list** %3
br label %61
61: ; preds = %56, %30, %17, %13
%62 = load %struct.hostent_list*, %struct.hostent_list** %3
ret %struct.hostent_list* %62
}

LLVM IR (-O2):
%struct.hostent_list = type opaque
%struct.hostent = type { i32 }
@.str = [15 x i8] c"reverselookups\00"
@.str.1 = [11 x i8] c"dnslookups\00"
@AF_INET = global i32 0
define %struct.hostent_list* @config_reverse_lookup(%struct.hostent_list** %0, i64 %1) {
%3 = alloca i64
store i64 %1, i64* %3
%4 = tail call i64 @config_get_bool(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %37, label %6
6: ; preds = %2
%7 = tail call i64 @config_get_bool(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = icmp eq %struct.hostent_list** %0, null
%10 = or i1 %9, %8
br i1 %10, label %37, label %11
11: ; preds = %6
%12 = load %struct.hostent_list*, %struct.hostent_list** %0
%13 = icmp eq %struct.hostent_list* %12, null
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = tail call %struct.hostent_list* @hostent_get(%struct.hostent_list* %12, i64 %1, i8* null)
%16 = tail call i64 @config_host_valid(%struct.hostent_list* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load %struct.hostent_list*, %struct.hostent_list** %0
%20 = tail call i32 @hostent_delete(%struct.hostent_list* %19, %struct.hostent_list* %15)
br label %21
21: ; preds = %18, %11
%22 = bitcast i64* %3 to i8*
%23 = load i32, i32* @AF_INET
%24 = call %struct.hostent* @gethostbyaddr(i8* %22, i32 8, i32 %23)
%25 = load %struct.hostent_list*, %struct.hostent_list** %0
%26 = icmp eq %struct.hostent_list* %25, null
%27 = load i64, i64* %3
br i1 %26, label %31, label %28
28: ; preds = %21
%29 = call i32 @hostent_push(%struct.hostent_list* %25, %struct.hostent* %24, i64 %27, i8* null)
%30 = load %struct.hostent_list*, %struct.hostent_list** %0
br label %33
31: ; preds = %21
%32 = call %struct.hostent_list* @hostent_init(%struct.hostent* %24, i64 %27, i8* null)
store %struct.hostent_list* %32, %struct.hostent_list** %0
br label %33
33: ; preds = %31, %28
%34 = phi %struct.hostent_list* [ %32, %31 ], [ %30, %28 ]
%35 = load i64, i64* %3
%36 = call %struct.hostent_list* @hostent_get(%struct.hostent_list* %34, i64 %35, i8* null)
br label %37
37: ; preds = %14, %2, %6, %33
%38 = phi %struct.hostent_list* [ %36, %33 ], [ null, %6 ], [ null, %2 ], [ %15, %14 ]
ret %struct.hostent_list* %38
}