#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*/ tp;
struct tpacket_req3 {
  int tp_block_size;
  int tp_block_nr;
  int tp_frame_size;
  int tp_frame_nr;
  int tp_retire_blk_tov;
};
typedef int /*<<< orphan*/ optval;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ PACKET_RX_RING;
int /*<<< orphan*/ PACKET_VERSION;
int /*<<< orphan*/ SOL_PACKET;
int TPACKET_V3;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpagesize();
int /*<<< orphan*/ memset(struct tpacket_req3 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
void timer_schedule(int handle, int timeout) {
  int optval = TPACKET_V3;
  int rv =
      setsockopt(handle, SOL_PACKET, PACKET_VERSION, &optval, sizeof(optval));
  if (rv != 0) {
    perror("setsockopt(PACKET_VERSION)");
    exit(EXIT_FAILURE);
  }
  struct tpacket_req3 tp;
  memset(&tp, 0, sizeof(tp));
  tp.tp_block_size = 1 * getpagesize();
  tp.tp_block_nr = 1;
  tp.tp_frame_size = getpagesize();
  tp.tp_frame_nr = 1;
  tp.tp_retire_blk_tov = timeout;
  rv = setsockopt(handle, SOL_PACKET, PACKET_RX_RING, (void *)&tp, sizeof(tp));
  if (rv != 0) {
    perror("setsockopt(PACKET_RX_RING)");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<timer_schedule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11b5 <timer_schedule+0x65>
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    $0x0,%al
call   1060 <getpagesize@plt>
shl    $0x0,%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x14,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     123b <timer_schedule+0xeb>
lea    0xdf3(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_schedule>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e7e(%rip),%r15
mov    (%r15),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jne    11fb <timer_schedule+0xab>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
xor    %eax,%eax
call   1060 <getpagesize@plt>
mov    %eax,0x10(%rsp)
movl   $0x1,0x14(%rsp)
xor    %eax,%eax
call   1060 <getpagesize@plt>
mov    %eax,0x18(%rsp)
movl   $0x1,0x1c(%rsp)
mov    %ebp,0x20(%rsp)
mov    (%r15),%esi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x14,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jne    1204 <timer_schedule+0xb4>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfe(%rip),%rdi
jmp    120b <timer_schedule+0xbb>
lea    0xe10(%rip),%rdi
call   1050 <perror@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.tpacket_req3 = type { i32, i32, i32, i32, i32 }
@TPACKET_V3 = global i32 0
@SOL_PACKET = global i32 0
@PACKET_VERSION = global i32 0
@.str = [27 x i8] c"setsockopt(PACKET_VERSION)\00"
@EXIT_FAILURE = global i32 0
@PACKET_RX_RING = global i32 0
@.str.1 = [27 x i8] c"setsockopt(PACKET_RX_RING)\00"
define void @timer_schedule(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tpacket_req3
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @TPACKET_V3
store i32 %8, i32* %5
%9 = load i32, i32* %3
%10 = load i32, i32* @SOL_PACKET
%11 = load i32, i32* @PACKET_VERSION
%12 = bitcast i32* %5 to i8*
%13 = call i32 @setsockopt(i32 %9, i32 %10, i32 %11, i8* %12, i32 4)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = call i32 @memset(%struct.tpacket_req3* %7, i32 0, i32 20)
%22 = call i32 (...) @getpagesize()
%23 = mul nsw i32 1, %22
%24 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %7, i32 0, i32 0
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %7, i32 0, i32 1
store i32 1, i32* %25
%26 = call i32 (...) @getpagesize()
%27 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %7, i32 0, i32 2
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %7, i32 0, i32 3
store i32 1, i32* %28
%29 = load i32, i32* %4
%30 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %7, i32 0, i32 4
store i32 %29, i32* %30
%31 = load i32, i32* %3
%32 = load i32, i32* @SOL_PACKET
%33 = load i32, i32* @PACKET_RX_RING
%34 = bitcast %struct.tpacket_req3* %7 to i8*
%35 = call i32 @setsockopt(i32 %31, i32 %32, i32 %33, i8* %34, i32 20)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %20
%39 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %20
ret void
}

LLVM IR (-O2):
%struct.tpacket_req3 = type { i32, i32, i32, i32, i32 }
@TPACKET_V3 = global i32 0
@SOL_PACKET = global i32 0
@PACKET_VERSION = global i32 0
@.str = [27 x i8] c"setsockopt(PACKET_VERSION)\00"
@EXIT_FAILURE = global i32 0
@PACKET_RX_RING = global i32 0
@.str.1 = [27 x i8] c"setsockopt(PACKET_RX_RING)\00"
define void @timer_schedule(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tpacket_req3
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @TPACKET_V3
store i32 %6, i32* %3
%7 = load i32, i32* @SOL_PACKET
%8 = load i32, i32* @PACKET_VERSION
%9 = call i32 @setsockopt(i32 %0, i32 %7, i32 %8, i8* %5, i32 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = bitcast %struct.tpacket_req3* %4 to i8*
%17 = call i32 @memset(%struct.tpacket_req3* %4, i32 0, i32 20)
%18 = call i32 (...) @getpagesize()
%19 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %4, i64 0, i32 0
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %4, i64 0, i32 1
store i32 1, i32* %20
%21 = call i32 (...) @getpagesize()
%22 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %4, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %4, i64 0, i32 3
store i32 1, i32* %23
%24 = getelementptr inbounds %struct.tpacket_req3, %struct.tpacket_req3* %4, i64 0, i32 4
store i32 %1, i32* %24
%25 = load i32, i32* @SOL_PACKET
%26 = load i32, i32* @PACKET_RX_RING
%27 = call i32 @setsockopt(i32 %0, i32 %25, i32 %26, i8* %16, i32 20)
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %15
%30 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %15
ret void
}