#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 */
struct tpacket_stats {
  unsigned long tp_packets;
  unsigned long tp_drops;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ kstats;

/* Variables and functions */
int /*<<< orphan*/ PACKET_STATISTICS;
int /*<<< orphan*/ SOL_PACKET;
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
               struct tpacket_stats *, int *);
int /*<<< orphan*/ memset(struct tpacket_stats *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, float);
void sock_print_net_stats(int sock, unsigned long skipped) {
  int ret;
  struct tpacket_stats kstats;
  socklen_t slen = sizeof(kstats);
  memset(&kstats, 0, sizeof(kstats));
  ret = getsockopt(sock, SOL_PACKET, PACKET_STATISTICS, &kstats, &slen);
  if (ret > -1) {
    printf("\r%12ld  frames incoming\n", 1UL * kstats.tp_packets);
    printf("\r%12ld  frames passed filter\n",
           1UL * kstats.tp_packets - kstats.tp_drops - skipped);
    printf("\r%12ld  frames failed filter (out of space)\n",
           1UL * kstats.tp_drops + skipped);
    if (kstats.tp_packets > 0)
      printf("\r%12.4f%% frame droprate\n",
             1.f * kstats.tp_drops / kstats.tp_packets * 100.f);
  }
}


x86 assembly (clang, -O0):
<sock_print_net_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x10,-0x2c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1050 <getsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jle    1346 <sock_print_net_stats+0x216>
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x34(%rbp)
test   %rax,%rax
movss  %xmm0,-0x30(%rbp)
js     11c2 <sock_print_net_stats+0x92>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x3c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x38(%rbp)
js     121e <sock_print_net_stats+0xee>
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x44(%rbp)
test   %rax,%rax
movss  %xmm0,-0x40(%rbp)
js     1273 <sock_print_net_stats+0x143>
movss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x40(%rbp),%xmm0
lea    0xdbc(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
jbe    1341 <sock_print_net_stats+0x211>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x4c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x48(%rbp)
js     12d4 <sock_print_net_stats+0x1a4>
movss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%rax
movss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x64(%rbp)
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x60(%rbp)
test   %rax,%rax
movss  %xmm0,-0x5c(%rbp)
js     131b <sock_print_net_stats+0x1eb>
movss  -0x60(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x64(%rbp),%xmm0
movss  -0x5c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xccf(%rip),%xmm1
mulss  %xmm1,%xmm0
lea    0xd2c(%rip),%rdi
call   1030 <printf@plt>
jmp    1346 <sock_print_net_stats+0x216>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_print_net_stats>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x10,0xc(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r8
mov    %ebp,%edi
mov    %r14,%rcx
call   1050 <getsockopt@plt>
test   %eax,%eax
js     129b <sock_print_net_stats+0x16b>
mov    0x10(%rsp),%rax
test   %rax,%rax
js     1193 <sock_print_net_stats+0x63>
cvtsi2ss %rax,%xmm0
jmp    11a8 <sock_print_net_stats+0x78>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%rax
mov    0x18(%rsp),%rcx
add    %rbx,%rcx
sub    %rcx,%rax
js     11d0 <sock_print_net_stats+0xa0>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
jmp    11e8 <sock_print_net_stats+0xb8>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
add    0x18(%rsp),%rbx
js     1205 <sock_print_net_stats+0xd5>
xorps  %xmm0,%xmm0
cvtsi2ss %rbx,%xmm0
jmp    121d <sock_print_net_stats+0xed>
mov    %rbx,%rax
shr    %rax
and    $0x1,%ebx
or     %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2ss %rbx,%xmm0
addss  %xmm0,%xmm0
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     129b <sock_print_net_stats+0x16b>
mov    0x18(%rsp),%rcx
test   %rcx,%rcx
js     1261 <sock_print_net_stats+0x131>
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
test   %rax,%rax
jns    127e <sock_print_net_stats+0x14e>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm1
addss  %xmm1,%xmm1
jmp    1283 <sock_print_net_stats+0x153>
mov    %rcx,%rdx
shr    %rdx
and    $0x1,%ecx
or     %rdx,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
test   %rax,%rax
js     124a <sock_print_net_stats+0x11a>
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
mulss  0xd71(%rip),%xmm0
lea    0xdd2(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tpacket_stats = type { i64, i64 }
@SOL_PACKET = global i32 0
@PACKET_STATISTICS = global i32 0
@.str = [25 x i8] c"\0D%12ld frames incoming\0A\00"
@.str.1 = [30 x i8] c"\0D%12ld frames passed filter\0A\00"
@.str.2 = [45 x i8] c"\0D%12ld frames failed filter (out of space)\0A\00"
@.str.3 = [26 x i8] c"\0D%12.4f%% frame droprate\0A\00"
define void @sock_print_net_stats(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.tpacket_stats
%7 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
store i32 16, i32* %7
%8 = call i32 @memset(%struct.tpacket_stats* %6, i32 0, i32 16)
%9 = load i32, i32* %3
%10 = load i32, i32* @SOL_PACKET
%11 = load i32, i32* @PACKET_STATISTICS
%12 = call i32 @getsockopt(i32 %9, i32 %10, i32 %11, %struct.tpacket_stats* %6, i32* %7)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %53
15: ; preds = %2
%16 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 0
%17 = load i64, i64* %16
%18 = mul i64 1, %17
%19 = uitofp i64 %18 to float
%20 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), float %19)
%21 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 0
%22 = load i64, i64* %21
%23 = mul i64 1, %22
%24 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub i64 %23, %25
%27 = load i64, i64* %4
%28 = sub i64 %26, %27
%29 = uitofp i64 %28 to float
%30 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), float %29)
%31 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 1
%32 = load i64, i64* %31
%33 = mul i64 1, %32
%34 = load i64, i64* %4
%35 = add i64 %33, %34
%36 = uitofp i64 %35 to float
%37 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), float %36)
%38 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 0
%39 = load i64, i64* %38
%40 = icmp ugt i64 %39, 0
br i1 %40, label %41, label %52
41: ; preds = %15
%42 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 1
%43 = load i64, i64* %42
%44 = uitofp i64 %43 to float
%45 = fmul float 1.000000e+00, %44
%46 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %6, i32 0, i32 0
%47 = load i64, i64* %46
%48 = uitofp i64 %47 to float
%49 = fdiv float %45, %48
%50 = fmul float %49, 1.000000e+02
%51 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), float %50)
br label %52
52: ; preds = %41, %15
br label %53
53: ; preds = %52, %2
ret void
}

