#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 hostent {
  scalar_t__ *h_addr_list;
};
typedef unsigned long in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
unsigned long inet_addr(char const *);
unsigned long ntohl(unsigned long);
unsigned long _GeoIP_lookupaddress(const char *host) {
  unsigned long addr = inet_addr(host);
  struct hostent phe2;
  struct hostent *phe = &phe2;
  char *buf = NULL;
  int result = 0;
  if (addr == -1) {
    if (!phe || result != 0) {
      free(buf);
      return 0;
    }
    addr = *((in_addr_t *)phe->h_addr_list[0]);
  }
  return ntohl(addr);
}


x86 assembly (clang, -O0):
<_GeoIP_lookupaddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11a7 <_GeoIP_lookupaddress+0x77>
cmpq   $0x0,-0x28(%rbp)
je     1180 <_GeoIP_lookupaddress+0x50>
cmpl   $0x0,-0x34(%rbp)
je     1196 <_GeoIP_lookupaddress+0x66>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b4 <_GeoIP_lookupaddress+0x84>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ntohl@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_GeoIP_lookupaddress>:
push   %rax
call   1030 <inet_addr@plt>
mov    %rax,%rdi
pop    %rax
jmp    1040 <ntohl@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
define i64 @_GeoIP_lookupaddress(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.hostent
%6 = alloca %struct.hostent*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i64 @inet_addr(i8* %9)
store i64 %10, i64* %4
store %struct.hostent* %5, %struct.hostent** %6
store i8* null, i8** %7
store i32 0, i32* %8
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, -1
br i1 %12, label %13, label %30
13: ; preds = %1
%14 = load %struct.hostent*, %struct.hostent** %6
%15 = icmp ne %struct.hostent* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16, %13
%20 = load i8*, i8** %7
%21 = call i32 @free(i8* %20)
store i64 0, i64* %2
br label %33
22: ; preds = %16
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i64*, i64** %24
%26 = getelementptr inbounds i64, i64* %25, i64 0
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to i64*
%29 = load i64, i64* %28
store i64 %29, i64* %4
br label %30
30: ; preds = %22, %1
%31 = load i64, i64* %4
%32 = call i64 @ntohl(i64 %31)
store i64 %32, i64* %2
br label %33
33: ; preds = %30, %19
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
define i64 @_GeoIP_lookupaddress(i8* %0) {
%2 = tail call i64 @inet_addr(i8* %0)
%3 = icmp ne i64 %2, -1
%4 = tail call i64 @ntohl(i64 %2)
ret i64 %4
}