#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 */
typedef int /*<<< orphan*/ temp;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int CreaSocket(char *Destinazione, int Porta) {
  struct sockaddr_in temp;
  struct hostent *h;
  int sock;
  int errore;
  temp.sin_family = AF_INET;
  temp.sin_port = htons(Porta);
  h = gethostbyname(Destinazione);
  if (h == 0) {
    printf("Gethostbyname fallito\n");
    exit(1);
  }
  bcopy(h->h_addr, &temp.sin_addr, h->h_length);
  sock = socket(AF_INET, SOCK_STREAM, 0);
  errore = connect(sock, (struct sockaddr *)&temp, sizeof(temp));
  return sock;
}


x86 assembly (clang, -O0):
<CreaSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c4 <CreaSocket+0x54>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreaSocket>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e68(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    %esi,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11de <CreaSocket+0x6e>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <bcopy@plt>
mov    0x0(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [23 x i8] c"Gethostbyname fallito\0A\00"
@SOCK_STREAM = global i32 0
define i32 @CreaSocket(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.hostent*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* %4
%12 = call i32 @htons(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i8*, i8** %3
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %6
%16 = load %struct.hostent*, %struct.hostent** %6
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load %struct.hostent*, %struct.hostent** %6
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%26 = load %struct.hostent*, %struct.hostent** %6
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @bcopy(i32 %24, i32* %25, i32 %28)
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%35 = call i32 @connect(i32 %33, %struct.sockaddr* %34, i32 12)
store i32 %35, i32* %8
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@str = [22 x i8] c"Gethostbyname fallito\00"
define i32 @CreaSocket(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %5, i32* %6
%7 = tail call i32 @htons(i32 %1)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %7, i32* %8
%9 = tail call %struct.hostent* @gethostbyname(i8* %0)
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @bcopy(i32 %16, i32* %17, i32 %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @connect(i32 %23, %struct.sockaddr* %24, i32 12)
ret i32 %23
}