#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 /*<<< orphan*/ s_addr;
};
struct hostent {
  char *h_name;
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ assert(struct hostent *);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  struct hostent *host;
  struct in_addr ip;
  host = gethostbyname("www.baidu.com");
  assert(host);
  printf("h_name: %s\n", host->h_name);
  bcopy(host->h_addr, &(ip.s_addr), host->h_length);
  printf("IP: %s\n", inet_ntoa(ip));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%edi
lea    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
call   1070 <bcopy@plt>
mov    -0x20(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <assert@plt>
mov    (%rbx),%rsi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%edi
lea    0x8(%rsp),%rsi
call   1070 <bcopy@plt>
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i32, i32 }
%struct.in_addr = type { i32 }
@.str = [14 x i8] c"www.baidu.com\00"
@.str.1 = [12 x i8] c"h_name: %s\0A\00"
@.str.2 = [8 x i8] c"IP: %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 %struct.in_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %8, %struct.hostent** %6
%9 = load %struct.hostent*, %struct.hostent** %6
%10 = call i32 @assert(%struct.hostent* %9)
%11 = load %struct.hostent*, %struct.hostent** %6
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load %struct.hostent*, %struct.hostent** %6
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i32 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%19 = load %struct.hostent*, %struct.hostent** %6
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @bcopy(i32 %17, i32* %18, i32 %21)
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i8* @inet_ntoa(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %25)
ret i32 0
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i8*, i32, i32 }
@.str = [14 x i8] c"www.baidu.com\00"
@.str.1 = [12 x i8] c"h_name: %s\0A\00"
@.str.2 = [8 x i8] c"IP: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.in_addr
%4 = bitcast %struct.in_addr* %3 to i8*
%5 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @assert(%struct.hostent* %5)
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 2
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 @bcopy(i32 %11, i32* %12, i32 %14)
%16 = load i32, i32* %12
%17 = call i8* @inet_ntoa(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %17)
ret i32 0
}