#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_name;
  char **h_aliases;
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyaddr(struct in_addr *, int, int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *, ...);
int main() {
  struct in_addr bar;
  struct hostent *foo;
  inet_aton("160.45.10.8", &bar);
  foo = gethostbyaddr(&bar, 4, AF_INET);
  if (foo) {
    int i;
    for (i = 0; foo->h_addr_list[i]; ++i)
      printf("%s -> %s\n", foo->h_name,
             inet_ntoa(*(struct in_addr *)foo->h_addr_list[i]));
    for (i = 0; foo->h_aliases[i]; ++i)
      printf("  also known as %s\n", foo->h_aliases[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <inet_aton@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1060 <gethostbyaddr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1237 <main+0xf7>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118c <main+0x4c>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1232 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ef <main+0xaf>
jmp    1237 <main+0xf7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <inet_aton@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <gethostbyaddr@plt>
test   %rax,%rax
je     120b <main+0xcb>
mov    %rax,%r15
mov    0x10(%rax),%rax
mov    (%rax),%rax
test   %rax,%rax
je     11cb <main+0x8b>
mov    $0x8,%ebx
lea    0xe78(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%r12
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r15),%rax
mov    (%rax,%rbx,1),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    11a0 <main+0x60>
mov    0x8(%r15),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     120b <main+0xcb>
mov    $0x8,%ebx
lea    0xe33(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%rax
mov    (%rax,%rbx,1),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11f0 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8*, i8**, i64* }
@.str = [12 x i8] c"160.45.10.8\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"%s -> %s\0A\00"
@.str.2 = [20 x i8] c" also known as %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.in_addr
%3 = alloca %struct.hostent*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @inet_aton(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %2)
%6 = load i32, i32* @AF_INET
%7 = call %struct.hostent* @gethostbyaddr(%struct.in_addr* %2, i32 4, i32 %6)
store %struct.hostent* %7, %struct.hostent** %3
%8 = load %struct.hostent*, %struct.hostent** %3
%9 = icmp ne %struct.hostent* %8, null
br i1 %9, label %10, label %62
10: ; preds = %0
store i32 0, i32* %4
br label %11
11: ; preds = %36, %10
%12 = load %struct.hostent*, %struct.hostent** %3
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i32 0, i32 2
%14 = load i64*, i64** %13
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i64, i64* %14, i64 %16
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %11
%21 = load %struct.hostent*, %struct.hostent** %3
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = load %struct.hostent*, %struct.hostent** %3
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 2
%26 = load i64*, i64** %25
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %26, i64 %28
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to %struct.in_addr*
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i8* @inet_ntoa(i32 %33)
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %34)
br label %36
36: ; preds = %20
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %11
39: ; preds = %11
store i32 0, i32* %4
br label %40
40: ; preds = %58, %39
%41 = load %struct.hostent*, %struct.hostent** %3
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 1
%43 = load i8**, i8*** %42
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %61
49: ; preds = %40
%50 = load %struct.hostent*, %struct.hostent** %3
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 1
%52 = load i8**, i8*** %51
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %49
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %40
61: ; preds = %40
br label %62
62: ; preds = %61, %0
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8*, i8**, i64* }
@.str = [12 x i8] c"160.45.10.8\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"%s -> %s\0A\00"
@.str.2 = [20 x i8] c" also known as %s\0A\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 ([12 x i8], [12 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 %42, label %7
7: ; preds = %0
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 2
%9 = load i64*, i64** %8
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
br label %19
14: ; preds = %19, %7
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%16 = load i8**, i8*** %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %42, label %33
19: ; preds = %12, %19
%20 = phi i64 [ 0, %12 ], [ %28, %19 ]
%21 = phi i64 [ %10, %12 ], [ %31, %19 ]
%22 = load i8*, i8** %13
%23 = inttoptr i64 %21 to %struct.in_addr*
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %23, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i8* @inet_ntoa(i32 %25)
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %26)
%28 = add nuw i64 %20, 1
%29 = load i64*, i64** %8
%30 = getelementptr inbounds i64, i64* %29, i64 %28
%31 = load i64, i64* %30
%32 = icmp eq i64 %31, 0
br i1 %32, label %14, label %19
33: ; preds = %14, %33
%34 = phi i64 [ %37, %33 ], [ 0, %14 ]
%35 = phi i8* [ %40, %33 ], [ %17, %14 ]
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = add nuw i64 %34, 1
%38 = load i8**, i8*** %15
%39 = getelementptr inbounds i8*, i8** %38, i64 %37
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %33
42: ; preds = %33, %14, %0
ret i32 0
}