#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 uint16_t;
typedef int /*<<< orphan*/ sockopt;
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ PACKET_FANOUT;
int /*<<< orphan*/ SOL_PACKET;
int /*<<< orphan*/ exit(int);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *,
                      int *);
int /*<<< orphan*/ perror(char *);
void sock_fanout_getopts(int fd, uint16_t *typeflags, uint16_t *group_id) {
  int sockopt;
  socklen_t sockopt_len = sizeof(sockopt);
  if (getsockopt(fd, SOL_PACKET, PACKET_FANOUT, &sockopt, &sockopt_len)) {
    perror("failed to getsockopt");
    exit(1);
  }
  *typeflags = sockopt >> 16;
  *group_id = sockopt & 0xfffff;
}


x86 assembly (clang, -O0):
<sock_fanout_getopts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1030 <getsockopt@plt>
cmp    $0x0,%rax
je     118c <sock_fanout_getopts+0x5c>
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
and    $0xfffff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_fanout_getopts>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0x4,(%rsp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
call   1030 <getsockopt@plt>
test   %rax,%rax
jne    1180 <sock_fanout_getopts+0x50>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
sar    $0x10,%ecx
mov    %ecx,(%rbx)
and    $0xfffff,%eax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe79(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SOL_PACKET = global i32 0
@PACKET_FANOUT = global i32 0
@.str = [21 x i8] c"failed to getsockopt\00"
define void @sock_fanout_getopts(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 4, i32* %8
%9 = load i32, i32* %4
%10 = load i32, i32* @SOL_PACKET
%11 = load i32, i32* @PACKET_FANOUT
%12 = call i64 @getsockopt(i32 %9, i32 %10, i32 %11, i32* %7, i32* %8)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i32, i32* %7
%19 = ashr i32 %18, 16
%20 = load i32*, i32** %5
store i32 %19, i32* %20
%21 = load i32, i32* %7
%22 = and i32 %21, 1048575
%23 = load i32*, i32** %6
store i32 %22, i32* %23
ret void
}

LLVM IR (-O2):
@SOL_PACKET = global i32 0
@PACKET_FANOUT = global i32 0
@.str = [21 x i8] c"failed to getsockopt\00"
define void @sock_fanout_getopts(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = load i32, i32* @SOL_PACKET
%9 = load i32, i32* @PACKET_FANOUT
%10 = call i64 @getsockopt(i32 %0, i32 %8, i32 %9, i32* %4, i32* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %3
%16 = load i32, i32* %4
%17 = ashr i32 %16, 16
store i32 %17, i32* %1
%18 = and i32 %16, 1048575
store i32 %18, i32* %2
ret void
}