#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*/ ETH_P_IP;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int setup_rx(void) {
  int fdr;
  fdr = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
  if (fdr == -1)
    error(1, errno, "socket r");
  return fdr;
}


x86 assembly (clang, -O0):
<setup_rx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    %eax,%edx
call   1050 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1192 <setup_rx+0x62>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe73(%rip),%rdx
call   1040 <error@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_rx>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eb6(%rip),%rax
mov    (%rax),%ebx
mov    0x2e9d(%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   1050 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117f <setup_rx+0x4f>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_IP = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"socket r\00"
define i32 @setup_rx() {
%1 = alloca i32
%2 = load i32, i32* @PF_PACKET
%3 = load i32, i32* @SOCK_RAW
%4 = load i32, i32* @ETH_P_IP
%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 %12
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = call i32 @error(i32 1, i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %0
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@ETH_P_IP = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"socket r\00"
define i32 @setup_rx() {
%1 = load i32, i32* @PF_PACKET
%2 = load i32, i32* @SOCK_RAW
%3 = load i32, i32* @ETH_P_IP
%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 %10
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = tail call i32 @error(i32 1, i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %0
ret i32 %5
}