#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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;
  }
  hostinfo = gethostbyname(host);
  if (hostinfo == NULL) {
    fprintf(stderr, "cannot get info for host: %s\n", host);
    exit(EXIT_FAILURE);
  }
  printf("results for host '%s':\n", host);
  printf("Name: %s\n", hostinfo->h_name);
  printf("Aliases:");
  names = hostinfo->h_aliases;
  while (names != NULL) {
    printf(" %s", *names);
    names++;
  }
  printf("\n");
  if (hostinfo->h_addrtype != AF_INET) {
    fprintf(stderr, "not an IP host!\n");
    exit(EXIT_FAILURE);
  }
  addrs = hostinfo->h_addr_list;
  while (*addrs != NULL) {
    printf(" %s", inet_ntoa(*(struct in_addr *)*addrs));
    addrs++;
  }
  printf("\n");
  return 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    11bb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
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    11fc <main+0x9c>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     126e <main+0x10e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    123d <main+0xdd>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x2d5d(%rip),%rcx
cmp    (%rcx),%rax
je     12b9 <main+0x159>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%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     1303 <main+0x1a3>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    12c5 <main+0x165>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
cmp    $0x1,%edi
jne    1193 <main+0x23>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%esi
call   1080 <gethostname@plt>
jmp    1197 <main+0x27>
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1279 <main+0x109>
mov    %rax,%r15
lea    0xe6c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%rsi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r15),%rbx
test   %rbx,%rbx
je     1203 <main+0x93>
lea    0xe5e(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x8,%rbx
jmp    11f0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%r15),%rax
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rax
jne    1295 <main+0x125>
mov    0x18(%r15),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     1260 <main+0xf0>
add    $0x8,%rbx
lea    0xe15(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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    1240 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12ac <main+0x13c>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%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"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 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, i32 1
store i8** %19, i8*** %5
%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 eq %struct.hostent* %24, null
br i1 %25, label %26, label %32
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 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %21
%33 = load i8*, i8** %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load %struct.hostent*, %struct.hostent** %9
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%40 = load %struct.hostent*, %struct.hostent** %9
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %40, i32 0, i32 1
%42 = load i8**, i8*** %41
store i8** %42, i8*** %7
br label %43
43: ; preds = %46, %32
%44 = load i8**, i8*** %7
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %52
46: ; preds = %43
%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 %43
52: ; preds = %43
%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 %64
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 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %52
%65 = load %struct.hostent*, %struct.hostent** %9
%66 = getelementptr inbounds %struct.hostent, %struct.hostent* %65, i32 0, i32 3
%67 = load i8**, i8*** %66
store i8** %67, i8*** %8
br label %68
68: ; preds = %72, %64
%69 = load i8**, i8*** %8
%70 = load i8*, i8** %69
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %82
72: ; preds = %68
%73 = load i8**, i8*** %8
%74 = load i8*, i8** %73
%75 = bitcast i8* %74 to %struct.in_addr*
%76 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %75, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i8* @inet_ntoa(i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %78)
%80 = load i8**, i8*** %8
%81 = getelementptr inbounds i8*, i8** %80, i32 1
store i8** %81, i8*** %8
br label %68
82: ; preds = %68
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

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"
@EXIT_FAILURE = global i32 0
@.str.1 = [24 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 %20
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 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %11
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%27 = load i8**, i8*** %26
%28 = icmp eq i8** %27, null
br i1 %28, label %34, label %29
29: ; preds = %20, %29
%30 = phi i8** [ %33, %29 ], [ %27, %20 ]
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds i8*, i8** %30, i64 1
br label %29
34: ; preds = %20
%35 = call i32 @putchar(i32 10)
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 2
%37 = load i64, i64* %36
%38 = load i64, i64* @AF_INET
%39 = icmp eq i64 %37, %38
br i1 %39, label %45, label %40
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 3
%47 = load i8**, i8*** %46
%48 = load i8*, i8** %47
%49 = icmp eq i8* %48, null
br i1 %49, label %60, label %50
50: ; preds = %45, %50
%51 = phi i8* [ %58, %50 ], [ %48, %45 ]
%52 = phi i8** [ %57, %50 ], [ %47, %45 ]
%53 = bitcast i8* %51 to i32*
%54 = load i32, i32* %53
%55 = call i8* @inet_ntoa(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = getelementptr inbounds i8*, i8** %52, i64 1
%58 = load i8*, i8** %57
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %50
60: ; preds = %50, %45
%61 = call i32 @putchar(i32 10)
ret i32 0
}