#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 dummy;
};
struct hostent {
  char **h_aliases;
  scalar_t__ h_addrtype;
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main(void) {
  struct hostent *host = gethostbyname("vvl.me");
  if (!host) {
    puts("Get IP address error!");
    exit(0);
  }
  for (int i = 0; host->h_aliases[i]; i++)
    printf("Aliases %d: %s\n", i + 1, host->h_aliases[i]);
  printf("Address type: %s\n",
         (host->h_addrtype == AF_INET) ? "AF_INET" : "AF_INET6");
  for (int i = 0; host->h_addr_list[i]; i++)
    printf("IP addr %d: %s\n", i + 1,
           inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <main+0x3d>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11db <main+0x8b>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    0x2dfe(%rip),%rax
mov    (%rax),%rdx
lea    0xe53(%rip),%rsi
lea    0xe44(%rip),%rax
cmp    %rdx,%rcx
cmove  %rax,%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1270 <main+0x120>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <main+0xc7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     122f <main+0xdf>
mov    %rax,%r14
mov    (%rax),%rax
mov    (%rax),%rdx
test   %rdx,%rdx
je     11ac <main+0x5c>
mov    $0x1,%ebx
lea    0xe99(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rax
mov    (%rax,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1190 <main+0x40>
mov    0x8(%r14),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
lea    0xe7e(%rip),%rax
lea    0xe7f(%rip),%rsi
cmove  %rax,%rsi
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rax
mov    (%rax),%rax
test   %rax,%rax
je     1227 <main+0xd7>
mov    $0x1,%ebx
lea    0xe5e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rax
mov    (%rax,%rbx,8),%rax
add    $0x1,%rbx
test   %rax,%rax
jne    1200 <main+0xb0>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8**, i64, i64* }
%struct.in_addr = type { i32 }
@.str = [7 x i8] c"vvl.me\00"
@.str.1 = [22 x i8] c"Get IP address error!\00"
@.str.2 = [16 x i8] c"Aliases %d: %s\0A\00"
@.str.3 = [18 x i8] c"Address type: %s\0A\00"
@AF_INET = global i64 0
@.str.4 = [8 x i8] c"AF_INET\00"
@.str.5 = [9 x i8] c"AF_INET6\00"
@.str.6 = [16 x i8] c"IP addr %d: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.hostent*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([7 x i8], [7 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 %11, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
store i32 0, i32* %3
br label %12
12: ; preds = %32, %11
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i8**, i8*** %14
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %35
21: ; preds = %12
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
%24 = load %struct.hostent*, %struct.hostent** %2
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 0
%26 = load i8**, i8*** %25
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %30)
br label %32
32: ; preds = %21
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %12
35: ; preds = %12
%36 = load %struct.hostent*, %struct.hostent** %2
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = load i64, i64* @AF_INET
%40 = icmp eq i64 %38, %39
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i32 0, i32* %4
br label %44
44: ; preds = %68, %35
%45 = load %struct.hostent*, %struct.hostent** %2
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 2
%47 = load i64*, i64** %46
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i64, i64* %47, i64 %49
%51 = load i64, i64* %50
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %71
53: ; preds = %44
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
%56 = load %struct.hostent*, %struct.hostent** %2
%57 = getelementptr inbounds %struct.hostent, %struct.hostent* %56, i32 0, i32 2
%58 = load i64*, i64** %57
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i64, i64* %58, i64 %60
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to %struct.in_addr*
%64 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i8* @inet_ntoa(i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %55, i8* %66)
br label %68
68: ; preds = %53
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %44
71: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i8**, i64, i64* }
%struct.in_addr = type { i32 }
@.str = [7 x i8] c"vvl.me\00"
@.str.1 = [22 x i8] c"Get IP address error!\00"
@.str.2 = [16 x i8] c"Aliases %d: %s\0A\00"
@.str.3 = [18 x i8] c"Address type: %s\0A\00"
@AF_INET = global i64 0
@.str.4 = [8 x i8] c"AF_INET\00"
@.str.5 = [9 x i8] c"AF_INET6\00"
@.str.6 = [16 x i8] c"IP addr %d: %s\0A\00"
define i32 @main() {
%1 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq %struct.hostent* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 0
%5 = load i8**, i8*** %4
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %22
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %22, %3
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 1
%13 = load i64, i64* %12
%14 = load i64, i64* @AF_INET
%15 = icmp eq i64 %13, %14
%16 = select i1 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 2
%19 = load i64*, i64** %18
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %33
22: ; preds = %3, %22
%23 = phi i64 [ %25, %22 ], [ 0, %3 ]
%24 = phi i8* [ %30, %22 ], [ %6, %3 ]
%25 = add nuw nsw i64 %23, 1
%26 = trunc i64 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %24)
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 %25
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %11, label %22
32: ; preds = %33, %11
ret i32 0
33: ; preds = %11, %33
%34 = phi i64 [ %36, %33 ], [ 0, %11 ]
%35 = phi i64 [ %45, %33 ], [ %20, %11 ]
%36 = add nuw i64 %34, 1
%37 = inttoptr i64 %35 to %struct.in_addr*
%38 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %37, i64 0, i32 0
%39 = load i32, i32* %38
%40 = tail call i8* @inet_ntoa(i32 %39)
%41 = trunc i64 %36 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %41, i8* %40)
%43 = load i64*, i64** %18
%44 = getelementptr inbounds i64, i64* %43, i64 %36
%45 = load i64, i64* %44
%46 = icmp eq i64 %45, 0
br i1 %46, label %32, label %33
}