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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct hostent *gethostbyaddr(char const *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char const *);
scalar_t__ inet_aton(char const *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  struct hostent *hostent;
  char **pp;
  struct in_addr addr;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <domain name or dotted-decimal>\n", argv[0]);
    exit(0);
  }
  if (inet_aton(argv[1], &addr)) {
    hostent = gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET);
  } else {
    hostent = gethostbyname(argv[1]);
  }
  printf("official hostname: %s\n", hostent->h_name);
  for (pp = hostent->h_aliases; *pp != NULL; pp++) {
    printf("alias: %s\n", *pp);
  }
  for (pp = hostent->h_addr_list; *pp != NULL; pp++) {
    addr.s_addr = ((struct in_addr *)*pp)->s_addr;
    printf("address: %s\n", inet_ntoa(addr));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x43>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <inet_aton@plt>
cmp    $0x0,%rax
je     11ee <main+0x7e>
lea    -0x28(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1080 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
jmp    11ff <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1250 <main+0xe0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    121e <main+0xae>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     129e <main+0x12e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    125c <main+0xec>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    124e <main+0xde>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1070 <inet_aton@plt>
test   %rax,%rax
je     11b2 <main+0x42>
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
call   1080 <gethostbyaddr@plt>
jmp    11bb <main+0x4b>
mov    0x8(%rbx),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%r14
mov    (%rax),%rsi
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%r14),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1204 <main+0x94>
add    $0x8,%rbx
lea    0xe5e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11f0 <main+0x80>
mov    0x10(%r14),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     1242 <main+0xd2>
add    $0x8,%rbx
lea    0xe32(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
call   1030 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    1220 <main+0xb0>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd9f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i8** }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"usage: %s <domain name or dotted-decimal>\0A\00"
@AF_INET = global i32 0
@.str.1 = [23 x i8] c"official hostname: %s\0A\00"
@.str.2 = [11 x i8] c"alias: %s\0A\00"
@.str.3 = [13 x i8] c"address: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca i8**
%8 = alloca %struct.in_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @inet_aton(i8* %21, %struct.in_addr* %8)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = bitcast %struct.in_addr* %8 to i8*
%26 = load i32, i32* @AF_INET
%27 = call %struct.hostent* @gethostbyaddr(i8* %25, i32 4, i32 %26)
store %struct.hostent* %27, %struct.hostent** %6
br label %33
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call %struct.hostent* @gethostbyname(i8* %31)
store %struct.hostent* %32, %struct.hostent** %6
br label %33
33: ; preds = %28, %24
%34 = load %struct.hostent*, %struct.hostent** %6
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load %struct.hostent*, %struct.hostent** %6
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 1
%40 = load i8**, i8*** %39
store i8** %40, i8*** %7
br label %41
41: ; preds = %49, %33
%42 = load i8**, i8*** %7
%43 = load i8*, i8** %42
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = load i8**, i8*** %7
%47 = load i8*, i8** %46
%48 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45
%50 = load i8**, i8*** %7
%51 = getelementptr inbounds i8*, i8** %50, i32 1
store i8** %51, i8*** %7
br label %41
52: ; preds = %41
%53 = load %struct.hostent*, %struct.hostent** %6
%54 = getelementptr inbounds %struct.hostent, %struct.hostent* %53, i32 0, i32 2
%55 = load i8**, i8*** %54
store i8** %55, i8*** %7
br label %56
56: ; preds = %71, %52
%57 = load i8**, i8*** %7
%58 = load i8*, i8** %57
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %74
60: ; preds = %56
%61 = load i8**, i8*** %7
%62 = load i8*, i8** %61
%63 = bitcast i8* %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 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
store i32 %65, i32* %66
%67 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i8* @inet_ntoa(i32 %68)
%70 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %60
%72 = load i8**, i8*** %7
%73 = getelementptr inbounds i8*, i8** %72, i32 1
store i8** %73, i8*** %7
br label %56
74: ; preds = %56
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8*, i8**, i8** }
@stderr = global i32 0
@.str = [43 x i8] c"usage: %s <domain name or dotted-decimal>\0A\00"
@AF_INET = global i32 0
@.str.1 = [23 x i8] c"official hostname: %s\0A\00"
@.str.2 = [11 x i8] c"alias: %s\0A\00"
@.str.3 = [13 x i8] c"address: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = bitcast %struct.in_addr* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @inet_aton(i8* %13, %struct.in_addr* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i32, i32* @AF_INET
%18 = call %struct.hostent* @gethostbyaddr(i8* %4, i32 4, i32 %17)
br label %22
19: ; preds = %11
%20 = load i8*, i8** %12
%21 = call %struct.hostent* @gethostbyname(i8* %20)
br label %22
22: ; preds = %19, %16
%23 = phi %struct.hostent* [ %18, %16 ], [ %21, %19 ]
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i64 0, i32 1
%28 = load i8**, i8*** %27
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %38, label %31
31: ; preds = %22, %31
%32 = phi i8* [ %36, %31 ], [ %29, %22 ]
%33 = phi i8** [ %35, %31 ], [ %28, %22 ]
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%35 = getelementptr inbounds i8*, i8** %33, i64 1
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %31
38: ; preds = %31, %22
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i64 0, i32 2
%40 = load i8**, i8*** %39
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %55, label %43
43: ; preds = %38
%44 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
br label %45
45: ; preds = %43, %45
%46 = phi i8* [ %41, %43 ], [ %53, %45 ]
%47 = phi i8** [ %40, %43 ], [ %52, %45 ]
%48 = bitcast i8* %46 to i32*
%49 = load i32, i32* %48
store i32 %49, i32* %44
%50 = call i8* @inet_ntoa(i32 %49)
%51 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds i8*, i8** %47, i64 1
%53 = load i8*, i8** %52
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %45
55: ; preds = %45, %38
ret i32 0
}