#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct nlmsghdr {
  int nlmsg_len;
  int /*<<< orphan*/ nlmsg_type;
};
struct nfqnl_msg_packet_hdr {
  int /*<<< orphan*/ packet_id;
};
struct nfgenmsg {
  int dummy;
};
struct nfattr {
  int dummy;
};
typedef unsigned int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNSPEC;
scalar_t__ EINTR;
void *NFA_DATA(struct nfattr const *);
struct nfattr *NFA_NEXT(struct nfattr const *, unsigned int);
scalar_t__ NFA_OK(struct nfattr const *, unsigned int);
unsigned int NFA_PAYLOAD(struct nfattr const *);
int NFA_TYPE(struct nfattr const *);
struct nfattr *NFM_NFA(struct nfgenmsg const *);
scalar_t__ NFNL_MSG_TYPE(int /*<<< orphan*/);
scalar_t__ NFNL_SUBSYS_ID(int /*<<< orphan*/);
scalar_t__ NFNL_SUBSYS_QUEUE;
#define NFQA_PACKET_HDR 129
#define NFQA_PAYLOAD 128
int /*<<< orphan*/ NFQNL_CFG_CMD_BIND;
int /*<<< orphan*/ NFQNL_CFG_CMD_PF_BIND;
int /*<<< orphan*/ NFQNL_CFG_CMD_PF_UNBIND;
int /*<<< orphan*/ NFQNL_COPY_PACKET;
scalar_t__ NFQNL_MSG_PACKET;
int /*<<< orphan*/ NF_ACCEPT;
unsigned int NLMSG_ALIGN(int);
struct nfgenmsg *NLMSG_DATA(struct nlmsghdr const *);
unsigned int NLMSG_LENGTH(unsigned int);
unsigned int NLMSG_SPACE(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int nf_socket();
int /*<<< orphan*/ nfq_cfg_cmd(int, int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ nfq_cfg_mode(int, int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int);
int /*<<< orphan*/ nfq_process(int, char const *, unsigned int,
                               int /*<<< orphan*/);
int /*<<< orphan*/ nfq_verdict(int, scalar_t__, int /*<<< orphan*/, scalar_t__,
                               int /*<<< orphan*/);
scalar_t__ ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int raw_socket();
unsigned int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
bool nfq_operate(uint16_t mtu, uint16_t qid) {
  bool rv = false;
  int fd = -1, sfd = -1;
  uint32_t seq = 0, id = 0;
  ssize_t xfer;
  unsigned len, sz, psz;
  char buf[2048];
  const char *ptr, *pkt;
  const struct nlmsghdr *nlmh;
  const struct nfgenmsg *nfgm;
  const struct nfattr *nfa;
  const struct nfqnl_msg_packet_hdr *nmph;
  sfd = raw_socket();
  if (sfd < 0)
    goto fail;
  fd = nf_socket();
  if (fd < 0 || !nfq_cfg_cmd(fd, seq++, 0, NFQNL_CFG_CMD_PF_UNBIND, AF_INET) ||
      !nfq_cfg_cmd(fd, seq++, 0, NFQNL_CFG_CMD_PF_BIND, AF_INET) ||
      !nfq_cfg_cmd(fd, seq++, qid, NFQNL_CFG_CMD_BIND, AF_UNSPEC) ||
      !nfq_cfg_mode(fd, seq++, qid, NFQNL_COPY_PACKET, sizeof buf))
    goto fail;
  while (true) {
    do {
      xfer = recv(fd, buf, sizeof buf, 0);
    } while (xfer < 0 && errno == EINTR);
    if (xfer < 0) {
      perror("recv()");
      goto fail;
    }
    ptr = (const char *)buf;
    while (xfer >= NLMSG_SPACE(0)) {
      nlmh = (const struct nlmsghdr *)ptr;
      if (nlmh->nlmsg_len < sizeof *nlmh || xfer < nlmh->nlmsg_len) {
        fprintf(stderr, "Truncated message\n");
        goto fail;
      }
      if (NFNL_SUBSYS_ID(nlmh->nlmsg_type) == NFNL_SUBSYS_QUEUE &&
          NFNL_MSG_TYPE(nlmh->nlmsg_type) == NFQNL_MSG_PACKET) {
        pkt = NULL;
        if (nlmh->nlmsg_len < NLMSG_LENGTH(NLMSG_ALIGN(sizeof *nfgm))) {
          fprintf(stderr, "Malformed message\n");
          goto fail;
        }
        nfgm = NLMSG_DATA(nlmh);
        if (nlmh->nlmsg_len > NLMSG_LENGTH(NLMSG_ALIGN(sizeof *nfgm))) {
          nfa = NFM_NFA(nfgm);
          sz = nlmh->nlmsg_len - NLMSG_ALIGN(sizeof *nfgm);
          while (NFA_OK(nfa, sz)) {
            switch (NFA_TYPE(nfa)) {
            case NFQA_PACKET_HDR:
              nmph = NFA_DATA(nfa);
              id = ntohl(nmph->packet_id);
              break;
            case NFQA_PAYLOAD:
              pkt = NFA_DATA(nfa);
              psz = NFA_PAYLOAD(nfa);
              break;
            default:
              break;
            }
            nfa = NFA_NEXT(nfa, sz);
          }
        }
        if ((pkt != NULL && !nfq_process(sfd, pkt, psz, mtu)) ||
            !nfq_verdict(fd, seq, qid, id, NF_ACCEPT))
          goto fail;
      }
      len = NLMSG_ALIGN(nlmh->nlmsg_len);
      if (len > xfer)
        len = xfer;
      xfer -= len;
      ptr += len;
    }
  }
  rv = true;
fail:
  return rv;
}


x86 assembly (clang, -O0):
<nfq_operate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x890,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1080 <raw_socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12af <nfq_operate+0x4f>
jmp    171b <nfq_operate+0x4bb>
mov    $0x0,%al
call   10b0 <nf_socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     139d <nfq_operate+0x13d>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
mov    0x2ce2(%rip),%rax
mov    (%rax),%ecx
mov    0x2cf1(%rip),%rax
mov    (%rax),%r8d
xor    %edx,%edx
call   10f0 <nfq_cfg_cmd@plt>
cmp    $0x0,%eax
je     139d <nfq_operate+0x13d>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
mov    0x2cdb(%rip),%rax
mov    (%rax),%ecx
mov    0x2cba(%rip),%rax
mov    (%rax),%r8d
xor    %edx,%edx
call   10f0 <nfq_cfg_cmd@plt>
cmp    $0x0,%eax
je     139d <nfq_operate+0x13d>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    0x2c61(%rip),%rax
mov    (%rax),%ecx
mov    0x2c70(%rip),%rax
mov    (%rax),%r8d
call   10f0 <nfq_cfg_cmd@plt>
cmp    $0x0,%eax
je     139d <nfq_operate+0x13d>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    0x2c59(%rip),%rax
mov    (%rax),%ecx
mov    $0x800,%r8d
call   1170 <nfq_cfg_mode@plt>
cmp    $0x0,%eax
jne    13a2 <nfq_operate+0x142>
jmp    171b <nfq_operate+0x4bb>
jmp    13a7 <nfq_operate+0x147>
jmp    13ac <nfq_operate+0x14c>
mov    -0x10(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x871(%rbp)
jae    13f4 <nfq_operate+0x194>
mov    0x2bc2(%rip),%rax
mov    (%rax),%rax
mov    0x2ba8(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x871(%rbp)
mov    -0x871(%rbp),%al
test   $0x1,%al
jne    13ac <nfq_operate+0x14c>
cmpl   $0x0,-0x2c(%rbp)
jae    141d <nfq_operate+0x1bd>
lea    0xbed(%rip),%rdi
call   1160 <perror@plt>
jmp    171b <nfq_operate+0x4bb>
lea    -0x840(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x878(%rbp)
xor    %edi,%edi
call   10d0 <NLMSG_SPACE@plt>
mov    %eax,%ecx
mov    -0x878(%rbp),%eax
cmp    %ecx,%eax
jb     1716 <nfq_operate+0x4b6>
mov    -0x848(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    -0x858(%rbp),%rax
movslq (%rax),%rax
cmp    $0x8,%rax
jb     147f <nfq_operate+0x21f>
mov    -0x2c(%rbp),%eax
mov    -0x858(%rbp),%rcx
cmp    (%rcx),%eax
jae    1499 <nfq_operate+0x239>
mov    0x2b22(%rip),%rax
mov    (%rax),%edi
lea    0xb78(%rip),%rsi
call   10e0 <fprintf@plt>
jmp    171b <nfq_operate+0x4bb>
mov    -0x858(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <NFNL_SUBSYS_ID@plt>
mov    0x2ad9(%rip),%rcx
cmp    (%rcx),%rax
jne    16cd <nfq_operate+0x46d>
mov    -0x858(%rbp),%rax
mov    0x4(%rax),%edi
call   1150 <NFNL_MSG_TYPE@plt>
mov    0x2aca(%rip),%rcx
cmp    (%rcx),%rax
jne    16cd <nfq_operate+0x46d>
movq   $0x0,-0x850(%rbp)
mov    -0x858(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x87c(%rbp)
mov    $0x4,%edi
call   1090 <NLMSG_ALIGN@plt>
mov    %eax,%edi
call   1060 <NLMSG_LENGTH@plt>
mov    %eax,%ecx
mov    -0x87c(%rbp),%eax
cmp    %ecx,%eax
jae    152c <nfq_operate+0x2cc>
mov    0x2a8f(%rip),%rax
mov    (%rax),%edi
lea    0xaf8(%rip),%rsi
call   10e0 <fprintf@plt>
jmp    171b <nfq_operate+0x4bb>
mov    -0x858(%rbp),%rdi
call   1110 <NLMSG_DATA@plt>
mov    %rax,-0x860(%rbp)
mov    -0x858(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x880(%rbp)
mov    $0x4,%edi
call   1090 <NLMSG_ALIGN@plt>
mov    %eax,%edi
call   1060 <NLMSG_LENGTH@plt>
mov    %eax,%ecx
mov    -0x880(%rbp),%eax
cmp    %ecx,%eax
jbe    1671 <nfq_operate+0x411>
mov    -0x860(%rbp),%rdi
call   1030 <NFM_NFA@plt>
mov    %rax,-0x868(%rbp)
mov    -0x858(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x884(%rbp)
mov    $0x4,%edi
call   1090 <NLMSG_ALIGN@plt>
mov    %eax,%ecx
mov    -0x884(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x868(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1130 <NFA_OK@plt>
cmp    $0x0,%rax
je     166c <nfq_operate+0x40c>
mov    -0x868(%rbp),%rdi
call   1070 <NFA_TYPE@plt>
mov    %eax,%ecx
mov    %ecx,-0x888(%rbp)
sub    $0x80,%eax
je     1625 <nfq_operate+0x3c5>
jmp    15e5 <nfq_operate+0x385>
mov    -0x888(%rbp),%eax
sub    $0x81,%eax
jne    164c <nfq_operate+0x3ec>
jmp    15fb <nfq_operate+0x39b>
mov    -0x868(%rbp),%rdi
call   1100 <NFA_DATA@plt>
mov    %rax,-0x870(%rbp)
mov    -0x870(%rbp),%rax
mov    (%rax),%edi
call   1180 <ntohl@plt>
mov    %rax,-0x28(%rbp)
jmp    1651 <nfq_operate+0x3f1>
mov    -0x868(%rbp),%rdi
call   1100 <NFA_DATA@plt>
mov    %rax,-0x850(%rbp)
mov    -0x868(%rbp),%rdi
call   1140 <NFA_PAYLOAD@plt>
mov    %eax,-0x38(%rbp)
jmp    1651 <nfq_operate+0x3f1>
jmp    1651 <nfq_operate+0x3f1>
mov    -0x868(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   10c0 <NFA_NEXT@plt>
mov    %rax,-0x868(%rbp)
jmp    15a8 <nfq_operate+0x348>
jmp    1671 <nfq_operate+0x411>
cmpq   $0x0,-0x850(%rbp)
je     169d <nfq_operate+0x43d>
mov    -0x14(%rbp),%edi
mov    -0x850(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x4(%rbp),%ecx
call   1120 <nfq_process@plt>
cmp    $0x0,%eax
je     16c3 <nfq_operate+0x463>
mov    -0x10(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    0x291e(%rip),%rax
mov    (%rax),%r8d
call   10a0 <nfq_verdict@plt>
cmp    $0x0,%eax
jne    16c8 <nfq_operate+0x468>
jmp    171b <nfq_operate+0x4bb>
jmp    16cd <nfq_operate+0x46d>
mov    -0x858(%rbp),%rax
mov    (%rax),%edi
call   1090 <NLMSG_ALIGN@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jbe    16f0 <nfq_operate+0x490>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x848(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x848(%rbp)
jmp    142b <nfq_operate+0x1cb>
jmp    13a7 <nfq_operate+0x147>
mov    -0xc(%rbp),%eax
add    $0x890,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nfq_operate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %esi,%r13d
mov    %edi,%r12d
xor    %eax,%eax
call   1080 <raw_socket@plt>
test   %eax,%eax
js     152b <nfq_operate+0x2db>
mov    %eax,%ebx
xor    %eax,%eax
call   10b0 <nf_socket@plt>
test   %eax,%eax
js     152b <nfq_operate+0x2db>
mov    %eax,%r15d
mov    0x2d2f(%rip),%rax
mov    (%rax),%ecx
mov    0x2d3e(%rip),%rbp
mov    0x0(%rbp),%r8d
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <nfq_cfg_cmd@plt>
test   %eax,%eax
je     152b <nfq_operate+0x2db>
mov    0x2d37(%rip),%rax
mov    (%rax),%ecx
mov    0x0(%rbp),%r8d
mov    %r15d,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   10f0 <nfq_cfg_cmd@plt>
test   %eax,%eax
je     152b <nfq_operate+0x2db>
mov    0x2cd3(%rip),%rax
mov    (%rax),%ecx
mov    0x2ce2(%rip),%rax
mov    (%rax),%r8d
mov    %r15d,%edi
mov    $0x2,%esi
mov    %r13d,%edx
call   10f0 <nfq_cfg_cmd@plt>
test   %eax,%eax
je     152b <nfq_operate+0x2db>
mov    0x2cd8(%rip),%rax
mov    (%rax),%ecx
mov    %r15d,%edi
mov    $0x3,%esi
mov    %r13d,%edx
mov    $0x800,%r8d
call   1160 <nfq_cfg_mode@plt>
test   %eax,%eax
je     152b <nfq_operate+0x2db>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    %r13d,0x8(%rsp)
mov    %r12d,0x10(%rsp)
mov    %ebx,0xc(%rsp)
lea    0x20(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   10d0 <NLMSG_SPACE@plt>
cmp    %eax,%r14d
jb     1350 <nfq_operate+0x100>
jmp    13cc <nfq_operate+0x17c>
mov    0x8(%rsp),%r13d
nopl   0x0(%rax,%rax,1)
mov    0x2c49(%rip),%rax
mov    (%rax),%r8d
mov    $0x4,%esi
mov    %r15d,%edi
mov    %r13d,%edx
mov    0x18(%rsp),%rcx
call   10a0 <nfq_verdict@plt>
test   %eax,%eax
je     152b <nfq_operate+0x2db>
mov    0x0(%rbp),%edi
call   1090 <NLMSG_ALIGN@plt>
cmp    %r14d,%eax
cmova  %r14d,%eax
sub    %eax,%r14d
add    %rax,%rbp
xor    %edi,%edi
call   10d0 <NLMSG_SPACE@plt>
cmp    %eax,%r14d
jb     133d <nfq_operate+0xed>
mov    0x0(%rbp),%eax
cmp    $0x8,%eax
jb     150d <nfq_operate+0x2bd>
cmp    %eax,%r14d
jb     150d <nfq_operate+0x2bd>
mov    0x4(%rbp),%edi
call   1050 <NFNL_SUBSYS_ID@plt>
mov    0x2ba8(%rip),%rcx
cmp    (%rcx),%rax
jne    13a7 <nfq_operate+0x157>
mov    0x4(%rbp),%edi
call   1150 <NFNL_MSG_TYPE@plt>
mov    0x2b9c(%rip),%rcx
cmp    (%rcx),%rax
jne    13a7 <nfq_operate+0x157>
mov    0x0(%rbp),%ebx
mov    $0x4,%edi
call   1090 <NLMSG_ALIGN@plt>
mov    %eax,%edi
call   1060 <NLMSG_LENGTH@plt>
cmp    %eax,%ebx
jb     1516 <nfq_operate+0x2c6>
mov    %rbp,%rdi
call   1110 <NLMSG_DATA@plt>
mov    %rax,%r12
mov    0x0(%rbp),%ebx
mov    $0x4,%edi
call   1090 <NLMSG_ALIGN@plt>
mov    %eax,%edi
call   1060 <NLMSG_LENGTH@plt>
cmp    %eax,%ebx
jbe    1380 <nfq_operate+0x130>
mov    %r12,%rdi
call   1030 <NFM_NFA@plt>
mov    %rax,%r13
mov    0x0(%rbp),%r12d
mov    $0x4,%edi
call   1090 <NLMSG_ALIGN@plt>
sub    %eax,%r12d
mov    %r13,%rdi
mov    %r12d,%esi
call   1130 <NFA_OK@plt>
test   %rax,%rax
je     1373 <nfq_operate+0x123>
xor    %ebx,%ebx
jmp    14b5 <nfq_operate+0x265>
mov    %r13,%rdi
call   1100 <NFA_DATA@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1140 <NFA_PAYLOAD@plt>
mov    %eax,0x14(%rsp)
mov    %r13,%rdi
mov    %r12d,%esi
call   10c0 <NFA_NEXT@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12d,%esi
call   1130 <NFA_OK@plt>
test   %rax,%rax
je     14e1 <nfq_operate+0x291>
mov    %r13,%rdi
call   1070 <NFA_TYPE@plt>
cmp    $0x80,%eax
je     1480 <nfq_operate+0x230>
cmp    $0x81,%eax
jne    1497 <nfq_operate+0x247>
mov    %r13,%rdi
call   1100 <NFA_DATA@plt>
mov    (%rax),%edi
call   1170 <ntohl@plt>
mov    %rax,0x18(%rsp)
jmp    1497 <nfq_operate+0x247>
test   %rbx,%rbx
mov    0x8(%rsp),%r13d
je     1380 <nfq_operate+0x130>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
call   1120 <nfq_process@plt>
test   %eax,%eax
jne    1380 <nfq_operate+0x130>
jmp    152b <nfq_operate+0x2db>
lea    0xaec(%rip),%rsi
jmp    151d <nfq_operate+0x2cd>
lea    0xaf6(%rip),%rsi
mov    0x2a84(%rip),%rax
mov    (%rax),%edi
call   10e0 <fprintf@plt>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32, i32 }
%struct.nfgenmsg = type { i32 }
%struct.nfattr = type { i32 }
%struct.nfqnl_msg_packet_hdr = type { i32 }
@NFQNL_CFG_CMD_PF_UNBIND = global i32 0
@AF_INET = global i32 0
@NFQNL_CFG_CMD_PF_BIND = global i32 0
@NFQNL_CFG_CMD_BIND = global i32 0
@AF_UNSPEC = global i32 0
@NFQNL_COPY_PACKET = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"recv()\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Truncated message\0A\00"
@NFNL_SUBSYS_QUEUE = global i64 0
@NFQNL_MSG_PACKET = global i64 0
@.str.2 = [19 x i8] c"Malformed message\0A\00"
@NF_ACCEPT = global i32 0
define i32 @nfq_operate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [2048 x i8]
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca %struct.nlmsghdr*
%18 = alloca %struct.nfgenmsg*
%19 = alloca %struct.nfattr*
%20 = alloca %struct.nfqnl_msg_packet_hdr*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i64 0, i64* %8
store i64 0, i64* %9
%21 = call i32 (...) @raw_socket()
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
br label %217
25: ; preds = %2
%26 = call i32 (...) @nf_socket()
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %66, label %29
29: ; preds = %25
%30 = load i32, i32* %6
%31 = load i64, i64* %8
%32 = add nsw i64 %31, 1
store i64 %32, i64* %8
%33 = trunc i64 %31 to i32
%34 = load i32, i32* @NFQNL_CFG_CMD_PF_UNBIND
%35 = load i32, i32* @AF_INET
%36 = call i32 @nfq_cfg_cmd(i32 %30, i32 %33, i32 0, i32 %34, i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %66
38: ; preds = %29
%39 = load i32, i32* %6
%40 = load i64, i64* %8
%41 = add nsw i64 %40, 1
store i64 %41, i64* %8
%42 = trunc i64 %40 to i32
%43 = load i32, i32* @NFQNL_CFG_CMD_PF_BIND
%44 = load i32, i32* @AF_INET
%45 = call i32 @nfq_cfg_cmd(i32 %39, i32 %42, i32 0, i32 %43, i32 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %66
47: ; preds = %38
%48 = load i32, i32* %6
%49 = load i64, i64* %8
%50 = add nsw i64 %49, 1
store i64 %50, i64* %8
%51 = trunc i64 %49 to i32
%52 = load i32, i32* %4
%53 = load i32, i32* @NFQNL_CFG_CMD_BIND
%54 = load i32, i32* @AF_UNSPEC
%55 = call i32 @nfq_cfg_cmd(i32 %48, i32 %51, i32 %52, i32 %53, i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %47
%58 = load i32, i32* %6
%59 = load i64, i64* %8
%60 = add nsw i64 %59, 1
store i64 %60, i64* %8
%61 = trunc i64 %59 to i32
%62 = load i32, i32* %4
%63 = load i32, i32* @NFQNL_COPY_PACKET
%64 = call i32 @nfq_cfg_mode(i32 %58, i32 %61, i32 %62, i32 %63, i32 2048)
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %57, %47, %38, %29, %25
br label %217
67: ; preds = %57
br label %68
68: ; preds = %67, %216
br label %69
69: ; preds = %80, %68
%70 = load i32, i32* %6
%71 = getelementptr inbounds [2048 x i8], [2048 x i8]* %14, i64 0, i64 0
%72 = call i32 @recv(i32 %70, i8* %71, i32 2048, i32 0)
store i32 %72, i32* %10
br label %73
73: ; preds = %69
%74 = load i32, i32* %10
%75 = icmp ult i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = load i64, i64* @errno
%78 = load i64, i64* @EINTR
%79 = icmp eq i64 %77, %78
br label %80
80: ; preds = %76, %73
%81 = phi i1 [ false, %73 ], [ %79, %76 ]
br i1 %81, label %69, label %82
82: ; preds = %80
%83 = load i32, i32* %10
%84 = icmp ult i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %217
87: ; preds = %82
%88 = getelementptr inbounds [2048 x i8], [2048 x i8]* %14, i64 0, i64 0
store i8* %88, i8** %15
br label %89
89: ; preds = %208, %87
%90 = load i32, i32* %10
%91 = call i32 @NLMSG_SPACE(i32 0)
%92 = icmp uge i32 %90, %91
br i1 %92, label %93, label %216
93: ; preds = %89
%94 = load i8*, i8** %15
%95 = bitcast i8* %94 to %struct.nlmsghdr*
store %struct.nlmsghdr* %95, %struct.nlmsghdr** %17
%96 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%97 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %96, i32 0, i32 0
%98 = load i32, i32* %97
%99 = sext i32 %98 to i64
%100 = icmp ult i64 %99, 8
br i1 %100, label %107, label %101
101: ; preds = %93
%102 = load i32, i32* %10
%103 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%104 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = icmp ult i32 %102, %105
br i1 %106, label %107, label %110
107: ; preds = %101, %93
%108 = load i32, i32* @stderr
%109 = call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %217
110: ; preds = %101
%111 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%112 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %111, i32 0, i32 1
%113 = load i32, i32* %112
%114 = call i64 @NFNL_SUBSYS_ID(i32 %113)
%115 = load i64, i64* @NFNL_SUBSYS_QUEUE
%116 = icmp eq i64 %114, %115
br i1 %116, label %117, label %198
117: ; preds = %110
%118 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%119 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %118, i32 0, i32 1
%120 = load i32, i32* %119
%121 = call i64 @NFNL_MSG_TYPE(i32 %120)
%122 = load i64, i64* @NFQNL_MSG_PACKET
%123 = icmp eq i64 %121, %122
br i1 %123, label %124, label %198
124: ; preds = %117
store i8* null, i8** %16
%125 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%126 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %125, i32 0, i32 0
%127 = load i32, i32* %126
%128 = call i32 @NLMSG_ALIGN(i32 4)
%129 = call i32 @NLMSG_LENGTH(i32 %128)
%130 = icmp ult i32 %127, %129
br i1 %130, label %131, label %134
131: ; preds = %124
%132 = load i32, i32* @stderr
%133 = call i32 @fprintf(i32 %132, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %217
134: ; preds = %124
%135 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%136 = call %struct.nfgenmsg* @NLMSG_DATA(%struct.nlmsghdr* %135)
store %struct.nfgenmsg* %136, %struct.nfgenmsg** %18
%137 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%138 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %137, i32 0, i32 0
%139 = load i32, i32* %138
%140 = call i32 @NLMSG_ALIGN(i32 4)
%141 = call i32 @NLMSG_LENGTH(i32 %140)
%142 = icmp ugt i32 %139, %141
br i1 %142, label %143, label %178
143: ; preds = %134
%144 = load %struct.nfgenmsg*, %struct.nfgenmsg** %18
%145 = call %struct.nfattr* @NFM_NFA(%struct.nfgenmsg* %144)
store %struct.nfattr* %145, %struct.nfattr** %19
%146 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%147 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %146, i32 0, i32 0
%148 = load i32, i32* %147
%149 = call i32 @NLMSG_ALIGN(i32 4)
%150 = sub i32 %148, %149
store i32 %150, i32* %12
br label %151
151: ; preds = %173, %143
%152 = load %struct.nfattr*, %struct.nfattr** %19
%153 = load i32, i32* %12
%154 = call i64 @NFA_OK(%struct.nfattr* %152, i32 %153)
%155 = icmp ne i64 %154, 0
br i1 %155, label %156, label %177
156: ; preds = %151
%157 = load %struct.nfattr*, %struct.nfattr** %19
%158 = call i32 @NFA_TYPE(%struct.nfattr* %157)
switch i32 %158, label %172 [
i32 129, label %159
i32 128, label %167
]
159: ; preds = %156
%160 = load %struct.nfattr*, %struct.nfattr** %19
%161 = call i8* @NFA_DATA(%struct.nfattr* %160)
%162 = bitcast i8* %161 to %struct.nfqnl_msg_packet_hdr*
store %struct.nfqnl_msg_packet_hdr* %162, %struct.nfqnl_msg_packet_hdr** %20
%163 = load %struct.nfqnl_msg_packet_hdr*, %struct.nfqnl_msg_packet_hdr** %20
%164 = getelementptr inbounds %struct.nfqnl_msg_packet_hdr, %struct.nfqnl_msg_packet_hdr* %163, i32 0, i32 0
%165 = load i32, i32* %164
%166 = call i64 @ntohl(i32 %165)
store i64 %166, i64* %9
br label %173
167: ; preds = %156
%168 = load %struct.nfattr*, %struct.nfattr** %19
%169 = call i8* @NFA_DATA(%struct.nfattr* %168)
store i8* %169, i8** %16
%170 = load %struct.nfattr*, %struct.nfattr** %19
%171 = call i32 @NFA_PAYLOAD(%struct.nfattr* %170)
store i32 %171, i32* %13
br label %173
172: ; preds = %156
br label %173
173: ; preds = %172, %167, %159
%174 = load %struct.nfattr*, %struct.nfattr** %19
%175 = load i32, i32* %12
%176 = call %struct.nfattr* @NFA_NEXT(%struct.nfattr* %174, i32 %175)
store %struct.nfattr* %176, %struct.nfattr** %19
br label %151
177: ; preds = %151
br label %178
178: ; preds = %177, %134
%179 = load i8*, i8** %16
%180 = icmp ne i8* %179, null
br i1 %180, label %181, label %188
181: ; preds = %178
%182 = load i32, i32* %7
%183 = load i8*, i8** %16
%184 = load i32, i32* %13
%185 = load i32, i32* %3
%186 = call i32 @nfq_process(i32 %182, i8* %183, i32 %184, i32 %185)
%187 = icmp ne i32 %186, 0
br i1 %187, label %188, label %196
188: ; preds = %181, %178
%189 = load i32, i32* %6
%190 = load i64, i64* %8
%191 = load i32, i32* %4
%192 = load i64, i64* %9
%193 = load i32, i32* @NF_ACCEPT
%194 = call i32 @nfq_verdict(i32 %189, i64 %190, i32 %191, i64 %192, i32 %193)
%195 = icmp ne i32 %194, 0
br i1 %195, label %197, label %196
196: ; preds = %188, %181
br label %217
197: ; preds = %188
br label %198
198: ; preds = %197, %117, %110
%199 = load %struct.nlmsghdr*, %struct.nlmsghdr** %17
%200 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %199, i32 0, i32 0
%201 = load i32, i32* %200
%202 = call i32 @NLMSG_ALIGN(i32 %201)
store i32 %202, i32* %11
%203 = load i32, i32* %11
%204 = load i32, i32* %10
%205 = icmp ugt i32 %203, %204
br i1 %205, label %206, label %208
206: ; preds = %198
%207 = load i32, i32* %10
store i32 %207, i32* %11
br label %208
208: ; preds = %206, %198
%209 = load i32, i32* %11
%210 = load i32, i32* %10
%211 = sub i32 %210, %209
store i32 %211, i32* %10
%212 = load i32, i32* %11
%213 = load i8*, i8** %15
%214 = zext i32 %212 to i64
%215 = getelementptr inbounds i8, i8* %213, i64 %214
store i8* %215, i8** %15
br label %89
216: ; preds = %89
br label %68
217: ; preds = %196, %131, %107, %85, %66, %24
%218 = load i32, i32* %5
ret i32 %218
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32, i32 }
%struct.nfgenmsg = type { i32 }
%struct.nfattr = type { i32 }
@NFQNL_CFG_CMD_PF_UNBIND = global i32 0
@AF_INET = global i32 0
@NFQNL_CFG_CMD_PF_BIND = global i32 0
@NFQNL_CFG_CMD_BIND = global i32 0
@AF_UNSPEC = global i32 0
@NFQNL_COPY_PACKET = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Truncated message\0A\00"
@NFNL_SUBSYS_QUEUE = global i64 0
@NFQNL_MSG_PACKET = global i64 0
@.str.2 = [19 x i8] c"Malformed message\0A\00"
@NF_ACCEPT = global i32 0
define i32 @nfq_operate(i32 %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @raw_socket()
%6 = icmp slt i32 %5, 0
br i1 %6, label %125, label %7
7: ; preds = %2
%8 = tail call i32 (...) @nf_socket()
%9 = icmp slt i32 %8, 0
br i1 %9, label %125, label %10
10: ; preds = %7
%11 = load i32, i32* @NFQNL_CFG_CMD_PF_UNBIND
%12 = load i32, i32* @AF_INET
%13 = tail call i32 @nfq_cfg_cmd(i32 %8, i32 0, i32 0, i32 %11, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %125, label %15
15: ; preds = %10
%16 = load i32, i32* @NFQNL_CFG_CMD_PF_BIND
%17 = load i32, i32* @AF_INET
%18 = tail call i32 @nfq_cfg_cmd(i32 %8, i32 1, i32 0, i32 %16, i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %125, label %20
20: ; preds = %15
%21 = load i32, i32* @NFQNL_CFG_CMD_BIND
%22 = load i32, i32* @AF_UNSPEC
%23 = tail call i32 @nfq_cfg_cmd(i32 %8, i32 2, i32 %1, i32 %21, i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %125, label %25
25: ; preds = %20
%26 = load i32, i32* @NFQNL_COPY_PACKET
%27 = tail call i32 @nfq_cfg_mode(i32 %8, i32 3, i32 %1, i32 %26, i32 2048)
%28 = icmp eq i32 %27, 0
br i1 %28, label %125, label %29
29: ; preds = %109, %25
%30 = phi i64 [ 0, %25 ], [ %110, %109 ]
%31 = phi i32 [ undef, %25 ], [ %111, %109 ]
br label %32
32: ; preds = %29, %32
%33 = call i32 @recv(i32 %8, i8* %4, i32 2048, i32 0)
%34 = call i32 @NLMSG_SPACE(i32 0)
%35 = icmp ult i32 %33, %34
br i1 %35, label %32, label %36
36: ; preds = %32, %109
%37 = phi i8* [ %118, %109 ], [ %4, %32 ]
%38 = phi i32 [ %111, %109 ], [ %31, %32 ]
%39 = phi i64 [ %110, %109 ], [ %30, %32 ]
%40 = phi i32 [ %116, %109 ], [ %33, %32 ]
%41 = bitcast i8* %37 to %struct.nlmsghdr*
%42 = bitcast i8* %37 to i32*
%43 = load i32, i32* %42
%44 = icmp ult i32 %43, 8
%45 = icmp ult i32 %40, %43
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %121, label %47
47: ; preds = %36
%48 = getelementptr inbounds i8, i8* %37, i64 4
%49 = bitcast i8* %48 to i32*
%50 = load i32, i32* %49
%51 = call i64 @NFNL_SUBSYS_ID(i32 %50)
%52 = load i64, i64* @NFNL_SUBSYS_QUEUE
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %109
54: ; preds = %47
%55 = load i32, i32* %49
%56 = call i64 @NFNL_MSG_TYPE(i32 %55)
%57 = load i64, i64* @NFQNL_MSG_PACKET
%58 = icmp eq i64 %56, %57
br i1 %58, label %59, label %109
59: ; preds = %54
%60 = load i32, i32* %42
%61 = call i32 @NLMSG_ALIGN(i32 4)
%62 = call i32 @NLMSG_LENGTH(i32 %61)
%63 = icmp ult i32 %60, %62
br i1 %63, label %121, label %64
64: ; preds = %59
%65 = call %struct.nfgenmsg* @NLMSG_DATA(%struct.nlmsghdr* %41)
%66 = load i32, i32* %42
%67 = call i32 @NLMSG_ALIGN(i32 4)
%68 = call i32 @NLMSG_LENGTH(i32 %67)
%69 = icmp ugt i32 %66, %68
br i1 %69, label %70, label %103
70: ; preds = %64
%71 = call %struct.nfattr* @NFM_NFA(%struct.nfgenmsg* %65)
%72 = load i32, i32* %42
%73 = call i32 @NLMSG_ALIGN(i32 4)
%74 = sub i32 %72, %73
%75 = call i64 @NFA_OK(%struct.nfattr* %71, i32 %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %103, label %77
77: ; preds = %70, %91
%78 = phi %struct.nfattr* [ %95, %91 ], [ %71, %70 ]
%79 = phi i8* [ %94, %91 ], [ null, %70 ]
%80 = phi i32 [ %93, %91 ], [ %38, %70 ]
%81 = phi i64 [ %92, %91 ], [ %39, %70 ]
%82 = call i32 @NFA_TYPE(%struct.nfattr* %78)
switch i32 %82, label %91 [
i32 129, label %83
i32 128, label %88
]
83: ; preds = %77
%84 = call i8* @NFA_DATA(%struct.nfattr* %78)
%85 = bitcast i8* %84 to i32*
%86 = load i32, i32* %85
%87 = call i64 @ntohl(i32 %86)
br label %91
88: ; preds = %77
%89 = call i8* @NFA_DATA(%struct.nfattr* %78)
%90 = call i32 @NFA_PAYLOAD(%struct.nfattr* %78)
br label %91
91: ; preds = %77, %88, %83
%92 = phi i64 [ %81, %77 ], [ %81, %88 ], [ %87, %83 ]
%93 = phi i32 [ %80, %77 ], [ %90, %88 ], [ %80, %83 ]
%94 = phi i8* [ %79, %77 ], [ %89, %88 ], [ %79, %83 ]
%95 = call %struct.nfattr* @NFA_NEXT(%struct.nfattr* %78, i32 %74)
%96 = call i64 @NFA_OK(%struct.nfattr* %95, i32 %74)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %77
98: ; preds = %91
%99 = icmp eq i8* %94, null
br i1 %99, label %103, label %100
100: ; preds = %98
%101 = call i32 @nfq_process(i32 %5, i8* %94, i32 %93, i32 %0)
%102 = icmp eq i32 %101, 0
br i1 %102, label %125, label %103
103: ; preds = %70, %64, %100, %98
%104 = phi i32 [ %93, %100 ], [ %93, %98 ], [ %38, %64 ], [ %38, %70 ]
%105 = phi i64 [ %92, %100 ], [ %92, %98 ], [ %39, %64 ], [ %39, %70 ]
%106 = load i32, i32* @NF_ACCEPT
%107 = call i32 @nfq_verdict(i32 %8, i64 4, i32 %1, i64 %105, i32 %106)
%108 = icmp eq i32 %107, 0
br i1 %108, label %125, label %109
109: ; preds = %103, %54, %47
%110 = phi i64 [ %105, %103 ], [ %39, %54 ], [ %39, %47 ]
%111 = phi i32 [ %104, %103 ], [ %38, %54 ], [ %38, %47 ]
%112 = load i32, i32* %42
%113 = call i32 @NLMSG_ALIGN(i32 %112)
%114 = icmp ugt i32 %113, %40
%115 = select i1 %114, i32 %40, i32 %113
%116 = sub i32 %40, %115
%117 = zext i32 %115 to i64
%118 = getelementptr inbounds i8, i8* %37, i64 %117
%119 = call i32 @NLMSG_SPACE(i32 0)
%120 = icmp ult i32 %116, %119
br i1 %120, label %29, label %36
121: ; preds = %59, %36
%122 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %36 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %59 ]
%123 = load i32, i32* @stderr
%124 = call i32 @fprintf(i32 %123, i8* %122)
br label %125
125: ; preds = %100, %103, %121, %7, %10, %15, %20, %25, %2
ret i32 0
}