#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*/ uint32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(char const *);
uint32_t resolve_host_addr(const char *host) {
  uint32_t dest = 0;
  struct hostent *he = gethostbyname(host);
  if (he && he->h_addr_list && he->h_addr_list[0]) {
    dest = ((struct in_addr *)(he->h_addr_list[0]))->s_addr;
  }
  return dest;
}


x86 assembly (clang, -O0):
<resolve_host_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1169 <resolve_host_addr+0x59>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1169 <resolve_host_addr+0x59>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     1169 <resolve_host_addr+0x59>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_host_addr>:
push   %rax
call   1030 <gethostbyname@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1132 <resolve_host_addr+0x22>
mov    (%rcx),%rcx
test   %rcx,%rcx
je     1132 <resolve_host_addr+0x22>
mov    (%rcx),%rcx
test   %rcx,%rcx
je     1132 <resolve_host_addr+0x22>
mov    (%rcx),%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define i32 @resolve_host_addr(i8* %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* %0)
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%6 = load i64*, i64** %5
%7 = icmp eq i64* %6, null
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = inttoptr i64 %9 to %struct.in_addr*
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %12, i64 0, i32 0
%14 = load i32, i32* %13
br label %15
15: ; preds = %11, %8, %4, %1
%16 = phi i32 [ %14, %11 ], [ 0, %8 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %16
}