#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 {
  char *h_name;
  scalar_t__ h_addrtype;
  int h_length;
  char **h_addr_list;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ AF_INET;
struct hostent *gethostbyname(char *);
char *inet_ntop(scalar_t__, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  struct hostent *res;
  res = gethostbyname("balance.test.com");
  if (res != NULL) {
    char **p;
    char buf[255];
    printf("h_name: %s\n", res->h_name);
    printf("h_addrtype: %s\n",
           (res->h_addrtype == AF_INET ? "AF_INET" : "AF_INET6"));
    printf("h_length: %d\n", res->h_length);
    printf("h_addr_list:\n");
    p = res->h_addr_list;
    while (*p != NULL) {
      printf("\t%s\n", inet_ntop(res->h_addrtype, *p, buf, sizeof(buf)));
      p++;
    }
  } else {
    printf("Failed to resolve name "
           "balance.test.com"
           "!\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     122b <main+0xfb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    0x2e67(%rip),%rax
mov    (%rax),%rdx
lea    0xeaa(%rip),%rsi
lea    0xe9b(%rip),%rax
cmp    %rdx,%rcx
cmove  %rax,%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1226 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    -0x120(%rbp),%rdx
mov    $0xff,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    11d6 <main+0xa6>
jmp    1239 <main+0x109>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xeab(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     120d <main+0xcd>
mov    %rax,%r12
mov    (%rax),%rsi
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
lea    0xea0(%rip),%rax
lea    0xea1(%rip),%rsi
cmove  %rax,%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r12),%esi
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
mov    0x18(%r12),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1219 <main+0xd9>
add    $0x8,%rbx
mov    %rsp,%r14
lea    0xe6c(%rip),%r15
mov    0x8(%r12),%rdi
mov    %r14,%rdx
mov    $0xff,%ecx
call   1030 <inet_ntop@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11e0 <main+0xa0>
jmp    1219 <main+0xd9>
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i64, i32, i8** }
@.str = [17 x i8] c"balance.test.com\00"
@.str.1 = [12 x i8] c"h_name: %s\0A\00"
@.str.2 = [16 x i8] c"h_addrtype: %s\0A\00"
@AF_INET = global i64 0
@.str.3 = [8 x i8] c"AF_INET\00"
@.str.4 = [9 x i8] c"AF_INET6\00"
@.str.5 = [14 x i8] c"h_length: %d\0A\00"
@.str.6 = [14 x i8] c"h_addr_list:\0A\00"
@.str.7 = [5 x i8] c"\09%s\0A\00"
@.str.8 = [42 x i8] c"Failed to resolve name balance.test.com!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.hostent*
%3 = alloca i8**
%4 = alloca [255 x i8]
store i32 0, i32* %1
%5 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %5, %struct.hostent** %2
%6 = load %struct.hostent*, %struct.hostent** %2
%7 = icmp ne %struct.hostent* %6, null
br i1 %7, label %8, label %45
8: ; preds = %0
%9 = load %struct.hostent*, %struct.hostent** %2
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i32 0, i32 0
%11 = load i8*, i8** %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = load i64, i64* @AF_INET
%17 = icmp eq i64 %15, %16
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load %struct.hostent*, %struct.hostent** %2
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%26 = load %struct.hostent*, %struct.hostent** %2
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 3
%28 = load i8**, i8*** %27
store i8** %28, i8*** %3
br label %29
29: ; preds = %33, %8
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load %struct.hostent*, %struct.hostent** %2
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = load i8**, i8*** %3
%38 = load i8*, i8** %37
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%40 = call i8* @inet_ntop(i64 %36, i8* %38, i8* %39, i32 255)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %40)
%42 = load i8**, i8*** %3
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %3
br label %29
44: ; preds = %29
br label %47
45: ; preds = %0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
br label %47
47: ; preds = %45, %44
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i64, i32, i8** }
@.str = [17 x i8] c"balance.test.com\00"
@.str.1 = [12 x i8] c"h_name: %s\0A\00"
@.str.2 = [16 x i8] c"h_addrtype: %s\0A\00"
@AF_INET = global i64 0
@.str.3 = [8 x i8] c"AF_INET\00"
@.str.4 = [9 x i8] c"AF_INET6\00"
@.str.5 = [14 x i8] c"h_length: %d\0A\00"
@.str.7 = [5 x i8] c"\09%s\0A\00"
@str = [41 x i8] c"Failed to resolve name balance.test.com!\00"
@str.9 = [13 x i8] c"h_addr_list:\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %33, label %4
4: ; preds = %0
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
%10 = load i64, i64* %9
%11 = load i64, i64* @AF_INET
%12 = icmp eq i64 %10, %11
%13 = select i1 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 2
%16 = load i32, i32* %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 3
%20 = load i8**, i8*** %19
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %32, label %23
23: ; preds = %4, %23
%24 = phi i8* [ %30, %23 ], [ %21, %4 ]
%25 = phi i8** [ %29, %23 ], [ %20, %4 ]
%26 = load i64, i64* %9
%27 = call i8* @inet_ntop(i64 %26, i8* %24, i8* %5, i32 255)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds i8*, i8** %25, i64 1
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %23
32: ; preds = %23, %4
br label %35
33: ; preds = %0
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %32
ret i32 0
}