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

/* Variables and functions */
struct hostent *gethostbyname(char const *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char const *argv[]) {
  if (argc != 2)
    return -1;
  struct hostent *host;
  host = gethostbyname(argv[1]);
  if (NULL == host)
    printf("Error!\n");
  int i = 0;
  while (host->h_addr_list[i] != NULL) {
    struct in_addr *a = (struct in_addr *)host->h_addr_list[i];
    printf("%s\n", inet_ntoa(*a));
    ++i;
  }
  return 0;
}


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)
je     115c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1187 <main+0x57>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e1 <main+0xb1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <main+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
cmp    $0x2,%edi
jne    118f <main+0x5f>
mov    0x8(%rsi),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115c <main+0x2c>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rax
mov    (%rax),%rax
xor    %r14d,%r14d
test   %rax,%rax
je     118f <main+0x5f>
mov    $0x8,%ebp
nop
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    (%rbx),%rax
mov    (%rax,%rbp,1),%rax
add    $0x8,%rbp
test   %rax,%rax
jne    1170 <main+0x40>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32** }
%struct.in_addr = type { i32 }
@.str = [8 x i8] c"Error!\0A\00"
@.str.1 = [4 x i8] c"%s\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
%8 = alloca %struct.in_addr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %48
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %6
%17 = load %struct.hostent*, %struct.hostent** %6
%18 = icmp eq %struct.hostent* null, %17
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
store i32 0, i32* %7
br label %22
22: ; preds = %31, %21
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i32**, i32*** %24
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32*, i32** %25, i64 %27
%29 = load i32*, i32** %28
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %47
31: ; preds = %22
%32 = load %struct.hostent*, %struct.hostent** %6
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 0
%34 = load i32**, i32*** %33
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32*, i32** %34, i64 %36
%38 = load i32*, i32** %37
%39 = bitcast i32* %38 to %struct.in_addr*
store %struct.in_addr* %39, %struct.in_addr** %8
%40 = load %struct.in_addr*, %struct.in_addr** %8
%41 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i8* @inet_ntoa(i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %22
47: ; preds = %22
store i32 0, i32* %3
br label %48
48: ; preds = %47, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.hostent = type { i32** }
@str = [7 x i8] c"Error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call %struct.hostent* @gethostbyname(i8* %6)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%13 = load i32**, i32*** %12
%14 = load i32*, i32** %13
%15 = icmp eq i32* %14, null
br i1 %15, label %27, label %16
16: ; preds = %11, %16
%17 = phi i64 [ %22, %16 ], [ 0, %11 ]
%18 = phi i32* [ %25, %16 ], [ %14, %11 ]
%19 = load i32, i32* %18
%20 = tail call i8* @inet_ntoa(i32 %19)
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
%22 = add nuw i64 %17, 1
%23 = load i32**, i32*** %12
%24 = getelementptr inbounds i32*, i32** %23, i64 %22
%25 = load i32*, i32** %24
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %16
27: ; preds = %16, %11, %2
%28 = phi i32 [ -1, %2 ], [ 0, %11 ], [ 0, %16 ]
ret i32 %28
}