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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: %s hostname\n", argv[0]);
    exit(-1);
  }
  struct hostent *hp = gethostbyname(argv[1]);
  if (hp == NULL) {
    printf("gethostbyname() failed\n");
  } else {
    printf("%s:\n", hp->h_name);
    unsigned int i = 0;
    while (hp->h_addr_list[i] != NULL) {
      printf("alias: %s , addr:%s\n", hp->h_aliases[i],
             inet_ntoa(*(struct in_addr *)(hp->h_addr_list[i])));
      i++;
    }
    printf("\n");
  }
}


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)
jge    117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ae <main+0x6e>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123a <main+0xfa>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x1c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     122c <main+0xec>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <main+0x8a>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1205 <main+0xa5>
mov    0x8(%rsi),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     11eb <main+0x8b>
mov    %rax,%r15
mov    (%rax),%rsi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r15),%rax
mov    (%rax),%rax
test   %rax,%rax
je     11df <main+0x7f>
lea    0xe73(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x8(%r15),%rcx
mov    (%rcx,%rbx,8),%r12
mov    (%rax),%edi
call   1050 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebx
mov    0x10(%r15),%rax
mov    (%rax,%rbx,8),%rax
test   %rax,%rax
jne    11b0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11f7 <main+0x97>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%rsi),%rsi
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i32** }
%struct.in_addr = type { i32 }
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@.str.1 = [24 x i8] c"gethostbyname() failed\0A\00"
@.str.2 = [5 x i8] c"%s:\0A\00"
@.str.3 = [21 x i8] c"alias: %s , addr:%s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call %struct.hostent* @gethostbyname(i8* %19)
store %struct.hostent* %20, %struct.hostent** %6
%21 = load %struct.hostent*, %struct.hostent** %6
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %63
25: ; preds = %16
%26 = load %struct.hostent*, %struct.hostent** %6
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 0, i32* %7
br label %30
30: ; preds = %39, %25
%31 = load %struct.hostent*, %struct.hostent** %6
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 2
%33 = load i32**, i32*** %32
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
%37 = load i32*, i32** %36
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %61
39: ; preds = %30
%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 = load i32, i32* %7
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = load %struct.hostent*, %struct.hostent** %6
%48 = getelementptr inbounds %struct.hostent, %struct.hostent* %47, i32 0, i32 2
%49 = load i32**, i32*** %48
%50 = load i32, i32* %7
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i32*, i32** %49, i64 %51
%53 = load i32*, i32** %52
%54 = bitcast i32* %53 to %struct.in_addr*
%55 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %57)
%59 = load i32, i32* %7
%60 = add i32 %59, 1
store i32 %60, i32* %7
br label %30
61: ; preds = %30
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %23
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32** }
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@.str.2 = [5 x i8] c"%s:\0A\00"
@.str.3 = [21 x i8] c"alias: %s , addr:%s\0A\00"
@str = [23 x i8] c"gethostbyname() failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call %struct.hostent* @gethostbyname(i8* %10)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %42
15: ; preds = %8
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 2
%20 = load i32**, i32*** %19
%21 = load i32*, i32** %20
%22 = icmp eq i32* %21, null
br i1 %22, label %40, label %23
23: ; preds = %15
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 1
br label %25
25: ; preds = %23, %25
%26 = phi i32* [ %21, %23 ], [ %38, %25 ]
%27 = phi i64 [ 0, %23 ], [ %36, %25 ]
%28 = load i8**, i8*** %24
%29 = getelementptr inbounds i8*, i8** %28, i64 %27
%30 = load i8*, i8** %29
%31 = load i32, i32* %26
%32 = tail call i8* @inet_ntoa(i32 %31)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %32)
%34 = add nuw nsw i64 %27, 1
%35 = load i32**, i32*** %19
%36 = and i64 %34, 4294967295
%37 = getelementptr inbounds i32*, i32** %35, i64 %36
%38 = load i32*, i32** %37
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %25
40: ; preds = %25, %15
%41 = tail call i32 @putchar(i32 10)
br label %42
42: ; preds = %40, %13
ret i32 0
}