#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 *h_name;
  int h_addrtype;
  int h_length;
  scalar_t__ *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 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;
  }
  printf("Informazioni circa il nodo: %s\n", ind_alphanum);
  ind = *((in_addr_t *)(host_info->h_addr_list[0]));
  printf("h_name     - nome ufficiale: ");
  for (i = 0; host_info->h_name[i] != 0; i++)
    printf("%c", host_info->h_name[i]);
  printf("\n");
  printf("h_addrtype - tipo di indirizzo: %d\n", host_info->h_addrtype);
  printf("h_length   - dimensioni indirizzo: %d byte\n", host_info->h_length);
  printf("h_addr_list- lista degli indirizzi (IP 32bit): %u\n", ind);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    124c <main+0x11c>
mov    -0x20(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11f7 <main+0xc7>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <main+0x88>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11fe <main+0xbe>
mov    %rax,%rbx
lea    0xeb7(%rip),%rdi
lea    0xe96(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rax
mov    (%rax),%rax
mov    (%rax),%r14d
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rax
mov    (%rax),%edi
test   %edi,%edi
je     11b3 <main+0x73>
mov    $0x4,%ebp
nopw   0x0(%rax,%rax,1)
call   1030 <putchar@plt>
mov    (%rbx),%rax
mov    (%rax,%rbp,1),%edi
add    $0x4,%rbp
test   %edi,%edi
jne    11a0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rbx),%esi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe07(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    11f9 <main+0xb9>

LLVM IR (-O0):
%struct.hostent = type { i32*, i32, i32, i64* }
@.str = [12 x i8] c"www.lwn.com\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [32 x i8] c"Informazioni circa il nodo: %s\0A\00"
@.str.3 = [30 x i8] c"h_name - nome ufficiale: \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [36 x i8] c"h_addrtype - tipo di indirizzo: %d\0A\00"
@.str.7 = [44 x i8] c"h_length - dimensioni indirizzo: %d byte\0A\00"
@.str.8 = [51 x i8] c"h_addr_list- lista degli indirizzi (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*
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
%10 = load i8*, i8** %7
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %9
%12 = load %struct.hostent*, %struct.hostent** %9
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = 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 %61
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load %struct.hostent*, %struct.hostent** %9
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 3
%21 = load i64*, i64** %20
%22 = getelementptr inbounds i64, i64* %21, i64 0
%23 = load i64, i64* %22
%24 = inttoptr i64 %23 to i32*
%25 = load i32, i32* %24
store i32 %25, i32* %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %27
27: ; preds = %45, %16
%28 = load %struct.hostent*, %struct.hostent** %9
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 0
%30 = load i32*, i32** %29
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %27
%37 = load %struct.hostent*, %struct.hostent** %9
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 0
%39 = load i32*, i32** %38
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %27
48: ; preds = %27
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%50 = load %struct.hostent*, %struct.hostent** %9
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = load %struct.hostent*, %struct.hostent** %9
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %54, i32 0, i32 2
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %8
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i32 %58)
%60 = load i32, i32* @EXIT_SUCCESS
store i32 %60, i32* %3
br label %61
61: ; preds = %48, %14
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
%struct.hostent = type { i32*, i32, i32, i64* }
@.str = [12 x i8] c"www.lwn.com\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [32 x i8] c"Informazioni circa il nodo: %s\0A\00"
@.str.3 = [30 x i8] c"h_name - nome ufficiale: \00"
@.str.6 = [36 x i8] c"h_addrtype - tipo di indirizzo: %d\0A\00"
@.str.7 = [44 x i8] c"h_length - dimensioni indirizzo: %d byte\0A\00"
@.str.8 = [51 x i8] c"h_addr_list- lista degli indirizzi (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 %38
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 3
%10 = load i64*, i64** %9
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%16 = load i32*, i32** %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %7, %19
%20 = phi i64 [ %23, %19 ], [ 0, %7 ]
%21 = phi i32 [ %26, %19 ], [ %17, %7 ]
%22 = tail call i32 @putchar(i32 %21)
%23 = add nuw i64 %20, 1
%24 = load i32*, i32** %15
%25 = getelementptr inbounds i32, i32* %24, i64 %23
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %19
28: ; preds = %19, %7
%29 = tail call i32 @putchar(i32 10)
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 2
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i32 %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i32 %13)
%37 = load i32, i32* @EXIT_SUCCESS
br label %38
38: ; preds = %28, %5
%39 = phi i32 [ -1, %5 ], [ %37, %28 ]
ret i32 %39
}