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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
scalar_t__ inet_aton(char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct hostent *answer;
  struct in_addr address, **addrptr;
  char **next;
  if (argc != 2) {
    fprintf(stderr, "only a single argument is supported\n");
    return 1;
  }
  if (inet_aton(argv[1], &address))
    answer = gethostbyaddr((char *)&address, sizeof(address), AF_INET);
  else
    answer = gethostbyname(argv[1]);
  if (!answer) {
    herror("error looking up host");
    return 1;
  }
  printf("Canonical hostname: %s\n", answer->h_name);
  if (answer->h_aliases[0]) {
    printf("Aliases:");
    for (next = answer->h_aliases; *next; next++)
      printf(" %s", *next);
    printf("\n");
  }
  printf("Addresses:");
  for (addrptr = (struct in_addr **)answer->h_addr_list; *addrptr; addrptr++)
    printf(" %s", inet_ntoa(**addrptr));
  printf("\n");
  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     11b1 <main+0x41>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1310 <main+0x1a0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <inet_aton@plt>
cmp    $0x0,%rax
je     11ec <main+0x7c>
lea    -0x20(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1090 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
jmp    11fd <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1220 <main+0xb0>
lea    0xe16(%rip),%rdi
call   1080 <herror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1310 <main+0x1a0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
cmpq   $0x0,(%rax)
je     12a3 <main+0x133>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     1295 <main+0x125>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    1261 <main+0xf1>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     12fb <main+0x18b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    12bd <main+0x14d>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11b8 <main+0x38>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1080 <inet_aton@plt>
test   %rax,%rax
je     11d2 <main+0x52>
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x4,%esi
call   10a0 <gethostbyaddr@plt>
jmp    11db <main+0x5b>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12b9 <main+0x139>
mov    0x8(%rbx),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%r15
test   %rax,%rax
je     12ad <main+0x12d>
mov    (%r15),%rsi
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r15),%rax
cmpq   $0x0,(%rax)
je     1250 <main+0xd0>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r15),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1246 <main+0xc6>
add    $0x8,%rbx
lea    0xe35(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1230 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe09(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r15),%rbp
mov    0x0(%rbp),%rax
test   %rax,%rax
je     12a1 <main+0x121>
add    $0x8,%rbp
lea    0xde3(%rip),%rbx
nopl   0x0(%rax)
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rax
add    $0x8,%rbp
test   %rax,%rax
jne    1280 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12bf <main+0x13f>
lea    0xd71(%rip),%rdi
call   1090 <herror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"only a single argument is supported\0A\00"
@AF_INET = global i32 0
@.str.1 = [22 x i8] c"error looking up host\00"
@.str.2 = [24 x i8] c"Canonical hostname: %s\0A\00"
@.str.3 = [9 x i8] c"Aliases:\00"
@.str.4 = [4 x i8] c" %s\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [11 x i8] c"Addresses:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.in_addr
%8 = alloca %struct.in_addr**
%9 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %86
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @inet_aton(i8* %18, %struct.in_addr* %7)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = bitcast %struct.in_addr* %7 to i8*
%23 = load i32, i32* @AF_INET
%24 = call %struct.hostent* @gethostbyaddr(i8* %22, i32 4, i32 %23)
store %struct.hostent* %24, %struct.hostent** %6
br label %30
25: ; preds = %15
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call %struct.hostent* @gethostbyname(i8* %28)
store %struct.hostent* %29, %struct.hostent** %6
br label %30
30: ; preds = %25, %21
%31 = load %struct.hostent*, %struct.hostent** %6
%32 = icmp ne %struct.hostent* %31, null
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @herror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %86
35: ; preds = %30
%36 = load %struct.hostent*, %struct.hostent** %6
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load %struct.hostent*, %struct.hostent** %6
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %40, i32 0, i32 1
%42 = load i8**, i8*** %41
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %64
46: ; preds = %35
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%48 = load %struct.hostent*, %struct.hostent** %6
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %48, i32 0, i32 1
%50 = load i8**, i8*** %49
store i8** %50, i8*** %9
br label %51
51: ; preds = %59, %46
%52 = load i8**, i8*** %9
%53 = load i8*, i8** %52
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %62
55: ; preds = %51
%56 = load i8**, i8*** %9
%57 = load i8*, i8** %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %55
%60 = load i8**, i8*** %9
%61 = getelementptr inbounds i8*, i8** %60, i32 1
store i8** %61, i8*** %9
br label %51
62: ; preds = %51
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %35
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%66 = load %struct.hostent*, %struct.hostent** %6
%67 = getelementptr inbounds %struct.hostent, %struct.hostent* %66, i32 0, i32 2
%68 = load i64, i64* %67
%69 = inttoptr i64 %68 to %struct.in_addr**
store %struct.in_addr** %69, %struct.in_addr*** %8
br label %70
70: ; preds = %81, %64
%71 = load %struct.in_addr**, %struct.in_addr*** %8
%72 = load %struct.in_addr*, %struct.in_addr** %71
%73 = icmp ne %struct.in_addr* %72, null
br i1 %73, label %74, label %84
74: ; preds = %70
%75 = load %struct.in_addr**, %struct.in_addr*** %8
%76 = load %struct.in_addr*, %struct.in_addr** %75
%77 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i8* @inet_ntoa(i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %74
%82 = load %struct.in_addr**, %struct.in_addr*** %8
%83 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %82, i32 1
store %struct.in_addr** %83, %struct.in_addr*** %8
br label %70
84: ; preds = %70
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %86
86: ; preds = %84, %33, %12
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8*, i8**, i64 }
@stderr = global i32 0
@.str = [37 x i8] c"only a single argument is supported\0A\00"
@AF_INET = global i32 0
@.str.1 = [22 x i8] c"error looking up host\00"
@.str.2 = [24 x i8] c"Canonical hostname: %s\0A\00"
@.str.3 = [9 x i8] c"Aliases:\00"
@.str.4 = [4 x i8] c" %s\00"
@.str.6 = [11 x i8] c"Addresses:\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 %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %66
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @inet_aton(i8* %11, %struct.in_addr* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i32, i32* @AF_INET
%16 = call %struct.hostent* @gethostbyaddr(i8* %4, i32 4, i32 %15)
br label %20
17: ; preds = %9
%18 = load i8*, i8** %10
%19 = call %struct.hostent* @gethostbyname(i8* %18)
br label %20
20: ; preds = %17, %14
%21 = phi %struct.hostent* [ %16, %14 ], [ %19, %17 ]
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @herror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %66
25: ; preds = %20
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 1
%30 = load i8**, i8*** %29
%31 = load i8*, i8** %30
%32 = icmp eq i8* %31, null
br i1 %32, label %47, label %33
33: ; preds = %25
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%35 = load i8**, i8*** %29
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %45, label %38
38: ; preds = %33, %38
%39 = phi i8* [ %43, %38 ], [ %36, %33 ]
%40 = phi i8** [ %42, %38 ], [ %35, %33 ]
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%42 = getelementptr inbounds i8*, i8** %40, i64 1
%43 = load i8*, i8** %42
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %38
45: ; preds = %38, %33
%46 = call i32 @putchar(i32 10)
br label %47
47: ; preds = %45, %25
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 2
%50 = load i64, i64* %49
%51 = inttoptr i64 %50 to %struct.in_addr**
%52 = load %struct.in_addr*, %struct.in_addr** %51
%53 = icmp eq %struct.in_addr* %52, null
br i1 %53, label %64, label %54
54: ; preds = %47, %54
%55 = phi %struct.in_addr* [ %62, %54 ], [ %52, %47 ]
%56 = phi %struct.in_addr** [ %61, %54 ], [ %51, %47 ]
%57 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %55, i64 0, i32 0
%58 = load i32, i32* %57
%59 = call i8* @inet_ntoa(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %56, i64 1
%62 = load %struct.in_addr*, %struct.in_addr** %61
%63 = icmp eq %struct.in_addr* %62, null
br i1 %63, label %64, label %54
64: ; preds = %54, %47
%65 = call i32 @putchar(i32 10)
br label %66
66: ; preds = %64, %23, %6
%67 = phi i32 [ 1, %6 ], [ 0, %64 ], [ 1, %23 ]
ret i32 %67
}