#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 */

/* Variables and functions */
int /*<<< orphan*/ AF_PACKET;
int /*<<< orphan*/ ETH_P_ALL;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int abrirSocketRaw(void) {
  int packet_socket = 0;
  packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  if (packet_socket == -1) {
    perror("Error al abrir el socket");
    exit(EXIT_FAILURE);
  }
  return packet_socket;
}


x86 assembly (clang, -O0):
<abrirSocketRaw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    %eax,%edx
call   1060 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11a9 <abrirSocketRaw+0x69>
lea    0xe6a(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abrirSocketRaw>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e86(%rip),%rax
mov    (%rax),%ebx
mov    0x2e95(%rip),%rax
mov    (%rax),%ebp
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <socket@plt>
cmp    $0xffffffff,%eax
je     117a <abrirSocketRaw+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str = [25 x i8] c"Error al abrir el socket\00"
@EXIT_FAILURE = global i32 0
define i32 @abrirSocketRaw() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @AF_PACKET
%3 = load i32, i32* @SOCK_RAW
%4 = load i32, i32* @ETH_P_ALL
%5 = call i32 @htons(i32 %4)
%6 = call i32 @socket(i32 %2, i32 %3, i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
@AF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_ALL = global i32 0
@.str = [25 x i8] c"Error al abrir el socket\00"
@EXIT_FAILURE = global i32 0
define i32 @abrirSocketRaw() {
%1 = load i32, i32* @AF_PACKET
%2 = load i32, i32* @SOCK_RAW
%3 = load i32, i32* @ETH_P_ALL
%4 = tail call i32 @htons(i32 %3)
%5 = tail call i32 @socket(i32 %1, i32 %2, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
ret i32 %5
}