#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_addrtype;
  int /*<<< orphan*/ **h_addr_list;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
scalar_t__ AF_INET;
unsigned long INADDR_NONE;
struct hostent *gethostbyname(char const *);
unsigned long inet_addr(char const *);
int /*<<< orphan*/ memcpy(unsigned long *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ nc_dump(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned long parse_addr(const char *address_str) {
  unsigned long addr;
  struct hostent *hent;
  addr = inet_addr(address_str);
  if (addr != INADDR_NONE)
    return addr;
  nc_dump("looking up address", NULL, 0);
  hent = gethostbyname(address_str);
  if (!hent) {
    return INADDR_NONE;
  }
  if (hent->h_addrtype == AF_INET && hent->h_addr_list[0] != NULL) {
    memcpy(&addr, hent->h_addr_list[0], sizeof(addr));
    return addr;
  }
  return INADDR_NONE;
}


x86 assembly (clang, -O0):
<parse_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
je     117a <parse_addr+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1214 <parse_addr+0xd4>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <nc_dump@plt>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <parse_addr+0x77>
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1214 <parse_addr+0xd4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <parse_addr+0xc6>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
cmpq   $0x0,(%rax)
je     1206 <parse_addr+0xc6>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rsi
lea    -0x18(%rbp),%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1214 <parse_addr+0xd4>
mov    0x2dd3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <inet_addr@plt>
mov    %rax,(%rsp)
mov    0x2e89(%rip),%r14
cmp    (%r14),%rax
jne    11aa <parse_addr+0x6a>
lea    0xe9d(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <nc_dump@plt>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11a7 <parse_addr+0x67>
mov    (%rax),%rcx
mov    0x2e65(%rip),%rdx
cmp    (%rdx),%rcx
jne    11a7 <parse_addr+0x67>
mov    0x8(%rax),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     11a7 <parse_addr+0x67>
mov    %rsp,%rdi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    (%rsp),%rax
jmp    11aa <parse_addr+0x6a>
mov    (%r14),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hostent = type { i64, i32** }
@INADDR_NONE = global i64 0
@.str = [19 x i8] c"looking up address\00"
@AF_INET = global i64 0
define i64 @parse_addr(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.hostent*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @inet_addr(i8* %6)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = load i64, i64* @INADDR_NONE
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i64, i64* %4
store i64 %12, i64* %2
br label %44
13: ; preds = %1
%14 = call i32 @nc_dump(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* null, i32 0)
%15 = load i8*, i8** %3
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %5
%17 = load %struct.hostent*, %struct.hostent** %5
%18 = icmp ne %struct.hostent* %17, null
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = load i64, i64* @INADDR_NONE
store i64 %20, i64* %2
br label %44
21: ; preds = %13
%22 = load %struct.hostent*, %struct.hostent** %5
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load i64, i64* @AF_INET
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %42
27: ; preds = %21
%28 = load %struct.hostent*, %struct.hostent** %5
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 1
%30 = load i32**, i32*** %29
%31 = getelementptr inbounds i32*, i32** %30, i64 0
%32 = load i32*, i32** %31
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %42
34: ; preds = %27
%35 = load %struct.hostent*, %struct.hostent** %5
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 1
%37 = load i32**, i32*** %36
%38 = getelementptr inbounds i32*, i32** %37, i64 0
%39 = load i32*, i32** %38
%40 = call i32 @memcpy(i64* %4, i32* %39, i32 8)
%41 = load i64, i64* %4
store i64 %41, i64* %2
br label %44
42: ; preds = %27, %21
%43 = load i64, i64* @INADDR_NONE
store i64 %43, i64* %2
br label %44
44: ; preds = %42, %34, %19, %11
%45 = load i64, i64* %2
ret i64 %45
}

LLVM IR (-O2):
%struct.hostent = type { i64, i32** }
@INADDR_NONE = global i64 0
@.str = [19 x i8] c"looking up address\00"
@AF_INET = global i64 0
define i64 @parse_addr(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i64 @inet_addr(i8* %0)
store i64 %4, i64* %2
%5 = load i64, i64* @INADDR_NONE
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %28
7: ; preds = %1
%8 = tail call i32 @nc_dump(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* null, i32 0)
%9 = tail call %struct.hostent* @gethostbyname(i8* %0)
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = load i64, i64* @INADDR_NONE
br label %28
13: ; preds = %7
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @AF_INET
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 1
%20 = load i32**, i32*** %19
%21 = load i32*, i32** %20
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = call i32 @memcpy(i64* %2, i32* %21, i32 8)
%25 = load i64, i64* %2
br label %28
26: ; preds = %18, %13
%27 = load i64, i64* @INADDR_NONE
br label %28
28: ; preds = %1, %26, %23, %11
%29 = phi i64 [ %25, %23 ], [ %27, %26 ], [ %12, %11 ], [ %4, %1 ]
ret i64 %29
}