#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__ uint8_t;
typedef int uint16_t;

/* Variables and functions */
scalar_t__ PACKET_FANOUT_CBPF;
int /*<<< orphan*/ PACKET_FANOUT_DATA;
scalar_t__ PACKET_FANOUT_EBPF;
int /*<<< orphan*/ SOL_PACKET;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpagesize();
scalar_t__ munmap(char *, int);
int /*<<< orphan*/ pair_udp_open(int *, int);
int /*<<< orphan*/ pair_udp_send(int *, int);
int /*<<< orphan*/ pair_udp_send_char(int *, int, char);
int sock_fanout_open(int, int);
char *sock_fanout_open_ring(int);
int sock_fanout_read(int *, char **, int const *);
int /*<<< orphan*/ sock_fanout_set_ebpf(int);
int /*<<< orphan*/ sock_setfilter(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int test_datapath(uint16_t typeflags, int port_off, const int expect1[],
                  const int expect2[]) {
  const int expect0[] = {0, 0};
  char *rings[2];
  uint8_t type = typeflags & 0xFF;
  int fds[2], fds_udp[2][2], ret;
  fprintf(stderr, "test: datapath 0x%hx\n", typeflags);
  fds[0] = sock_fanout_open(typeflags, 20);
  fds[1] = sock_fanout_open(typeflags, 20);
  if (fds[0] == -1 || fds[1] == -1) {
    fprintf(stderr, "ERROR: failed open\n");
    exit(1);
  }
  if (type == PACKET_FANOUT_CBPF)
    sock_setfilter(fds[0], SOL_PACKET, PACKET_FANOUT_DATA);
  else if (type == PACKET_FANOUT_EBPF)
    sock_fanout_set_ebpf(fds[0]);
  rings[0] = sock_fanout_open_ring(fds[0]);
  rings[1] = sock_fanout_open_ring(fds[1]);
  pair_udp_open(fds_udp[0], 8000);
  pair_udp_open(fds_udp[1], 8000 + port_off);
  sock_fanout_read(fds, rings, expect0);
  pair_udp_send(fds_udp[0], 15);
  pair_udp_send_char(fds_udp[1], 5, 'b');
  ret = sock_fanout_read(fds, rings, expect1);
  pair_udp_send_char(fds_udp[0], 15, 'b');
  ret |= sock_fanout_read(fds, rings, expect2);
  if (munmap(rings[1], 20 * getpagesize()) ||
      munmap(rings[0], 20 * getpagesize())) {
    fprintf(stderr, "close rings\n");
    exit(1);
  }
  if (close(fds_udp[1][1]) || close(fds_udp[1][0]) || close(fds_udp[0][1]) ||
      close(fds_udp[0][0]) || close(fds[1]) || close(fds[0])) {
    fprintf(stderr, "close datapath\n");
    exit(1);
  }
  return ret;
}


x86 assembly (clang, -O0):
<test_datapath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    $0x14,%esi
call   1090 <sock_fanout_open@plt>
mov    %eax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x14,%esi
call   1090 <sock_fanout_open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
je     1262 <test_datapath+0x82>
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1283 <test_datapath+0xa3>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    0x2d2a(%rip),%rcx
cmp    (%rcx),%rax
jne    12b6 <test_datapath+0xd6>
mov    -0x40(%rbp),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
mov    0x2d1e(%rip),%rax
mov    (%rax),%edx
call   10a0 <sock_setfilter@plt>
jmp    12d7 <test_datapath+0xf7>
mov    -0x38(%rbp),%rax
mov    0x2d1f(%rip),%rcx
cmp    (%rcx),%rax
jne    12d2 <test_datapath+0xf2>
mov    -0x40(%rbp),%edi
call   10c0 <sock_fanout_set_ebpf@plt>
jmp    12d7 <test_datapath+0xf7>
mov    -0x40(%rbp),%edi
call   1100 <sock_fanout_open_ring@plt>
mov    %rax,-0x30(%rbp)
mov    -0x3c(%rbp),%edi
call   1100 <sock_fanout_open_ring@plt>
mov    %rax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x1f40,%esi
call   10f0 <pair_udp_open@plt>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
mov    -0x8(%rbp),%esi
add    $0x1f40,%esi
call   10f0 <pair_udp_open@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sock_fanout_read@plt>
lea    -0x50(%rbp),%rdi
mov    $0xf,%esi
call   1040 <pair_udp_send@plt>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
mov    $0x5,%esi
mov    $0x62,%edx
call   1030 <pair_udp_send_char@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <sock_fanout_read@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0xf,%esi
mov    $0x62,%edx
call   1030 <pair_udp_send_char@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <sock_fanout_read@plt>
or     -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   10d0 <getpagesize@plt>
mov    -0x60(%rbp),%rdi
imul   $0x14,%eax,%esi
call   10b0 <munmap@plt>
cmp    $0x0,%rax
jne    13d1 <test_datapath+0x1f1>
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   10d0 <getpagesize@plt>
mov    -0x68(%rbp),%rdi
imul   $0x14,%eax,%esi
call   10b0 <munmap@plt>
cmp    $0x0,%rax
je     13f2 <test_datapath+0x212>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
lea    0xc49(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x44(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jne    145e <test_datapath+0x27e>
mov    -0x48(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jne    145e <test_datapath+0x27e>
mov    -0x4c(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jne    145e <test_datapath+0x27e>
mov    -0x50(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jne    145e <test_datapath+0x27e>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jne    145e <test_datapath+0x27e>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
je     147f <test_datapath+0x29f>
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
lea    0xbc9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x54(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_datapath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,0x38(%rsp)
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%ebp
movq   $0x0,0x40(%rsp)
mov    0x2dd5(%rip),%r14
mov    (%r14),%edi
lea    0xdfb(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebp,%edi
mov    $0x14,%esi
call   1080 <sock_fanout_open@plt>
mov    %eax,%ebx
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    $0x14,%esi
call   1080 <sock_fanout_open@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%ebx
je     1401 <test_datapath+0x231>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1401 <test_datapath+0x231>
movzbl %bpl,%eax
mov    0x2d68(%rip),%rcx
cmp    %rax,(%rcx)
jne    1270 <test_datapath+0xa0>
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1090 <sock_setfilter@plt>
jmp    1283 <test_datapath+0xb3>
mov    0x2d69(%rip),%rcx
cmp    %rax,(%rcx)
jne    1283 <test_datapath+0xb3>
mov    %ebx,%edi
call   10b0 <sock_fanout_set_ebpf@plt>
mov    %ebx,%edi
call   10f0 <sock_fanout_open_ring@plt>
mov    %rax,0x20(%rsp)
mov    %r13d,%edi
call   10f0 <sock_fanout_open_ring@plt>
mov    %rax,0x28(%rsp)
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x1f40,%esi
call   10e0 <pair_udp_open@plt>
lea    0x18(%rsp),%r14
add    $0x1f40,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
call   10e0 <pair_udp_open@plt>
lea    0x8(%rsp),%rbx
lea    0x20(%rsp),%rbp
lea    0x40(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <sock_fanout_read@plt>
mov    %r13,%rdi
mov    $0xf,%esi
call   1040 <pair_udp_send@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    $0x62,%edx
call   1030 <pair_udp_send_char@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1050 <sock_fanout_read@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    $0xf,%esi
mov    $0x62,%edx
call   1030 <pair_udp_send_char@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    0x38(%rsp),%rdx
call   1050 <sock_fanout_read@plt>
mov    %eax,%ebp
mov    0x28(%rsp),%rbx
xor    %eax,%eax
call   10c0 <getpagesize@plt>
shl    $0x2,%eax
lea    (%rax,%rax,4),%esi
mov    %rbx,%rdi
call   10a0 <munmap@plt>
test   %rax,%rax
jne    13ef <test_datapath+0x21f>
mov    0x20(%rsp),%rbx
xor    %eax,%eax
call   10c0 <getpagesize@plt>
shl    $0x2,%eax
lea    (%rax,%rax,4),%esi
mov    %rbx,%rdi
call   10a0 <munmap@plt>
test   %rax,%rax
jne    13ef <test_datapath+0x21f>
mov    0x1c(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13dd <test_datapath+0x20d>
mov    0x18(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13dd <test_datapath+0x20d>
mov    0x14(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13dd <test_datapath+0x20d>
mov    0x10(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13dd <test_datapath+0x20d>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13dd <test_datapath+0x20d>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
test   %rax,%rax
jne    13dd <test_datapath+0x20d>
or     %r15d,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bec(%rip),%rax
mov    (%rax),%edi
lea    0xc4a(%rip),%rsi
jmp    140b <test_datapath+0x23b>
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
lea    0xc2b(%rip),%rsi
jmp    140b <test_datapath+0x23b>
mov    (%r14),%edi
lea    0xc0b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"test: datapath 0x%hx\0A\00"
@.str.1 = [20 x i8] c"ERROR: failed open\0A\00"
@PACKET_FANOUT_CBPF = global i64 0
@SOL_PACKET = global i32 0
@PACKET_FANOUT_DATA = global i32 0
@PACKET_FANOUT_EBPF = global i64 0
@.str.2 = [13 x i8] c"close rings\0A\00"
@.str.3 = [16 x i8] c"close datapath\0A\00"
define i32 @test_datapath(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [2 x i32]
%10 = alloca [2 x i8*]
%11 = alloca i64
%12 = alloca [2 x i32]
%13 = alloca [2 x [2 x i32]]
%14 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%15 = bitcast [2 x i32]* %9 to i8*
%16 = load i32, i32* %5
%17 = and i32 %16, 255
%18 = sext i32 %17 to i64
store i64 %18, i64* %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* %5
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %5
%23 = call i32 @sock_fanout_open(i32 %22, i32 20)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
store i32 %23, i32* %24
%25 = load i32, i32* %5
%26 = call i32 @sock_fanout_open(i32 %25, i32 20)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
store i32 %26, i32* %27
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, -1
br i1 %30, label %35, label %31
31: ; preds = %4
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %31, %4
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i64, i64* %11
%41 = load i64, i64* @PACKET_FANOUT_CBPF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%45 = load i32, i32* %44
%46 = load i32, i32* @SOL_PACKET
%47 = load i32, i32* @PACKET_FANOUT_DATA
%48 = call i32 @sock_setfilter(i32 %45, i32 %46, i32 %47)
br label %58
49: ; preds = %39
%50 = load i64, i64* %11
%51 = load i64, i64* @PACKET_FANOUT_EBPF
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%55 = load i32, i32* %54
%56 = call i32 @sock_fanout_set_ebpf(i32 %55)
br label %57
57: ; preds = %53, %49
br label %58
58: ; preds = %57, %43
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i8* @sock_fanout_open_ring(i32 %60)
%62 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
store i8* %61, i8** %62
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%64 = load i32, i32* %63
%65 = call i8* @sock_fanout_open_ring(i32 %64)
%66 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 1
store i8* %65, i8** %66
%67 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %67, i64 0, i64 0
%69 = call i32 @pair_udp_open(i32* %68, i32 8000)
%70 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %70, i64 0, i64 0
%72 = load i32, i32* %6
%73 = add nsw i32 8000, %72
%74 = call i32 @pair_udp_open(i32* %71, i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%76 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%78 = call i32 @sock_fanout_read(i32* %75, i8** %76, i32* %77)
%79 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %79, i64 0, i64 0
%81 = call i32 @pair_udp_send(i32* %80, i32 15)
%82 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %82, i64 0, i64 0
%84 = call i32 @pair_udp_send_char(i32* %83, i32 5, i8 signext 98)
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%86 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%87 = load i32*, i32** %7
%88 = call i32 @sock_fanout_read(i32* %85, i8** %86, i32* %87)
store i32 %88, i32* %14
%89 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %89, i64 0, i64 0
%91 = call i32 @pair_udp_send_char(i32* %90, i32 15, i8 signext 98)
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%93 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%94 = load i32*, i32** %8
%95 = call i32 @sock_fanout_read(i32* %92, i8** %93, i32* %94)
%96 = load i32, i32* %14
%97 = or i32 %96, %95
store i32 %97, i32* %14
%98 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 1
%99 = load i8*, i8** %98
%100 = call i32 (...) @getpagesize()
%101 = mul nsw i32 20, %100
%102 = call i64 @munmap(i8* %99, i32 %101)
%103 = icmp ne i64 %102, 0
br i1 %103, label %111, label %104
104: ; preds = %58
%105 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%106 = load i8*, i8** %105
%107 = call i32 (...) @getpagesize()
%108 = mul nsw i32 20, %107
%109 = call i64 @munmap(i8* %106, i32 %108)
%110 = icmp ne i64 %109, 0
br i1 %110, label %111, label %115
111: ; preds = %104, %58
%112 = load i32, i32* @stderr
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %104
%116 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %116, i64 0, i64 1
%118 = load i32, i32* %117
%119 = call i64 @close(i32 %118)
%120 = icmp ne i64 %119, 0
br i1 %120, label %149, label %121
121: ; preds = %115
%122 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%123 = getelementptr inbounds [2 x i32], [2 x i32]* %122, i64 0, i64 0
%124 = load i32, i32* %123
%125 = call i64 @close(i32 %124)
%126 = icmp ne i64 %125, 0
br i1 %126, label %149, label %127
127: ; preds = %121
%128 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%129 = getelementptr inbounds [2 x i32], [2 x i32]* %128, i64 0, i64 1
%130 = load i32, i32* %129
%131 = call i64 @close(i32 %130)
%132 = icmp ne i64 %131, 0
br i1 %132, label %149, label %133
133: ; preds = %127
%134 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%135 = getelementptr inbounds [2 x i32], [2 x i32]* %134, i64 0, i64 0
%136 = load i32, i32* %135
%137 = call i64 @close(i32 %136)
%138 = icmp ne i64 %137, 0
br i1 %138, label %149, label %139
139: ; preds = %133
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%141 = load i32, i32* %140
%142 = call i64 @close(i32 %141)
%143 = icmp ne i64 %142, 0
br i1 %143, label %149, label %144
144: ; preds = %139
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%146 = load i32, i32* %145
%147 = call i64 @close(i32 %146)
%148 = icmp ne i64 %147, 0
br i1 %148, label %149, label %153
149: ; preds = %144, %139, %133, %127, %121, %115
%150 = load i32, i32* @stderr
%151 = call i32 (i32, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%152 = call i32 @exit(i32 1)
unreachable
153: ; preds = %144
%154 = load i32, i32* %14
ret i32 %154
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"test: datapath 0x%hx\0A\00"
@.str.1 = [20 x i8] c"ERROR: failed open\0A\00"
@PACKET_FANOUT_CBPF = global i64 0
@SOL_PACKET = global i32 0
@PACKET_FANOUT_DATA = global i32 0
@PACKET_FANOUT_EBPF = global i64 0
@.str.2 = [13 x i8] c"close rings\0A\00"
@.str.3 = [16 x i8] c"close datapath\0A\00"
define i32 @test_datapath(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i64
%6 = alloca [2 x i8*]
%7 = alloca [2 x i32]
%8 = alloca [2 x [2 x i32]]
%9 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%10 = bitcast [2 x i8*]* %6 to i8*
%11 = and i32 %0, 255
%12 = zext i32 %11 to i64
%13 = bitcast [2 x i32]* %7 to i8*
%14 = bitcast [2 x [2 x i32]]* %8 to i8*
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0)
%17 = tail call i32 @sock_fanout_open(i32 %0, i32 20)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %17, i32* %18
%19 = tail call i32 @sock_fanout_open(i32 %0, i32 20)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %19, i32* %20
%21 = icmp eq i32 %17, -1
%22 = icmp eq i32 %19, -1
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %4
%29 = load i64, i64* @PACKET_FANOUT_CBPF
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* @SOL_PACKET
%33 = load i32, i32* @PACKET_FANOUT_DATA
%34 = tail call i32 @sock_setfilter(i32 %17, i32 %32, i32 %33)
br label %40
35: ; preds = %28
%36 = load i64, i64* @PACKET_FANOUT_EBPF
%37 = icmp eq i64 %36, %12
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @sock_fanout_set_ebpf(i32 %17)
br label %40
40: ; preds = %35, %38, %31
%41 = tail call i8* @sock_fanout_open_ring(i32 %17)
%42 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
store i8* %41, i8** %42
%43 = tail call i8* @sock_fanout_open_ring(i32 %19)
%44 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
store i8* %43, i8** %44
%45 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0, i64 0
%46 = call i32 @pair_udp_open(i32* %45, i32 8000)
%47 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1, i64 0
%48 = add nsw i32 %1, 8000
%49 = call i32 @pair_udp_open(i32* %47, i32 %48)
%50 = bitcast i64* %5 to i32*
%51 = call i32 @sock_fanout_read(i32* %18, i8** %42, i32* %50)
%52 = call i32 @pair_udp_send(i32* %45, i32 15)
%53 = call i32 @pair_udp_send_char(i32* %47, i32 5, i8 signext 98)
%54 = call i32 @sock_fanout_read(i32* %18, i8** %42, i32* %2)
%55 = call i32 @pair_udp_send_char(i32* %45, i32 15, i8 signext 98)
%56 = call i32 @sock_fanout_read(i32* %18, i8** %42, i32* %3)
%57 = load i8*, i8** %44
%58 = call i32 (...) @getpagesize()
%59 = mul nsw i32 %58, 20
%60 = call i64 @munmap(i8* %57, i32 %59)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %40
%63 = load i8*, i8** %42
%64 = call i32 (...) @getpagesize()
%65 = mul nsw i32 %64, 20
%66 = call i64 @munmap(i8* %63, i32 %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %62, %40
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %62
%73 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1, i64 1
%74 = load i32, i32* %73
%75 = call i64 @close(i32 %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %98
77: ; preds = %72
%78 = load i32, i32* %47
%79 = call i64 @close(i32 %78)
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %98
81: ; preds = %77
%82 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0, i64 1
%83 = load i32, i32* %82
%84 = call i64 @close(i32 %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %98
86: ; preds = %81
%87 = load i32, i32* %45
%88 = call i64 @close(i32 %87)
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %98
90: ; preds = %86
%91 = load i32, i32* %20
%92 = call i64 @close(i32 %91)
%93 = icmp eq i64 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %90
%95 = load i32, i32* %18
%96 = call i64 @close(i32 %95)
%97 = icmp eq i64 %96, 0
br i1 %97, label %102, label %98
98: ; preds = %94, %90, %86, %81, %77, %72
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %94
%103 = or i32 %56, %54
ret i32 %103
}