#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 *);
void *inet_addr(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ yp_get_default_domain(char **);
scalar_t__ yp_match(char *, char *, char *, int /*<<< orphan*/, char **, int *);
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]);
  } else {
    static char *domain = 0;
    char *value;
    int value_len;
    if (!domain)
      yp_get_default_domain(&domain);
    if (yp_match(domain, "hosts.byname", host, strlen(host), &value,
                 &value_len) == 0) {
      in.s_addr = inet_addr(value);
    }
  }
  return in;
}


x86 assembly (clang, -O0):
<host2ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1177 <host2ip+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1188 <host2ip+0x38>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1246 <host2ip+0xf6>
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     11a2 <host2ip+0x52>
jmp    1241 <host2ip+0xf1>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11cd <host2ip+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    123c <host2ip+0xec>
cmpq   $0x0,0x2e83(%rip)
jne    11e7 <host2ip+0x97>
lea    0x2e76(%rip),%rdi
call   1060 <yp_get_default_domain@plt>
mov    0x2e6a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
lea    0xdec(%rip),%rsi
lea    -0x20(%rbp),%r8
lea    -0x24(%rbp),%r9
call   1070 <yp_match@plt>
cmp    $0x0,%rax
jne    1237 <host2ip+0xe7>
mov    -0x20(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x8(%rbp)
jmp    123c <host2ip+0xec>
jmp    1241 <host2ip+0xf1>
jmp    1246 <host2ip+0xf6>
mov    -0x8(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host2ip>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     1186 <host2ip+0x36>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1186 <host2ip+0x36>
mov    %rbx,%rdi
call   1040 <inet_addr@plt>
cmp    $0xffffffff,%eax
jne    118f <host2ip+0x3f>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1197 <host2ip+0x47>
mov    (%rax),%rax
mov    (%rax),%rax
jmp    118d <host2ip+0x3d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2eba(%rip),%r14
test   %r14,%r14
jne    11b6 <host2ip+0x66>
lea    0x2eae(%rip),%rdi
call   1060 <yp_get_default_domain@plt>
mov    0x2ea2(%rip),%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe3b(%rip),%rsi
lea    0x8(%rsp),%r8
lea    0x14(%rsp),%r9
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1070 <yp_match@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    118f <host2ip+0x3f>
mov    0x8(%rsp),%rdi
call   1040 <inet_addr@plt>
jmp    118f <host2ip+0x3f>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@INADDR_ANY = global i32 0
@host2ip.domain = internal global i8* null
@.str = [13 x i8] c"hosts.byname\00"
define i32 @host2ip(i8* %0) {
%2 = alloca %struct.in_addr
%3 = alloca i8*
%4 = alloca %struct.hostent*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9, %1
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
store i32 %15, i32* %16
br label %57
17: ; preds = %9
%18 = load i8*, i8** %3
%19 = call i8* @inet_addr(i8* %18)
%20 = ptrtoint i8* %19 to i32
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
store i32 %20, i32* %21
%22 = icmp ne i32 %20, -1
br i1 %22, label %23, label %24
23: ; preds = %17
br label %56
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = call %struct.hostent* @gethostbyname(i8* %25)
store %struct.hostent* %26, %struct.hostent** %4
%27 = icmp ne %struct.hostent* %26, null
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load %struct.hostent*, %struct.hostent** %4
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 0
%31 = load i64*, i64** %30
%32 = getelementptr inbounds i64, i64* %31, i64 0
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.in_addr*
%35 = bitcast %struct.in_addr* %2 to i8*
%36 = bitcast %struct.in_addr* %34 to i8*
br label %55
37: ; preds = %24
%38 = load i8*, i8** @host2ip.domain
%39 = icmp ne i8* %38, null
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = call i32 @yp_get_default_domain(i8** @host2ip.domain)
br label %42
42: ; preds = %40, %37
%43 = load i8*, i8** @host2ip.domain
%44 = load i8*, i8** %3
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* %45)
%47 = call i64 @yp_match(i8* %43, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %44, i32 %46, i8** %5, i32* %6)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %42
%50 = load i8*, i8** %5
%51 = call i8* @inet_addr(i8* %50)
%52 = ptrtoint i8* %51 to i32
%53 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
store i32 %52, i32* %53
br label %54
54: ; preds = %49, %42
br label %55
55: ; preds = %54, %28
br label %56
56: ; preds = %55, %23
br label %57
57: ; preds = %56, %14
%58 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
%59 = load i32, i32* %58
ret i32 %59
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@INADDR_ANY = global i32 0
@host2ip.domain = internal global i8* null
@.str = [13 x i8] c"hosts.byname\00"
define i32 @host2ip(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5, %1
%9 = load i32, i32* @INADDR_ANY
br label %45
10: ; preds = %5
%11 = tail call i8* @inet_addr(i8* %0)
%12 = ptrtoint i8* %11 to i64
%13 = trunc i64 %12 to i32
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = tail call %struct.hostent* @gethostbyname(i8* %0)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%20 = load i64*, i64** %19
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to %struct.in_addr*
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %22, i64 0, i32 0
%24 = load i32, i32* %23
br label %45
25: ; preds = %15
%26 = bitcast i8** %2 to i8*
%27 = bitcast i32* %3 to i8*
%28 = load i8*, i8** @host2ip.domain
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = tail call i32 @yp_get_default_domain(i8** @host2ip.domain)
%32 = load i8*, i8** @host2ip.domain
br label %33
33: ; preds = %30, %25
%34 = phi i8* [ %32, %30 ], [ %28, %25 ]
%35 = tail call i32 @strlen(i8* %0)
%36 = call i64 @yp_match(i8* %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %35, i8** %2, i32* %3)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i8*, i8** %2
%40 = call i8* @inet_addr(i8* %39)
%41 = ptrtoint i8* %40 to i64
%42 = trunc i64 %41 to i32
br label %43
43: ; preds = %38, %33
%44 = phi i32 [ %42, %38 ], [ -1, %33 ]
br label %45
45: ; preds = %10, %43, %18, %8
%46 = phi i32 [ %9, %8 ], [ %13, %10 ], [ %24, %18 ], [ %44, %43 ]
ret i32 %46
}