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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *url = "www.baidu.com";
  struct hostent *phost;
  char **ppaddr;
  phost = gethostbyname(url);
  if (phost == NULL) {
    printf("get host error!\n");
    return -1;
  }
  char buff[48] = {0};
  for (ppaddr = phost->h_addr_list; *ppaddr != NULL; ppaddr++) {
    inet_ntop(AF_INET, *ppaddr, buff, sizeof(buff));
    printf("ip = %s\n", buff);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <main+0x4c>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <main+0xbd>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11f6 <main+0xb6>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x30,%ecx
call   1030 <inet_ntop@plt>
lea    -0x50(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <main+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeae(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11be <main+0x7e>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    (%rax),%rbx
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11ba <main+0x7a>
add    $0x8,%rbx
mov    0x2e65(%rip),%r12
mov    %rsp,%r15
lea    0xe81(%rip),%r14
nopl   (%rax)
mov    (%r12),%edi
mov    %r15,%rdx
mov    $0x30,%ecx
call   1030 <inet_ntop@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1190 <main+0x50>
xor    %eax,%eax
jmp    11cf <main+0x8f>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hostent = type { i8** }
@.str = [14 x i8] c"www.baidu.com\00"
@.str.1 = [17 x i8] c"get host error!\0A\00"
@AF_INET = global i32 0
@.str.2 = [9 x i8] c"ip = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.hostent*
%4 = alloca i8**
%5 = alloca [48 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %3
%8 = load %struct.hostent*, %struct.hostent** %3
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %33
12: ; preds = %0
%13 = bitcast [48 x i8]* %5 to i8*
%14 = load %struct.hostent*, %struct.hostent** %3
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i8**, i8*** %15
store i8** %16, i8*** %4
br label %17
17: ; preds = %29, %12
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load i32, i32* @AF_INET
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%26 = call i32 @inet_ntop(i32 %22, i8* %24, i8* %25, i32 48)
%27 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %21
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i32 1
store i8** %31, i8*** %4
br label %17
32: ; preds = %17
store i32 0, i32* %1
br label %33
33: ; preds = %32, %10
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
%struct.hostent = type { i8** }
@.str = [14 x i8] c"www.baidu.com\00"
@AF_INET = global i32 0
@.str.2 = [9 x i8] c"ip = %s\0A\00"
@str = [16 x i8] c"get host error!\00"
define i32 @main() {
%1 = alloca [48 x i8]
%2 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %0
%7 = getelementptr inbounds [48 x i8], [48 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%9 = load i8**, i8*** %8
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %6, %12
%13 = phi i8* [ %19, %12 ], [ %10, %6 ]
%14 = phi i8** [ %18, %12 ], [ %9, %6 ]
%15 = load i32, i32* @AF_INET
%16 = call i32 @inet_ntop(i32 %15, i8* %13, i8* %7, i32 48)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%18 = getelementptr inbounds i8*, i8** %14, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %12
21: ; preds = %12, %6
br label %22
22: ; preds = %21, %4
%23 = phi i32 [ -1, %4 ], [ 0, %21 ]
ret i32 %23
}