LLVM IR (-O2):
%struct.tpacket_stats = type { i64, i64 }
@SOL_PACKET = global i32 0
@PACKET_STATISTICS = global i32 0
@.str = [25 x i8] c"\0D%12ld frames incoming\0A\00"
@.str.1 = [30 x i8] c"\0D%12ld frames passed filter\0A\00"
@.str.2 = [45 x i8] c"\0D%12ld frames failed filter (out of space)\0A\00"
@.str.3 = [26 x i8] c"\0D%12.4f%% frame droprate\0A\00"
define void @sock_print_net_stats(i32 %0, i64 %1) {
%3 = alloca %struct.tpacket_stats
%4 = alloca i32
%5 = bitcast %struct.tpacket_stats* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 16, i32* %4
%7 = call i32 @memset(%struct.tpacket_stats* %3, i32 0, i32 16)
%8 = load i32, i32* @SOL_PACKET
%9 = load i32, i32* @PACKET_STATISTICS
%10 = call i32 @getsockopt(i32 %0, i32 %8, i32 %9, %struct.tpacket_stats* %3, i32* %4)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %12, label %37
12: ; preds = %2
%13 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %3, i64 0, i32 0
%14 = load i64, i64* %13
%15 = uitofp i64 %14 to float
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), float %15)
%17 = load i64, i64* %13
%18 = getelementptr inbounds %struct.tpacket_stats, %struct.tpacket_stats* %3, i64 0, i32 1
%19 = load i64, i64* %18
%20 = add i64 %19, %1
%21 = sub i64 %17, %20
%22 = uitofp i64 %21 to float
%23 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), float %22)
%24 = load i64, i64* %18
%25 = add i64 %24, %1
%26 = uitofp i64 %25 to float
%27 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), float %26)
%28 = load i64, i64* %13
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %12
%31 = load i64, i64* %18
%32 = uitofp i64 %31 to float
%33 = uitofp i64 %28 to float
%34 = fdiv float %32, %33
%35 = fmul float %34, 1.000000e+02
%36 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), float %35)
br label %37
37: ; preds = %12, %30, %2
ret void
}