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

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *host, **names, **addrs;
  struct hostent *hostinfo;
  if (argc == 1) {
    char myname[256];
    gethostname(myname, 255);
    host = myname;
  } else
    host = argv[1];
  hostinfo = gethostbyname(host);
  if (!hostinfo) {
    fprintf(stderr, "cannot get info for host: %s\n", host);
    exit(1);
  }
  printf("results for host %s:\n", host);
  printf("Name: %s\n", hostinfo->h_name);
  printf("Aliases:");
  names = hostinfo->h_aliases;
  while (*names) {
    printf(" %s", *names);
    names++;
  }
  printf("\n");
  if (hostinfo->h_addrtype != AF_INET) {
    fprintf(stderr, "not an IP host!\n");
    exit(1);
  }
  addrs = hostinfo->h_addr_list;
  while (*addrs) {
    printf(" %s", inet_ntoa(*(struct in_addr *)*addrs));
    addrs++;
  }
  printf("\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a4 <main+0x44>
lea    -0x130(%rbp),%rdi
mov    $0xff,%esi
call   1070 <gethostname@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11b0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ed <main+0x8d>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1262 <main+0x102>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    122e <main+0xce>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2d69(%rip),%rcx
cmp    (%rcx),%rax
je     12a9 <main+0x149>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     12f3 <main+0x193>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    12b5 <main+0x155>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
cmp    $0x1,%edi
jne    1193 <main+0x23>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1080 <gethostname@plt>
jmp    1197 <main+0x27>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
jne    11c8 <main+0x58>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%r14
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rsi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1236 <main+0xc6>
add    $0x8,%rbx
lea    0xe35(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1220 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%r14),%rax
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%rax
jne    12a1 <main+0x131>
mov    0x18(%r14),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     1290 <main+0x120>
add    $0x8,%rbx
lea    0xde0(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    1270 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i64, i8** }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [30 x i8] c"cannot get info for host: %s\0A\00"
@.str.1 = [22 x i8] c"results for host %s:\0A\00"
@.str.2 = [10 x i8] c"Name: %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"
@AF_INET = global i64 0
@.str.6 = [17 x i8] c"not an IP host!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca %struct.hostent*
%10 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%15 = call i32 @gethostname(i8* %14, i32 255)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %16, i8** %6
br label %21
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
br label %21
21: ; preds = %17, %13
%22 = load i8*, i8** %6
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %9
%24 = load %struct.hostent*, %struct.hostent** %9
%25 = icmp ne %struct.hostent* %24, null
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %6
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i8*, i8** %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load %struct.hostent*, %struct.hostent** %9
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%39 = load %struct.hostent*, %struct.hostent** %9
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 1
%41 = load i8**, i8*** %40
store i8** %41, i8*** %7
br label %42
42: ; preds = %46, %31
%43 = load i8**, i8*** %7
%44 = load i8*, i8** %43
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i8**, i8*** %7
%48 = load i8*, i8** %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = load i8**, i8*** %7
%51 = getelementptr inbounds i8*, i8** %50, i32 1
store i8** %51, i8*** %7
br label %42
52: ; preds = %42
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%54 = load %struct.hostent*, %struct.hostent** %9
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %54, i32 0, i32 2
%56 = load i64, i64* %55
%57 = load i64, i64* @AF_INET
%58 = icmp ne i64 %56, %57
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %52
%64 = load %struct.hostent*, %struct.hostent** %9
%65 = getelementptr inbounds %struct.hostent, %struct.hostent* %64, i32 0, i32 3
%66 = load i8**, i8*** %65
store i8** %66, i8*** %8
br label %67
67: ; preds = %71, %63
%68 = load i8**, i8*** %8
%69 = load i8*, i8** %68
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %81
71: ; preds = %67
%72 = load i8**, i8*** %8
%73 = load i8*, i8** %72
%74 = bitcast i8* %73 to %struct.in_addr*
%75 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i8* @inet_ntoa(i32 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %77)
%79 = load i8**, i8*** %8
%80 = getelementptr inbounds i8*, i8** %79, i32 1
store i8** %80, i8*** %8
br label %67
81: ; preds = %67
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%83 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i64, i8** }
@stderr = global i32 0
@.str = [30 x i8] c"cannot get info for host: %s\0A\00"
@.str.1 = [22 x i8] c"results for host %s:\0A\00"
@.str.2 = [10 x i8] c"Name: %s\0A\00"
@.str.3 = [9 x i8] c"Aliases:\00"
@.str.4 = [4 x i8] c" %s\00"
@AF_INET = global i64 0
@.str.6 = [17 x i8] c"not an IP host!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = call i32 @gethostname(i8* %6, i32 255)
br label %11
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
br label %11
11: ; preds = %8, %5
%12 = phi i8* [ %6, %5 ], [ %10, %8 ]
%13 = call %struct.hostent* @gethostbyname(i8* %12)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %12)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%26 = load i8**, i8*** %25
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %36, label %29
29: ; preds = %19, %29
%30 = phi i8* [ %34, %29 ], [ %27, %19 ]
%31 = phi i8** [ %33, %29 ], [ %26, %19 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%33 = getelementptr inbounds i8*, i8** %31, i64 1
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %29
36: ; preds = %29, %19
%37 = call i32 @putchar(i32 10)
%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
br i1 %41, label %46, label %42
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 3
%48 = load i8**, i8*** %47
%49 = load i8*, i8** %48
%50 = icmp eq i8* %49, null
br i1 %50, label %61, label %51
51: ; preds = %46, %51
%52 = phi i8* [ %59, %51 ], [ %49, %46 ]
%53 = phi i8** [ %58, %51 ], [ %48, %46 ]
%54 = bitcast i8* %52 to i32*
%55 = load i32, i32* %54
%56 = call i8* @inet_ntoa(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds i8*, i8** %53, i64 1
%59 = load i8*, i8** %58
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %51
61: ; preds = %51, %46
%62 = call i32 @putchar(i32 10)
%63 = call i32 @exit(i32 0)
unreachable
}