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

/* Variables and functions */
int EXIT_SUCCESS;
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int i;
  char *ind_alphanum = "www.lwn.com";
  in_addr_t ind;
  struct hostent *host_info;
  host_info = gethostbyname(ind_alphanum);
  if (host_info == NULL) {
    perror("gethostbyname");
    return -1;
  }
  ind = *((in_addr_t *)(host_info->h_addr_list[0]));
  printf("1° metodo - Indirizzo IP 32bit: %u\n", ind);
  for (i = 0; host_info->h_addr_list[i] != NULL; i++) {
    int indirizzo = *((int *)(host_info->h_addr_list[i]));
    printf("2° metodo - %d Indirizzo IP 32bit: %u\n", i, indirizzo);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1181 <main+0x51>
lea    0xe9c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <main+0xd0>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11f4 <main+0xc4>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <main+0x78>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11ae <main+0x7e>
mov    %rax,%r15
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%esi
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%rax
mov    (%rax),%rax
test   %rax,%rax
je     119f <main+0x6f>
lea    0xece(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%rax
mov    0x8(%rax,%rbx,8),%rax
add    $0x1,%rbx
test   %rax,%rax
jne    1180 <main+0x50>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    11a8 <main+0x78>

LLVM IR (-O0):
%struct.hostent = type { i32** }
@.str = [12 x i8] c"www.lwn.com\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [37 x i8] c"1\C2\B0 metodo - Indirizzo IP 32bit: %u\0A\00"
@.str.3 = [40 x i8] c"2\C2\B0 metodo - %d Indirizzo IP 32bit: %u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.hostent*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = load i8*, i8** %7
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %9
%13 = load %struct.hostent*, %struct.hostent** %9
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %52
17: ; preds = %2
%18 = load %struct.hostent*, %struct.hostent** %9
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 0
%20 = load i32**, i32*** %19
%21 = getelementptr inbounds i32*, i32** %20, i64 0
%22 = load i32*, i32** %21
%23 = load i32, i32* %22
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 0, i32* %6
br label %26
26: ; preds = %47, %17
%27 = load %struct.hostent*, %struct.hostent** %9
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 0
%29 = load i32**, i32*** %28
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32*, i32** %29, i64 %31
%33 = load i32*, i32** %32
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %50
35: ; preds = %26
%36 = load %struct.hostent*, %struct.hostent** %9
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 0
%38 = load i32**, i32*** %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32*, i32** %38, i64 %40
%42 = load i32*, i32** %41
%43 = load i32, i32* %42
store i32 %43, i32* %10
%44 = load i32, i32* %6
%45 = load i32, i32* %10
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %45)
br label %47
47: ; preds = %35
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %26
50: ; preds = %26
%51 = load i32, i32* @EXIT_SUCCESS
store i32 %51, i32* %3
br label %52
52: ; preds = %50, %15
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.hostent = type { i32** }
@.str = [12 x i8] c"www.lwn.com\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [37 x i8] c"1\C2\B0 metodo - Indirizzo IP 32bit: %u\0A\00"
@.str.3 = [40 x i8] c"2\C2\B0 metodo - %d Indirizzo IP 32bit: %u\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %29
7: ; preds = %2
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%9 = load i32**, i32*** %8
%10 = load i32*, i32** %9
%11 = load i32, i32* %10
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32**, i32*** %8
%14 = load i32*, i32** %13
%15 = icmp eq i32* %14, null
br i1 %15, label %27, label %16
16: ; preds = %7, %16
%17 = phi i64 [ %22, %16 ], [ 0, %7 ]
%18 = phi i32* [ %25, %16 ], [ %14, %7 ]
%19 = load i32, i32* %18
%20 = trunc i64 %17 to i32
%21 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %19)
%22 = add nuw i64 %17, 1
%23 = load i32**, i32*** %8
%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, %7
%28 = load i32, i32* @EXIT_SUCCESS
br label %29
29: ; preds = %27, %5
%30 = phi i32 [ -1, %5 ], [ %28, %27 ]
ret i32 %30
}