#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  int sin_family;
  int sin_port;
  TYPE_1__ sin_addr;
};
struct hostent {
  scalar_t__ *h_addr_list;
};
typedef int in_addr_t;

/* Variables and functions */
int AF_INET;
int EXIT_SUCCESS;
struct hostent *gethostbyname(char *);
int htons(int);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(void) {
  char *host_name = "www.lwn.com";
  int dominio = AF_INET;
  in_addr_t indirizzo = 0;
  int porta = 80;
  struct hostent *host_info = gethostbyname(host_name);
  indirizzo = *((in_addr_t *)host_info->h_addr_list[0]);
  struct sockaddr_in ind_trasporto;
  ind_trasporto.sin_family = dominio;
  ind_trasporto.sin_addr.s_addr = indirizzo;
  ind_trasporto.sin_port = htons(porta);
  printf("\t%u\t%u\t%u\n", ind_trasporto.sin_family,
         ind_trasporto.sin_addr.s_addr, ind_trasporto.sin_port);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x50,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%ebx
lea    0xebd(%rip),%rdi
call   1050 <gethostbyname@plt>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%ebp
mov    $0x50,%edi
call   1030 <htons@plt>
lea    0xeab(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [12 x i8] c"www.lwn.com\00"
@AF_INET = global i32 0
@.str.1 = [11 x i8] c"\09%u\09%u\09%u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.hostent*
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = load i32, i32* @AF_INET
store i32 %8, i32* %3
store i32 0, i32* %4
store i32 80, i32* %5
%9 = load i8*, i8** %2
%10 = call %struct.hostent* @gethostbyname(i8* %9)
store %struct.hostent* %10, %struct.hostent** %6
%11 = load %struct.hostent*, %struct.hostent** %6
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i32 0, i32 0
%13 = load i64*, i64** %12
%14 = getelementptr inbounds i64, i64* %13, i64 0
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to i32*
%17 = load i32, i32* %16
store i32 %17, i32* %4
%18 = load i32, i32* %3
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %4
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %5
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %30, i32 %32)
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
@.str = [12 x i8] c"www.lwn.com\00"
@AF_INET = global i32 0
@.str.1 = [11 x i8] c"\09%u\09%u\09%u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @AF_INET
%2 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%4 = load i64*, i64** %3
%5 = load i64, i64* %4
%6 = inttoptr i64 %5 to i32*
%7 = load i32, i32* %6
%8 = tail call i32 @htons(i32 80)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %7, i32 %8)
%10 = load i32, i32* @EXIT_SUCCESS
ret i32 %10
}