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

/* Variables and functions */
int EXIT_FAILURE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int resolve(const char *name) {
  fprintf(stdout, "Host: %s\n", name);
  struct hostent *h = gethostbyname(name);
  if (0 == h) {
    fprintf(stderr, "Unable to resolve host '%s'\n", name);
    return EXIT_FAILURE;
  }
  if (h->h_aliases[0] != 0) {
    fprintf(stdout, "Alias(es):\n");
  }
  int i = 0;
  for (char *alias = h->h_aliases[i]; alias != 0; i++) {
    fprintf(stdout, "%s\n", alias);
  }
  if (h->h_addr_list[0] != 0) {
    fprintf(stdout, "IP(s):\n");
  }
  char ip[INET6_ADDRSTRLEN + 1];
  ip[INET6_ADDRSTRLEN] = '\0';
  struct in_addr **addr_list = (struct in_addr **)h->h_addr_list;
  for (i = 0; addr_list[i] != 0; i++) {
    strcpy(ip, inet_ntoa(*addr_list[i]));
    fprintf(stdout, "%s\n", ip);
  }
  return 0;
}


x86 assembly (clang, -O0):
<resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11ac <resolve+0x6c>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <resolve+0x1c5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     11d4 <resolve+0x94>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1222 <resolve+0xe2>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ee <resolve+0xae>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
cmpq   $0x0,(%rax)
je     124b <resolve+0x10b>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x48(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x38(%rbp)
mov    0x2d65(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12f7 <resolve+0x1b7>
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rdx
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    129d <resolve+0x15d>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e70(%rip),%r15
mov    (%r15),%edi
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11d2 <resolve+0x92>
mov    %rax,%r14
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     11fa <resolve+0xba>
mov    (%r15),%edi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
je     11fa <resolve+0xba>
mov    (%r15),%edi
lea    0xe5b(%rip),%r14
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11c0 <resolve+0x80>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
jmp    1292 <resolve+0x152>
mov    0x8(%r14),%rax
cmpq   $0x0,(%rax)
je     1215 <resolve+0xd5>
mov    (%r15),%edi
lea    0xe25(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%r12
mov    0x2dc9(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%r13
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
movslq (%rax),%rax
movb   $0x0,(%rax,%r13,1)
mov    0x8(%r14),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     128d <resolve+0x14d>
add    $0x8,%rbx
lea    0xdb2(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    1260 <resolve+0x120>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8**, i64* }
%struct.in_addr = type { i32 }
@stdout = global i32 0
@.str = [10 x i8] c"Host: %s\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Unable to resolve host '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"Alias(es):\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [8 x i8] c"IP(s):\0A\00"
@INET6_ADDRSTRLEN = global i32 0
define i32 @resolve(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.hostent*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.in_addr**
store i8* %0, i8** %3
%10 = load i32, i32* @stdout
%11 = load i8*, i8** %3
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %3
%14 = call %struct.hostent* @gethostbyname(i8* %13)
store %struct.hostent* %14, %struct.hostent** %4
%15 = load %struct.hostent*, %struct.hostent** %4
%16 = icmp eq %struct.hostent* null, %15
br i1 %16, label %17, label %22
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %2
br label %97
22: ; preds = %1
%23 = load %struct.hostent*, %struct.hostent** %4
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i8**, i8*** %24
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %29, %22
store i32 0, i32* %5
%33 = load %struct.hostent*, %struct.hostent** %4
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i32 0, i32 0
%35 = load i8**, i8*** %34
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
store i8* %39, i8** %6
br label %40
40: ; preds = %47, %32
%41 = load i8*, i8** %6
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = load i32, i32* @stdout
%45 = load i8*, i8** %6
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %40
50: ; preds = %40
%51 = load %struct.hostent*, %struct.hostent** %4
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 1
%53 = load i64*, i64** %52
%54 = getelementptr inbounds i64, i64* %53, i64 0
%55 = load i64, i64* %54
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* @stdout
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %57, %50
%61 = load i32, i32* @INET6_ADDRSTRLEN
%62 = add nsw i32 %61, 1
%63 = zext i32 %62 to i64
%64 = call i8* @llvm.stacksave()
store i8* %64, i8** %7
%65 = alloca i8, i64 %63
store i64 %63, i64* %8
%66 = load i32, i32* @INET6_ADDRSTRLEN
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 0, i8* %68
%69 = load %struct.hostent*, %struct.hostent** %4
%70 = getelementptr inbounds %struct.hostent, %struct.hostent* %69, i32 0, i32 1
%71 = load i64*, i64** %70
%72 = bitcast i64* %71 to %struct.in_addr**
store %struct.in_addr** %72, %struct.in_addr*** %9
store i32 0, i32* %5
br label %73
73: ; preds = %92, %60
%74 = load %struct.in_addr**, %struct.in_addr*** %9
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %74, i64 %76
%78 = load %struct.in_addr*, %struct.in_addr** %77
%79 = icmp ne %struct.in_addr* %78, null
br i1 %79, label %80, label %95
80: ; preds = %73
%81 = load %struct.in_addr**, %struct.in_addr*** %9
%82 = load i32, i32* %5
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %81, i64 %83
%85 = load %struct.in_addr*, %struct.in_addr** %84
%86 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %85, i32 0, i32 0
%87 = load i32, i32* %86
%88 = call i32 @inet_ntoa(i32 %87)
%89 = call i32 @strcpy(i8* %65, i32 %88)
%90 = load i32, i32* @stdout
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %65)
br label %92
92: ; preds = %80
%93 = load i32, i32* %5
%94 = add nsw i32 %93, 1
store i32 %94, i32* %5
br label %73
95: ; preds = %73
store i32 0, i32* %2
%96 = load i8*, i8** %7
br label %97
97: ; preds = %95, %17
%98 = load i32, i32* %2
ret i32 %98
}

LLVM IR (-O2):
%struct.hostent = type { i8**, i64* }
%struct.in_addr = type { i32 }
@stdout = global i32 0
@.str = [10 x i8] c"Host: %s\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Unable to resolve host '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"Alias(es):\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [8 x i8] c"IP(s):\0A\00"
@INET6_ADDRSTRLEN = global i32 0
define i32 @resolve(i8* %0) {
%2 = load i32, i32* @stdout
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call %struct.hostent* @gethostbyname(i8* %0)
%5 = icmp eq %struct.hostent* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @EXIT_FAILURE
br label %62
10: ; preds = %1
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 0
%12 = load i8**, i8*** %11
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %24, label %15
15: ; preds = %10
%16 = load i32, i32* @stdout
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%18 = load i8**, i8*** %11
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = load i32, i32* @stdout
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %29
24: ; preds = %10, %15
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 1
%26 = load i64*, i64** %25
%27 = load i64, i64* %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %35, label %32
29: ; preds = %29, %21
%30 = load i32, i32* @stdout
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %29
32: ; preds = %24
%33 = load i32, i32* @stdout
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %32, %24
%36 = load i32, i32* @INET6_ADDRSTRLEN
%37 = add nsw i32 %36, 1
%38 = zext i32 %37 to i64
%39 = tail call i8* @llvm.stacksave()
%40 = alloca i8, i64 %38
%41 = load i32, i32* @INET6_ADDRSTRLEN
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
%44 = bitcast i64** %25 to %struct.in_addr***
%45 = load %struct.in_addr**, %struct.in_addr*** %44
%46 = load %struct.in_addr*, %struct.in_addr** %45
%47 = icmp eq %struct.in_addr* %46, null
br i1 %47, label %61, label %48
48: ; preds = %35, %48
%49 = phi i64 [ %57, %48 ], [ 0, %35 ]
%50 = phi %struct.in_addr* [ %59, %48 ], [ %46, %35 ]
%51 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %50, i64 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @inet_ntoa(i32 %52)
%54 = call i32 @strcpy(i8* %40, i32 %53)
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%57 = add nuw i64 %49, 1
%58 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %45, i64 %57
%59 = load %struct.in_addr*, %struct.in_addr** %58
%60 = icmp eq %struct.in_addr* %59, null
br i1 %60, label %61, label %48
61: ; preds = %48, %35
br label %62
62: ; preds = %61, %6
%63 = phi i32 [ %9, %6 ], [ 0, %61 ]
ret i32 %63
}