#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 {
  int h_addrtype;
  char *h_name;
  char **h_aliases;
};

/* Variables and functions */
int /*<<< orphan*/ _endhtent();
struct hostent *_gethtent();
int /*<<< orphan*/ _sethtent(int /*<<< orphan*/);
scalar_t__ strcasecmp(char *, char const *);
struct hostent *_gethtbyname2(const char *name, int af) {
  struct hostent *p;
  char **cp;
  _sethtent(0);
  while ((p = _gethtent())) {
    if (p->h_addrtype != af)
      continue;
    if (strcasecmp(p->h_name, name) == 0)
      break;
    for (cp = p->h_aliases; *cp != 0; cp++)
      if (strcasecmp(*cp, name) == 0)
        goto found;
  }
found:
  _endhtent();
  return (p);
}


x86 assembly (clang, -O0):
<_gethtbyname2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %edi,%edi
call   1060 <_sethtent@plt>
mov    $0x0,%al
call   1050 <_gethtent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f3 <_gethtbyname2+0xb3>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
je     117f <_gethtbyname2+0x3f>
jmp    1156 <_gethtbyname2+0x16>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    119f <_gethtbyname2+0x5f>
jmp    11f3 <_gethtbyname2+0xb3>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ee <_gethtbyname2+0xae>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11d8 <_gethtbyname2+0x98>
jmp    11f8 <_gethtbyname2+0xb8>
jmp    11dd <_gethtbyname2+0x9d>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11ab <_gethtbyname2+0x6b>
jmp    1156 <_gethtbyname2+0x16>
jmp    11f8 <_gethtbyname2+0xb8>
mov    $0x0,%al
call   1030 <_endhtent@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gethtbyname2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %r15d,%r15d
xor    %edi,%edi
call   1060 <_sethtent@plt>
xor    %eax,%eax
call   1050 <_gethtent@plt>
test   %rax,%rax
je     11ce <_gethtbyname2+0x8e>
mov    %rax,%r15
jmp    117f <_gethtbyname2+0x3f>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <_gethtent@plt>
mov    %rax,%r15
test   %rax,%rax
je     11cb <_gethtbyname2+0x8b>
cmp    %r14d,(%r15)
jne    1170 <_gethtbyname2+0x30>
mov    0x8(%r15),%rdi
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11ce <_gethtbyname2+0x8e>
mov    0x10(%r15),%rbx
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1170 <_gethtbyname2+0x30>
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     11ce <_gethtbyname2+0x8e>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    11b0 <_gethtbyname2+0x70>
jmp    1170 <_gethtbyname2+0x30>
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <_endhtent@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i8*, i8** }
define %struct.hostent* @_gethtbyname2(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.hostent*
%6 = alloca i8**
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 @_sethtent(i32 0)
br label %8
8: ; preds = %45, %17, %2
%9 = call %struct.hostent* (...) @_gethtent()
store %struct.hostent* %9, %struct.hostent** %5
%10 = icmp ne %struct.hostent* %9, null
br i1 %10, label %11, label %46
11: ; preds = %8
%12 = load %struct.hostent*, %struct.hostent** %5
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* %4
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %11
br label %8
18: ; preds = %11
%19 = load %struct.hostent*, %struct.hostent** %5
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 1
%21 = load i8*, i8** %20
%22 = load i8*, i8** %3
%23 = call i64 @strcasecmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
br label %46
26: ; preds = %18
%27 = load %struct.hostent*, %struct.hostent** %5
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 2
%29 = load i8**, i8*** %28
store i8** %29, i8*** %6
br label %30
30: ; preds = %42, %26
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i8**, i8*** %6
%36 = load i8*, i8** %35
%37 = load i8*, i8** %3
%38 = call i64 @strcasecmp(i8* %36, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
br label %47
41: ; preds = %34
br label %42
42: ; preds = %41
%43 = load i8**, i8*** %6
%44 = getelementptr inbounds i8*, i8** %43, i32 1
store i8** %44, i8*** %6
br label %30
45: ; preds = %30
br label %8
46: ; preds = %25, %8
br label %47
47: ; preds = %46, %40
%48 = call i32 (...) @_endhtent()
%49 = load %struct.hostent*, %struct.hostent** %5
ret %struct.hostent* %49
}

LLVM IR (-O2):
%struct.hostent = type { i32, i8*, i8** }
define %struct.hostent* @_gethtbyname2(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @_sethtent(i32 0)
%4 = tail call %struct.hostent* (...) @_gethtent()
%5 = icmp eq %struct.hostent* %4, null
br i1 %5, label %33, label %6
6: ; preds = %2, %11
%7 = phi %struct.hostent* [ %12, %11 ], [ %4, %2 ]
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, %1
br i1 %10, label %14, label %11
11: ; preds = %24, %19, %6
%12 = tail call %struct.hostent* (...) @_gethtent()
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %33, label %6
14: ; preds = %6
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strcasecmp(i8* %16, i8* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %33, label %19
19: ; preds = %14
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 2
%21 = load i8**, i8*** %20
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %11, label %27
24: ; preds = %27
%25 = load i8*, i8** %32
%26 = icmp eq i8* %25, null
br i1 %26, label %11, label %27
27: ; preds = %19, %24
%28 = phi i8* [ %25, %24 ], [ %22, %19 ]
%29 = phi i8** [ %32, %24 ], [ %21, %19 ]
%30 = tail call i64 @strcasecmp(i8* %28, i8* %0)
%31 = icmp eq i64 %30, 0
%32 = getelementptr inbounds i8*, i8** %29, i64 1
br i1 %31, label %33, label %24
33: ; preds = %14, %11, %27, %2
%34 = phi %struct.hostent* [ null, %2 ], [ %7, %27 ], [ %7, %14 ], [ null, %11 ]
%35 = tail call i32 (...) @_endhtent()
ret %struct.hostent* %34
}