#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_aliases;
  char **h_addr_list;
};
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getchar();
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int loop(void) {
  struct hostent *h;
  char *name;
  printf("Press any key to continue...");
  getchar();
  printf("\n");
  name = "www.facebook.com";
  h = gethostbyname(name);
  if (h == NULL) {
    fprintf(stderr, "error: gethostbyname\n");
  } else {
    char **aliases;
    char **addresses;
    aliases = h->h_aliases;
    while (*aliases != NULL) {
      printf("alias: %s\n", *aliases);
      aliases++;
    }
    addresses = h->h_addr_list;
    while (*addresses != NULL) {
      struct in_addr addr;
      memcpy(&addr.s_addr, *addresses, sizeof(in_addr_t));
      printf("addr: %s\n", inet_ntoa(addr));
      addresses++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c8 <loop+0x68>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1265 <loop+0x105>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1207 <loop+0xa7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    11d3 <loop+0x73>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1260 <loop+0x100>
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1213 <loop+0xb3>
jmp    1265 <loop+0x105>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe7e(%rip),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     1241 <loop+0xd1>
mov    %rax,%r14
mov    (%rax),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11e6 <loop+0x76>
add    $0x8,%rbx
lea    0xe7e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11d0 <loop+0x60>
mov    0x8(%r14),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1256 <loop+0xe6>
add    $0x8,%rbx
lea    0x8(%rsp),%r14
lea    0xe4d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1210 <loop+0xa0>
jmp    1256 <loop+0xe6>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hostent = type { i8**, i8** }
%struct.in_addr = type { i32 }
@.str = [29 x i8] c"Press any key to continue...\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [17 x i8] c"www.facebook.com\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"error: gethostbyname\0A\00"
@.str.4 = [11 x i8] c"alias: %s\0A\00"
@.str.5 = [10 x i8] c"addr: %s\0A\00"
define i32 @loop() {
%1 = alloca %struct.hostent*
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca %struct.in_addr
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @getchar()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %2
%9 = load i8*, i8** %2
%10 = call %struct.hostent* @gethostbyname(i8* %9)
store %struct.hostent* %10, %struct.hostent** %1
%11 = load %struct.hostent*, %struct.hostent** %1
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %50
16: ; preds = %0
%17 = load %struct.hostent*, %struct.hostent** %1
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i8**, i8*** %18
store i8** %19, i8*** %3
br label %20
20: ; preds = %24, %16
%21 = load i8**, i8*** %3
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8**, i8*** %3
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i8**, i8*** %3
%29 = getelementptr inbounds i8*, i8** %28, i32 1
store i8** %29, i8*** %3
br label %20
30: ; preds = %20
%31 = load %struct.hostent*, %struct.hostent** %1
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 1
%33 = load i8**, i8*** %32
store i8** %33, i8*** %4
br label %34
34: ; preds = %38, %30
%35 = load i8**, i8*** %4
%36 = load i8*, i8** %35
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%40 = load i8**, i8*** %4
%41 = load i8*, i8** %40
%42 = call i32 @memcpy(i32* %39, i8* %41, i32 4)
%43 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i8* @inet_ntoa(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i8**, i8*** %4
%48 = getelementptr inbounds i8*, i8** %47, i32 1
store i8** %48, i8*** %4
br label %34
49: ; preds = %34
br label %50
50: ; preds = %49, %13
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8**, i8** }
@.str = [29 x i8] c"Press any key to continue...\00"
@.str.2 = [17 x i8] c"www.facebook.com\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"error: gethostbyname\0A\00"
@.str.4 = [11 x i8] c"alias: %s\0A\00"
@.str.5 = [10 x i8] c"addr: %s\0A\00"
define i32 @loop() {
%1 = alloca %struct.in_addr
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = tail call i32 @putchar(i32 10)
%5 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %40
10: ; preds = %0
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%12 = load i8**, i8*** %11
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %22, label %15
15: ; preds = %10, %15
%16 = phi i8* [ %20, %15 ], [ %13, %10 ]
%17 = phi i8** [ %19, %15 ], [ %12, %10 ]
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%19 = getelementptr inbounds i8*, i8** %17, i64 1
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %15
22: ; preds = %15, %10
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%24 = load i8**, i8*** %23
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %40, label %27
27: ; preds = %22
%28 = bitcast %struct.in_addr* %1 to i8*
%29 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
br label %30
30: ; preds = %27, %30
%31 = phi i8* [ %25, %27 ], [ %38, %30 ]
%32 = phi i8** [ %24, %27 ], [ %37, %30 ]
%33 = call i32 @memcpy(i32* %29, i8* %31, i32 4)
%34 = load i32, i32* %29
%35 = call i8* @inet_ntoa(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds i8*, i8** %32, i64 1
%38 = load i8*, i8** %37
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %30
40: ; preds = %30, %22, %7
ret i32 0
}