#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*/ tv;
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ do_bind(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ pair_udp_setfilter(int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int setup_sniffer(void) {
  struct timeval tv = {.tv_usec = 100 * 1000};
  int fd;
  fd = socket(PF_PACKET, SOCK_RAW, 0);
  if (fd == -1)
    error(1, errno, "socket p");
  if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)))
    error(1, errno, "setsockopt rcv timeout");
  pair_udp_setfilter(fd);
  do_bind(fd);
  return fd;
}


x86 assembly (clang, -O0):
<setup_sniffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xea2(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a1 <setup_sniffer+0x51>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe68(%rip),%rdx
call   1050 <error@plt>
mov    -0xc(%rbp),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11e9 <setup_sniffer+0x99>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe29(%rip),%rdx
call   1050 <error@plt>
mov    -0xc(%rbp),%edi
call   1040 <pair_udp_setfilter@plt>
mov    -0xc(%rbp),%edi
call   1060 <do_bind@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_sniffer>:
push   %rbx
sub    $0x10,%rsp
movl   $0x186a0,0x8(%rsp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1197 <setup_sniffer+0x47>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     11da <setup_sniffer+0x8a>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe39(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
mov    %ebx,%edi
call   1040 <pair_udp_setfilter@plt>
mov    %ebx,%edi
call   1060 <do_bind@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@__const.setup_sniffer.tv = %struct.timeval { i32 100000 }
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"socket p\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.1 = [23 x i8] c"setsockopt rcv timeout\00"
define i32 @setup_sniffer() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = bitcast %struct.timeval* %1 to i8*
%4 = load i32, i32* @PF_PACKET
%5 = load i32, i32* @SOCK_RAW
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%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* %2
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_RCVTIMEO
%16 = call i64 @setsockopt(i32 %13, i32 %14, i32 %15, %struct.timeval* %1, i32 4)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @errno
%20 = call i32 @error(i32 1, i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %12
%22 = load i32, i32* %2
%23 = call i32 @pair_udp_setfilter(i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @do_bind(i32 %24)
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@PF_PACKET = global i32 0
@SOCK_RAW = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"socket p\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.1 = [23 x i8] c"setsockopt rcv timeout\00"
define i32 @setup_sniffer() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 100000, i32* %3
%4 = load i32, i32* @PF_PACKET
%5 = load i32, i32* @SOCK_RAW
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = tail call i32 @error(i32 1, i32 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %0
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_RCVTIMEO
%14 = call i64 @setsockopt(i32 %6, i32 %12, i32 %13, %struct.timeval* %1, i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = call i32 @error(i32 1, i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %16, %11
%20 = call i32 @pair_udp_setfilter(i32 %6)
%21 = call i32 @do_bind(i32 %6)
ret i32 %6
}