#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 */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *hostname = "www.baidu.com";
  char ip[100] = {};
  struct hostent *he = NULL;
  struct in_addr **addr_list;
  int i = 0;
  if ((he = gethostbyname(hostname)) == NULL) {
    herror("gethostbyname");
    return 1;
  }
  addr_list = (struct in_addr **)he->h_addr_list;
  for (i = 0; addr_list[i] != NULL; i++) {
    strcpy(ip, inet_ntoa(*addr_list[i]));
    printf("%s resolved to: %s\n", hostname, ip);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
movq   $0x0,-0x88(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    11db <main+0x7b>
lea    0xe44(%rip),%rdi
call   1080 <herror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1270 <main+0x110>
mov    -0x88(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x90(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x90(%rbp),%rax
movslq -0x94(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1269 <main+0x109>
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x90(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    -0x80(%rbp),%rdx
lea    0xdcc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11f6 <main+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe75(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11ee <main+0x9e>
mov    (%rax),%rbp
mov    0x0(%rbp),%rax
xor    %r14d,%r14d
test   %rax,%rax
je     1200 <main+0xb0>
add    $0x8,%rbp
mov    %rsp,%rbx
lea    0xe6a(%rip),%r15
lea    0xe47(%rip),%r12
nopl   0x0(%rax)
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    0x0(%rbp),%rax
add    $0x8,%rbp
test   %rax,%rax
jne    11c0 <main+0x70>
jmp    1200 <main+0xb0>
lea    0xe19(%rip),%rdi
call   1070 <herror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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