#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 /*<<< orphan*/ s_addr;
};
struct hostent {
  char *h_name;
  char **h_aliases;
};
typedef int /*<<< orphan*/ hostaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyaddr(struct in_addr *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ strcmp(char *, char *);
int main(void) {
  struct hostent *ent;
  struct in_addr hostaddr;
  int result = 0;
  inet_aton("127.0.0.1", (struct in_addr *)&hostaddr.s_addr);
  ent = gethostbyaddr(&hostaddr, sizeof(hostaddr), AF_INET);
  if (ent == NULL)
    puts("gethostbyaddr (...) == NULL");
  else {
    puts("Using gethostbyaddr(..):");
    printf("h_name: %s\n", ent->h_name);
    if (ent->h_aliases == NULL)
      puts("ent->h_aliases == NULL");
    else
      printf("h_aliases[0]: %s\n", ent->h_aliases[0]);
  }
  ent = gethostbyname("127.0.0.1");
  if (ent == NULL) {
    puts("gethostbyname (\"127.0.0.1\") == NULL");
    result = 1;
  } else {
    printf("\nNow using gethostbyname(..):\n");
    printf("h_name: %s\n", ent->h_name);
    if (strcmp(ent->h_name, "127.0.0.1") != 0) {
      puts("ent->h_name != \"127.0.0.1\"");
      result = 1;
    }
    if (ent->h_aliases == NULL) {
      puts("ent->h_aliases == NULL");
      result = 1;
    } else {
      printf("h_aliases[0]: %s\n", ent->h_aliases[0]);
      result |= ent->h_aliases[0] != NULL;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1070 <inet_aton@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1080 <gethostbyaddr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <main+0x5d>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
jmp    121c <main+0xbc>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11fe <main+0x9e>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
jmp    1217 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121c <main+0xbc>
lea    0xddd(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    124f <main+0xef>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1301 <main+0x1a1>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd80(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     12a2 <main+0x142>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12c9 <main+0x169>
lea    0xd93(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x1c(%rbp)
jmp    12fc <main+0x19c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1301 <main+0x1a1>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <inet_aton@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1080 <gethostbyaddr@plt>
test   %rax,%rax
je     11cc <main+0x6c>
mov    %rax,%rbx
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
test   %rax,%rax
je     11d5 <main+0x75>
mov    (%rax),%rsi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e1 <main+0x81>
lea    0xe37(%rip),%rdi
jmp    11dc <main+0x7c>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe18(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1264 <main+0x104>
mov    %rax,%rbx
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe34(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
lea    0xde2(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1239 <main+0xd9>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    0x8(%rbx),%rax
test   %rax,%rax
je     126d <main+0x10d>
mov    (%rax),%rsi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
xor    %ecx,%ecx
cmpq   $0x0,(%rax)
setne  %cl
or     %ecx,%ebp
jmp    127e <main+0x11e>
lea    0xe09(%rip),%rdi
jmp    1274 <main+0x114>
lea    0xdd7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i8** }
%struct.in_addr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@.str.1 = [28 x i8] c"gethostbyaddr (...) == NULL\00"
@.str.2 = [25 x i8] c"Using gethostbyaddr(..):\00"
@.str.3 = [12 x i8] c"h_name: %s\0A\00"
@.str.4 = [23 x i8] c"ent->h_aliases == NULL\00"
@.str.5 = [18 x i8] c"h_aliases[0]: %s\0A\00"
@.str.6 = [36 x i8] c"gethostbyname (\22127.0.0.1\22) == NULL\00"
@.str.7 = [31 x i8] c"\0ANow using gethostbyname(..):\0A\00"
@.str.8 = [27 x i8] c"ent->h_name != \22127.0.0.1\22\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.hostent*
%3 = alloca %struct.in_addr
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%6 = bitcast i32* %5 to %struct.in_addr*
%7 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %6)
%8 = load i32, i32* @AF_INET
%9 = call %struct.hostent* @gethostbyaddr(%struct.in_addr* %3, i32 4, i32 %8)
store %struct.hostent* %9, %struct.hostent** %2
%10 = load %struct.hostent*, %struct.hostent** %2
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %34
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = load %struct.hostent*, %struct.hostent** %2
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load %struct.hostent*, %struct.hostent** %2
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 1
%22 = load i8**, i8*** %21
%23 = icmp eq i8** %22, null
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %33
26: ; preds = %14
%27 = load %struct.hostent*, %struct.hostent** %2
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 1
%29 = load i8**, i8*** %28
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %26, %24
br label %34
34: ; preds = %33, %12
%35 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %35, %struct.hostent** %2
%36 = load %struct.hostent*, %struct.hostent** %2
%37 = icmp eq %struct.hostent* %36, null
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %4
br label %77
40: ; preds = %34
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%42 = load %struct.hostent*, %struct.hostent** %2
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load %struct.hostent*, %struct.hostent** %2
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %4
br label %53
53: ; preds = %51, %40
%54 = load %struct.hostent*, %struct.hostent** %2
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %54, i32 0, i32 1
%56 = load i8**, i8*** %55
%57 = icmp eq i8** %56, null
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %4
br label %76
60: ; preds = %53
%61 = load %struct.hostent*, %struct.hostent** %2
%62 = getelementptr inbounds %struct.hostent, %struct.hostent* %61, i32 0, i32 1
%63 = load i8**, i8*** %62
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %65)
%67 = load %struct.hostent*, %struct.hostent** %2
%68 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i32 0, i32 1
%69 = load i8**, i8*** %68
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = icmp ne i8* %71, null
%73 = zext i1 %72 to i32
%74 = load i32, i32* %4
%75 = or i32 %74, %73
store i32 %75, i32* %4
br label %76
76: ; preds = %60, %58
br label %77
77: ; preds = %76, %38
%78 = load i32, i32* %4
ret i32 %78
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8*, i8** }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@.str.1 = [28 x i8] c"gethostbyaddr (...) == NULL\00"
@.str.2 = [25 x i8] c"Using gethostbyaddr(..):\00"
@.str.3 = [12 x i8] c"h_name: %s\0A\00"
@.str.4 = [23 x i8] c"ent->h_aliases == NULL\00"
@.str.5 = [18 x i8] c"h_aliases[0]: %s\0A\00"
@.str.6 = [36 x i8] c"gethostbyname (\22127.0.0.1\22) == NULL\00"
@.str.8 = [27 x i8] c"ent->h_name != \22127.0.0.1\22\00"
@str = [30 x i8] c"\0ANow using gethostbyname(..):\00"
define i32 @main() {
%1 = alloca %struct.in_addr
%2 = bitcast %struct.in_addr* %1 to i8*
%3 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %1)
%4 = load i32, i32* @AF_INET
%5 = call %struct.hostent* @gethostbyaddr(%struct.in_addr* %1, i32 4, i32 %4)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %22
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%15 = load i8**, i8*** %14
%16 = icmp eq i8** %15, null
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %22
19: ; preds = %9
%20 = load i8*, i8** %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %17, %19, %7
%23 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq %struct.hostent* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %52
27: ; preds = %22
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %29
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
br label %37
37: ; preds = %35, %27
%38 = phi i32 [ 1, %35 ], [ 0, %27 ]
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i64 0, i32 1
%40 = load i8**, i8*** %39
%41 = icmp eq i8** %40, null
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %52
44: ; preds = %37
%45 = load i8*, i8** %40
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i8**, i8*** %39
%48 = load i8*, i8** %47
%49 = icmp ne i8* %48, null
%50 = zext i1 %49 to i32
%51 = or i32 %38, %50
br label %52
52: ; preds = %42, %44, %25
%53 = phi i32 [ 1, %25 ], [ 1, %42 ], [ %51, %44 ]
ret i32 %53
}