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

/* Variables and functions */
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 snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (2 != argc) {
    fprintf(stderr, "usage: %s hostname\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  char ip[1024] = {0};
  struct hostent *info;
  struct in_addr **addr_list;
  if ((info = gethostbyname(argv[1])) == NULL) {
    herror("gethostbyname");
    exit(EXIT_FAILURE);
  }
  addr_list = (struct in_addr **)info->h_addr_list;
  char *p = ip;
  int i = 0;
  for (i = 0; NULL != addr_list[i]; i++) {
    int off_set = 0;
    off_set = snprintf(p, 1024 - (p - ip), "%s ", inet_ntoa(*addr_list[i]));
    p += off_set;
  }
  fprintf(stdout, "%s resolve to %s\n", argv[1], ip);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     11c3 <main+0x53>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jne    120e <main+0x9e>
lea    0xe19(%rip),%rdi
call   1080 <herror@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x418(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x420(%rbp),%rcx
movslq -0x42c(%rbp),%rdx
xor    %eax,%eax
cmp    (%rcx,%rdx,8),%rax
je     12fb <main+0x18b>
movl   $0x0,-0x430(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x428(%rbp),%rcx
lea    -0x410(%rbp),%rax
sub    %rax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,-0x434(%rbp)
mov    -0x420(%rbp),%rax
movslq -0x42c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x440(%rbp),%rdi
mov    -0x434(%rbp),%esi
mov    %rax,%rcx
lea    0xd60(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x430(%rbp)
mov    -0x430(%rbp),%ecx
mov    -0x428(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x428(%rbp)
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1241 <main+0xd1>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0x410(%rbp),%rcx
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1236 <main+0xc6>
mov    %rsp,%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x8(%r14),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1252 <main+0xe2>
mov    (%rax),%r13
mov    0x0(%r13),%rax
test   %rax,%rax
je     1204 <main+0x94>
add    $0x8,%r13
lea    0xe5a(%rip),%r12
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%ebp
sub    %ebx,%ebp
add    $0x400,%ebp
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1040 <snprintf@plt>
cltq
add    %rax,%rbx
mov    0x0(%r13),%rax
add    $0x8,%r13
test   %rax,%rax
jne    11d0 <main+0x60>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe0e(%rip),%rsi
mov    %rsp,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdb7(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    125e <main+0xee>
lea    0xdbb(%rip),%rdi
call   1080 <herror@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s hostname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [4 x i8] c"%s \00"
@stdout = global i32 0
@.str.3 = [18 x i8] c"%s resolve to %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca %struct.hostent*
%8 = alloca %struct.in_addr**
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 2, %12
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = bitcast [1024 x i8]* %6 to i8*
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call %struct.hostent* @gethostbyname(i8* %26)
store %struct.hostent* %27, %struct.hostent** %7
%28 = icmp eq %struct.hostent* %27, null
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %22
%34 = load %struct.hostent*, %struct.hostent** %7
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 0
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to %struct.in_addr**
store %struct.in_addr** %37, %struct.in_addr*** %8
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8* %38, i8** %9
store i32 0, i32* %10
store i32 0, i32* %10
br label %39
39: ; preds = %68, %33
%40 = load %struct.in_addr**, %struct.in_addr*** %8
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %40, i64 %42
%44 = load %struct.in_addr*, %struct.in_addr** %43
%45 = icmp ne %struct.in_addr* null, %44
br i1 %45, label %46, label %71
46: ; preds = %39
store i32 0, i32* %11
%47 = load i8*, i8** %9
%48 = load i8*, i8** %9
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = sub nsw i64 1024, %52
%54 = trunc i64 %53 to i32
%55 = load %struct.in_addr**, %struct.in_addr*** %8
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %55, i64 %57
%59 = load %struct.in_addr*, %struct.in_addr** %58
%60 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i8* @inet_ntoa(i32 %61)
%63 = call i32 @snprintf(i8* %47, i32 %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %62)
store i32 %63, i32* %11
%64 = load i32, i32* %11
%65 = load i8*, i8** %9
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %65, i64 %66
store i8* %67, i8** %9
br label %68
68: ; preds = %46
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %39
71: ; preds = %39
%72 = load i32, i32* @stdout
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%77 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %76)
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s hostname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [4 x i8] c"%s \00"
@stdout = global i32 0
@.str.3 = [18 x i8] c"%s resolve to %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %11
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%23 = load i64, i64* %22
%24 = inttoptr i64 %23 to %struct.in_addr**
%25 = load %struct.in_addr*, %struct.in_addr** %24
%26 = icmp eq %struct.in_addr* %25, null
br i1 %26, label %47, label %27
27: ; preds = %21
%28 = ptrtoint [1024 x i8]* %3 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 0, %27 ], [ %43, %29 ]
%31 = phi %struct.in_addr* [ %25, %27 ], [ %45, %29 ]
%32 = phi i8* [ %12, %27 ], [ %42, %29 ]
%33 = ptrtoint i8* %32 to i64
%34 = sub i64 %28, %33
%35 = trunc i64 %34 to i32
%36 = add i32 %35, 1024
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %31, i64 0, i32 0
%38 = load i32, i32* %37
%39 = call i8* @inet_ntoa(i32 %38)
%40 = call i32 @snprintf(i8* %32, i32 %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %32, i64 %41
%43 = add nuw i64 %30, 1
%44 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %24, i64 %43
%45 = load %struct.in_addr*, %struct.in_addr** %44
%46 = icmp eq %struct.in_addr* %45, null
br i1 %46, label %47, label %29
47: ; preds = %29, %21
%48 = load i32, i32* @stdout
%49 = load i8*, i8** %13
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %49, i8* %12)
ret i32 0
}