#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_addrtype;
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  struct hostent *host;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <addr>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  host = gethostbyname(argv[1]);
  if (host == NULL) {
    herror("gethostbyname() 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     11aa <main+0x4a>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <main+0x80>
lea    0xe45(%rip),%rdi
call   1070 <herror@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%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     1245 <main+0xe5>
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    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11fc <main+0x9c>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
mov    0x2d94(%rip),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
lea    0xdf7(%rip),%rax
cmp    %rdx,%rcx
cmove  %rax,%rsi
lea    0xdd8(%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     12da <main+0x17a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%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    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1281 <main+0x121>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    124f <main+0xef>
mov    0x8(%rsi),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1269 <main+0x109>
mov    %rax,%r14
mov    (%rax),%rsi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%rax
mov    (%rax),%rdx
test   %rdx,%rdx
je     11cd <main+0x6d>
mov    $0x1,%ebx
lea    0xe8f(%rip),%r15
nopl   0x0(%rax)
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    11b0 <main+0x50>
mov    0x10(%r14),%rax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
lea    0xe7a(%rip),%rax
lea    0xe7b(%rip),%rsi
cmove  %rax,%rsi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r14),%rax
mov    (%rax),%rax
test   %rax,%rax
je     1247 <main+0xe7>
mov    $0x1,%ebx
lea    0xe5a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
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    1220 <main+0xc0>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd9e(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1275 <main+0x115>
lea    0xda2(%rip),%rdi
call   1070 <herror@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

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