#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_req {
  int dummy;
};
typedef int /*<<< orphan*/ req;

/* Variables and functions */
int /*<<< orphan*/ PACKET_RX_RING;
int /*<<< orphan*/ SOL_PACKET;
int /*<<< orphan*/ memset(struct tpacket_req *, int /*<<< orphan*/, int);
int /*<<< orphan*/ munmap(char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct tpacket_req *, int);
void iface_munmap(int sd, int framenum, char *buf) {
  struct tpacket_req req;
  if (framenum) {
    memset(&req, 0, sizeof(req));
    setsockopt(sd, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req));
    munmap(buf, ((8192) * framenum));
  }
}


x86 assembly (clang, -O0):
<iface_munmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118f <iface_munmap+0x5f>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
shl    $0xd,%esi
call   1050 <munmap@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iface_munmap>:
test   %esi,%esi
je     118d <iface_munmap+0x5d>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
shl    $0xd,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <munmap@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tpacket_req = type { i32 }
@SOL_PACKET = global i32 0
@PACKET_RX_RING = global i32 0
define void @iface_munmap(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.tpacket_req
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = call i32 @memset(%struct.tpacket_req* %7, i32 0, i32 4)
%12 = load i32, i32* %4
%13 = load i32, i32* @SOL_PACKET
%14 = load i32, i32* @PACKET_RX_RING
%15 = call i32 @setsockopt(i32 %12, i32 %13, i32 %14, %struct.tpacket_req* %7, i32 4)
%16 = load i8*, i8** %6
%17 = load i32, i32* %5
%18 = mul nsw i32 8192, %17
%19 = call i32 @munmap(i8* %16, i32 %18)
br label %20
20: ; preds = %10, %3
ret void
}

LLVM IR (-O2):
%struct.tpacket_req = type { i32 }
@SOL_PACKET = global i32 0
@PACKET_RX_RING = global i32 0
define void @iface_munmap(i32 %0, i32 %1, i8* %2) {
%4 = alloca %struct.tpacket_req
%5 = bitcast %struct.tpacket_req* %4 to i8*
%6 = icmp eq i32 %1, 0
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = call i32 @memset(%struct.tpacket_req* %4, i32 0, i32 4)
%9 = load i32, i32* @SOL_PACKET
%10 = load i32, i32* @PACKET_RX_RING
%11 = call i32 @setsockopt(i32 %0, i32 %9, i32 %10, %struct.tpacket_req* %4, i32 4)
%12 = shl nsw i32 %1, 13
%13 = call i32 @munmap(i8* %2, i32 %12)
br label %14
14: ; preds = %7, %3
ret void
}