#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct in_addr {
  int dummy;
};
struct hostent {
  char *h_name;
  char **h_aliases;
  scalar_t__ h_addrtype;
  scalar_t__ *h_addr_list;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyaddr(char *, int, scalar_t__);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  struct hostent *host;
  struct sockaddr_in addr;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <addr>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  memset(&addr, 0, sizeof(addr));
  if (!inet_aton(argv[1], &addr.sin_addr))
    fprintf(stderr, "inet_aton() failed\n");
  host = gethostbyaddr((char *)&addr.sin_addr, 4, AF_INET);
  if (host == NULL) {
    herror("gethostbyaddr() failed");
    exit(EXIT_FAILURE);
  }
  printf("offical name: %s\n", host->h_name);
  for (i = 0; host->h_aliases[i]; ++i)
    printf("Aliases %d: %s\n", i + 1, host->h_aliases[i]);
  printf("Addres type: %s\n",
         (host->h_addrtype == AF_INET) ? "AF_INET" : "AF_INET6");
  for (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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cc <main+0x4c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <inet_aton@plt>
cmp    $0x0,%eax
jne    120d <main+0x8d>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x28(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%rdx
mov    $0x4,%esi
call   1090 <gethostbyaddr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124e <main+0xce>
lea    0xdeb(%rip),%rdi
call   1080 <herror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12b3 <main+0x133>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    126a <main+0xea>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
mov    0x2d26(%rip),%rax
mov    (%rax),%rdx
lea    0xdac(%rip),%rsi
lea    0xd9d(%rip),%rax
cmp    %rdx,%rcx
cmove  %rax,%rsi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1348 <main+0x1c8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x2c(%rbp),%esi
mov    %rax,%rdx
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12ef <main+0x16f>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    12b5 <main+0x135>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1070 <inet_aton@plt>
test   %eax,%eax
jne    11cd <main+0x4d>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2e14(%rip),%r12
mov    (%r12),%rdx
mov    %rsp,%rdi
mov    $0x4,%esi
call   1090 <gethostbyaddr@plt>
test   %rax,%rax
je     12d1 <main+0x151>
mov    %rax,%r14
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%rax
mov    (%rax),%rdx
test   %rdx,%rdx
je     123d <main+0xbd>
mov    $0x1,%ebx
lea    0xe35(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%rax
mov    (%rax,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1220 <main+0xa0>
mov    0x10(%r14),%rax
cmp    (%r12),%rax
lea    0xe24(%rip),%rax
lea    0xe25(%rip),%rsi
cmove  %rax,%rsi
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r14),%rax
mov    (%rax),%rax
test   %rax,%rax
je     12a7 <main+0x127>
mov    $0x1,%ebx
lea    0xe04(%rip),%r15
nopl   (%rax)
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r14),%rax
mov    (%rax,%rbx,8),%rax
add    $0x1,%rbx
test   %rax,%rax
jne    1280 <main+0x100>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd38(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12dd <main+0x15d>
lea    0xd4e(%rip),%rdi
call   1080 <herror@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i64, i64* }
%struct.sockaddr_in = type { i32 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <addr>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"inet_aton() failed\0A\00"
@AF_INET = global i64 0
@.str.2 = [23 x i8] c"gethostbyaddr() failed\00"
@.str.3 = [18 x i8] c"offical name: %s\0A\00"
@.str.4 = [16 x i8] c"Aliases %d: %s\0A\00"
@.str.5 = [17 x i8] c"Addres type: %s\0A\00"
@.str.6 = [8 x i8] c"AF_INET\00"
@.str.7 = [9 x i8] c"AF_INET6\00"
@.str.8 = [16 x i8] c"IP addr %d: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
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 %19
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 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 4)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%25 = call i32 @inet_aton(i8* %23, i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %19
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%32 = bitcast i32* %31 to i8*
%33 = load i64, i64* @AF_INET
%34 = call %struct.hostent* @gethostbyaddr(i8* %32, i32 4, i64 %33)
store %struct.hostent* %34, %struct.hostent** %7
%35 = load %struct.hostent*, %struct.hostent** %7
%36 = icmp eq %struct.hostent* %35, null
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = call i32 @herror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = load %struct.hostent*, %struct.hostent** %7
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %44)
store i32 0, i32* %6
br label %46
46: ; preds = %66, %41
%47 = load %struct.hostent*, %struct.hostent** %7
%48 = getelementptr inbounds %struct.hostent, %struct.hostent* %47, i32 0, i32 1
%49 = load i8**, i8*** %48
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %69
55: ; preds = %46
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
%58 = load %struct.hostent*, %struct.hostent** %7
%59 = getelementptr inbounds %struct.hostent, %struct.hostent* %58, i32 0, i32 1
%60 = load i8**, i8*** %59
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %57, i8* %64)
br label %66
66: ; preds = %55
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %46
69: ; preds = %46
%70 = load %struct.hostent*, %struct.hostent** %7
%71 = getelementptr inbounds %struct.hostent, %struct.hostent* %70, i32 0, i32 2
%72 = load i64, i64* %71
%73 = load i64, i64* @AF_INET
%74 = icmp eq i64 %72, %73
%75 = zext i1 %74 to i64
%76 = select i1 %74, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %76)
store i32 0, i32* %6
br label %78
78: ; preds = %102, %69
%79 = load %struct.hostent*, %struct.hostent** %7
%80 = getelementptr inbounds %struct.hostent, %struct.hostent* %79, i32 0, i32 3
%81 = load i64*, i64** %80
%82 = load i32, i32* %6
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i64, i64* %81, i64 %83
%85 = load i64, i64* %84
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %105
87: ; preds = %78
%88 = load i32, i32* %6
%89 = add nsw i32 %88, 1
%90 = load %struct.hostent*, %struct.hostent** %7
%91 = getelementptr inbounds %struct.hostent, %struct.hostent* %90, i32 0, i32 3
%92 = load i64*, i64** %91
%93 = load i32, i32* %6
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i64, i64* %92, i64 %94
%96 = load i64, i64* %95
%97 = inttoptr i64 %96 to %struct.in_addr*
%98 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %97, i32 0, i32 0
%99 = load i32, i32* %98
%100 = call i8* @inet_ntoa(i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %89, i8* %100)
br label %102
102: ; preds = %87
%103 = load i32, i32* %6
%104 = add nsw i32 %103, 1
store i32 %104, i32* %6
br label %78
105: ; preds = %78
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i8*, i8**, i64, i64* }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <addr>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"inet_aton() failed\0A\00"
@AF_INET = global i64 0
@.str.2 = [23 x i8] c"gethostbyaddr() failed\00"
@.str.3 = [18 x i8] c"offical name: %s\0A\00"
@.str.4 = [16 x i8] c"Aliases %d: %s\0A\00"
@.str.5 = [17 x i8] c"Addres type: %s\0A\00"
@.str.6 = [8 x i8] c"AF_INET\00"
@.str.7 = [9 x i8] c"AF_INET6\00"
@.str.8 = [16 x i8] c"IP addr %d: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 4)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%17 = call i32 @inet_aton(i8* %15, i32* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %12
%23 = load i64, i64* @AF_INET
%24 = call %struct.hostent* @gethostbyaddr(i8* %4, i32 4, i64 %23)
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = call i32 @herror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 1
%35 = load i8**, i8*** %34
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %48, label %38
38: ; preds = %30, %38
%39 = phi i64 [ %41, %38 ], [ 0, %30 ]
%40 = phi i8* [ %46, %38 ], [ %36, %30 ]
%41 = add nuw nsw i64 %39, 1
%42 = trunc i64 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %42, i8* %40)
%44 = load i8**, i8*** %34
%45 = getelementptr inbounds i8*, i8** %44, i64 %41
%46 = load i8*, i8** %45
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %38
48: ; preds = %38, %30
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 2
%50 = load i64, i64* %49
%51 = load i64, i64* @AF_INET
%52 = icmp eq i64 %50, %51
%53 = select i1 %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 3
%56 = load i64*, i64** %55
%57 = load i64, i64* %56
%58 = icmp eq i64 %57, 0
br i1 %58, label %73, label %59
59: ; preds = %48, %59
%60 = phi i64 [ %62, %59 ], [ 0, %48 ]
%61 = phi i64 [ %71, %59 ], [ %57, %48 ]
%62 = add nuw i64 %60, 1
%63 = inttoptr i64 %61 to %struct.in_addr*
%64 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %63, i64 0, i32 0
%65 = load i32, i32* %64
%66 = call i8* @inet_ntoa(i32 %65)
%67 = trunc i64 %62 to i32
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %67, i8* %66)
%69 = load i64*, i64** %55
%70 = getelementptr inbounds i64, i64* %69, i64 %62
%71 = load i64, i64* %70
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %59
73: ; preds = %59, %48
ret i32 0
}