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

/* Variables and functions */
int INADDR_ANY;
struct hostent *gethostbyname(char *);
int inet_addr(char *);
struct in_addr host2ip(char *host) {
  struct in_addr in;
  register struct hostent *hep;
  if (!host || *host == '\0') {
    in.s_addr = INADDR_ANY;
  } else if ((in.s_addr = inet_addr(host)) != -1) {
  } else if ((hep = gethostbyname(host))) {
    in = *(struct in_addr *)(hep->h_addr_list[0]);
  }
  return in;
}


x86 assembly (clang, -O0):
<host2ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1147 <host2ip+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1158 <host2ip+0x38>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    11a2 <host2ip+0x82>
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1172 <host2ip+0x52>
jmp    119d <host2ip+0x7d>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1198 <host2ip+0x78>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    119d <host2ip+0x7d>
jmp    11a2 <host2ip+0x82>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host2ip>:
push   %rbx
mov    0x2ec0(%rip),%rax
test   %rdi,%rdi
je     1157 <host2ip+0x37>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1157 <host2ip+0x37>
mov    %rbx,%rdi
call   1030 <inet_addr@plt>
cmp    $0xffffffff,%eax
je     1144 <host2ip+0x24>
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     115b <host2ip+0x3b>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

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