#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;
scalar_t__ PACKET_FANOUT_EBPF;
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 /*<<< orphan*/);
char *sock_fanout_open_ring(int);
int sock_fanout_read(int *, char **, int const *);
int /*<<< orphan*/ sock_fanout_set_cbpf(int);
int /*<<< orphan*/ sock_fanout_set_ebpf(int);
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, 0);
  fds[1] = sock_fanout_open(typeflags, 0);
  if (fds[0] == -1 || fds[1] == -1) {
    fprintf(stderr, "ERROR: failed open\n");
    exit(1);
  }
  if (type == PACKET_FANOUT_CBPF)
    sock_fanout_set_cbpf(fds[0]);
  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   1070 <memset@plt>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10a0 <sock_fanout_open@plt>
mov    %eax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10a0 <sock_fanout_open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
je     125c <test_datapath+0x7c>
cmpl   $0xffffffff,-0x3c(%rbp)
jne    127d <test_datapath+0x9d>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    0x2d40(%rip),%rcx
cmp    (%rcx),%rax
jne    129e <test_datapath+0xbe>
mov    -0x40(%rbp),%edi
call   1030 <sock_fanout_set_cbpf@plt>
jmp    12bf <test_datapath+0xdf>
mov    -0x38(%rbp),%rax
mov    0x2d3f(%rip),%rcx
cmp    (%rcx),%rax
jne    12ba <test_datapath+0xda>
mov    -0x40(%rbp),%edi
call   10c0 <sock_fanout_set_ebpf@plt>
jmp    12bf <test_datapath+0xdf>
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   1060 <sock_fanout_read@plt>
lea    -0x50(%rbp),%rdi
mov    $0xf,%esi
call   1050 <pair_udp_send@plt>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
mov    $0x5,%esi
mov    $0x62,%edx
call   1040 <pair_udp_send_char@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <sock_fanout_read@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0xf,%esi
mov    $0x62,%edx
call   1040 <pair_udp_send_char@plt>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <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    13b9 <test_datapath+0x1d9>
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     13da <test_datapath+0x1fa>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
lea    0xc61(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jne    1446 <test_datapath+0x266>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jne    1446 <test_datapath+0x266>
mov    -0x4c(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jne    1446 <test_datapath+0x266>
mov    -0x50(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jne    1446 <test_datapath+0x266>
mov    -0x3c(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jne    1446 <test_datapath+0x266>
mov    -0x40(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
je     1467 <test_datapath+0x287>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
lea    0xbe1(%rip),%rsi
mov    $0x0,%al
call   1090 <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,%ebx
movq   $0x0,0x40(%rsp)
mov    0x2ddd(%rip),%r14
mov    (%r14),%edi
lea    0xdfb(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1090 <sock_fanout_open@plt>
mov    %eax,%ebp
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
xor    %esi,%esi
call   1090 <sock_fanout_open@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%ebp
je     13e8 <test_datapath+0x218>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     13e8 <test_datapath+0x218>
movzbl %bl,%eax
mov    0x2d7f(%rip),%rcx
cmp    %rax,(%rcx)
jne    1257 <test_datapath+0x87>
mov    %ebp,%edi
call   1030 <sock_fanout_set_cbpf@plt>
jmp    126a <test_datapath+0x9a>
mov    0x2d8a(%rip),%rcx
cmp    %rax,(%rcx)
jne    126a <test_datapath+0x9a>
mov    %ebp,%edi
call   10b0 <sock_fanout_set_ebpf@plt>
mov    %ebp,%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   1060 <sock_fanout_read@plt>
mov    %r13,%rdi
mov    $0xf,%esi
call   1050 <pair_udp_send@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    $0x62,%edx
call   1040 <pair_udp_send_char@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1060 <sock_fanout_read@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    $0xf,%esi
mov    $0x62,%edx
call   1040 <pair_udp_send_char@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    0x38(%rsp),%rdx
call   1060 <sock_fanout_read@plt>
mov    %eax,%ebx
mov    0x28(%rsp),%rbp
xor    %eax,%eax
call   10c0 <getpagesize@plt>
shl    $0x2,%eax
lea    (%rax,%rax,4),%esi
mov    %rbp,%rdi
call   10a0 <munmap@plt>
test   %rax,%rax
jne    13d6 <test_datapath+0x206>
mov    0x20(%rsp),%rbp
xor    %eax,%eax
call   10c0 <getpagesize@plt>
shl    $0x2,%eax
lea    (%rax,%rax,4),%esi
mov    %rbp,%rdi
call   10a0 <munmap@plt>
test   %rax,%rax
jne    13d6 <test_datapath+0x206>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
test   %rax,%rax
jne    13c4 <test_datapath+0x1f4>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
test   %rax,%rax
jne    13c4 <test_datapath+0x1f4>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
test   %rax,%rax
jne    13c4 <test_datapath+0x1f4>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
test   %rax,%rax
jne    13c4 <test_datapath+0x1f4>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
test   %rax,%rax
jne    13c4 <test_datapath+0x1f4>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
test   %rax,%rax
jne    13c4 <test_datapath+0x1f4>
or     %r15d,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c0d(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
jmp    13f2 <test_datapath+0x222>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
lea    0xc44(%rip),%rsi
jmp    13f2 <test_datapath+0x222>
mov    (%r14),%edi
lea    0xc24(%rip),%rsi
xor    %eax,%eax
call   1080 <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
@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 0)
%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 0)
%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 %47
43: ; preds = %39
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%45 = load i32, i32* %44
%46 = call i32 @sock_fanout_set_cbpf(i32 %45)
br label %56
47: ; preds = %39
%48 = load i64, i64* %11
%49 = load i64, i64* @PACKET_FANOUT_EBPF
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @sock_fanout_set_ebpf(i32 %53)
br label %55
55: ; preds = %51, %47
br label %56
56: ; preds = %55, %43
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%58 = load i32, i32* %57
%59 = call i8* @sock_fanout_open_ring(i32 %58)
%60 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
store i8* %59, i8** %60
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%62 = load i32, i32* %61
%63 = call i8* @sock_fanout_open_ring(i32 %62)
%64 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 1
store i8* %63, i8** %64
%65 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %65, i64 0, i64 0
%67 = call i32 @pair_udp_open(i32* %66, i32 8000)
%68 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %68, i64 0, i64 0
%70 = load i32, i32* %6
%71 = add nsw i32 8000, %70
%72 = call i32 @pair_udp_open(i32* %69, i32 %71)
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%74 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%76 = call i32 @sock_fanout_read(i32* %73, i8** %74, i32* %75)
%77 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %77, i64 0, i64 0
%79 = call i32 @pair_udp_send(i32* %78, i32 15)
%80 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %80, i64 0, i64 0
%82 = call i32 @pair_udp_send_char(i32* %81, i32 5, i8 signext 98)
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%84 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%85 = load i32*, i32** %7
%86 = call i32 @sock_fanout_read(i32* %83, i8** %84, i32* %85)
store i32 %86, i32* %14
%87 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %87, i64 0, i64 0
%89 = call i32 @pair_udp_send_char(i32* %88, i32 15, i8 signext 98)
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%91 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%92 = load i32*, i32** %8
%93 = call i32 @sock_fanout_read(i32* %90, i8** %91, i32* %92)
%94 = load i32, i32* %14
%95 = or i32 %94, %93
store i32 %95, i32* %14
%96 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 1
%97 = load i8*, i8** %96
%98 = call i32 (...) @getpagesize()
%99 = mul nsw i32 20, %98
%100 = call i64 @munmap(i8* %97, i32 %99)
%101 = icmp ne i64 %100, 0
br i1 %101, label %109, label %102
102: ; preds = %56
%103 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%104 = load i8*, i8** %103
%105 = call i32 (...) @getpagesize()
%106 = mul nsw i32 20, %105
%107 = call i64 @munmap(i8* %104, i32 %106)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %102, %56
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %102
%114 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%115 = getelementptr inbounds [2 x i32], [2 x i32]* %114, i64 0, i64 1
%116 = load i32, i32* %115
%117 = call i64 @close(i32 %116)
%118 = icmp ne i64 %117, 0
br i1 %118, label %147, label %119
119: ; preds = %113
%120 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 1
%121 = getelementptr inbounds [2 x i32], [2 x i32]* %120, i64 0, i64 0
%122 = load i32, i32* %121
%123 = call i64 @close(i32 %122)
%124 = icmp ne i64 %123, 0
br i1 %124, label %147, label %125
125: ; preds = %119
%126 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %126, i64 0, i64 1
%128 = load i32, i32* %127
%129 = call i64 @close(i32 %128)
%130 = icmp ne i64 %129, 0
br i1 %130, label %147, label %131
131: ; preds = %125
%132 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %13, i64 0, i64 0
%133 = getelementptr inbounds [2 x i32], [2 x i32]* %132, i64 0, i64 0
%134 = load i32, i32* %133
%135 = call i64 @close(i32 %134)
%136 = icmp ne i64 %135, 0
br i1 %136, label %147, label %137
137: ; preds = %131
%138 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%139 = load i32, i32* %138
%140 = call i64 @close(i32 %139)
%141 = icmp ne i64 %140, 0
br i1 %141, label %147, label %142
142: ; preds = %137
%143 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%144 = load i32, i32* %143
%145 = call i64 @close(i32 %144)
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %151
147: ; preds = %142, %137, %131, %125, %119, %113
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%150 = call i32 @exit(i32 1)
unreachable
151: ; preds = %142
%152 = load i32, i32* %14
ret i32 %152
}

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
@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 0)
%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 0)
%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 %33
31: ; preds = %28
%32 = tail call i32 @sock_fanout_set_cbpf(i32 %17)
br label %38
33: ; preds = %28
%34 = load i64, i64* @PACKET_FANOUT_EBPF
%35 = icmp eq i64 %34, %12
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call i32 @sock_fanout_set_ebpf(i32 %17)
br label %38
38: ; preds = %33, %36, %31
%39 = tail call i8* @sock_fanout_open_ring(i32 %17)
%40 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
store i8* %39, i8** %40
%41 = tail call i8* @sock_fanout_open_ring(i32 %19)
%42 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
store i8* %41, i8** %42
%43 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0, i64 0
%44 = call i32 @pair_udp_open(i32* %43, i32 8000)
%45 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1, i64 0
%46 = add nsw i32 %1, 8000
%47 = call i32 @pair_udp_open(i32* %45, i32 %46)
%48 = bitcast i64* %5 to i32*
%49 = call i32 @sock_fanout_read(i32* %18, i8** %40, i32* %48)
%50 = call i32 @pair_udp_send(i32* %43, i32 15)
%51 = call i32 @pair_udp_send_char(i32* %45, i32 5, i8 signext 98)
%52 = call i32 @sock_fanout_read(i32* %18, i8** %40, i32* %2)
%53 = call i32 @pair_udp_send_char(i32* %43, i32 15, i8 signext 98)
%54 = call i32 @sock_fanout_read(i32* %18, i8** %40, i32* %3)
%55 = load i8*, i8** %42
%56 = call i32 (...) @getpagesize()
%57 = mul nsw i32 %56, 20
%58 = call i64 @munmap(i8* %55, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %38
%61 = load i8*, i8** %40
%62 = call i32 (...) @getpagesize()
%63 = mul nsw i32 %62, 20
%64 = call i64 @munmap(i8* %61, i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %60, %38
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %60
%71 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 1, i64 1
%72 = load i32, i32* %71
%73 = call i64 @close(i32 %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %96
75: ; preds = %70
%76 = load i32, i32* %45
%77 = call i64 @close(i32 %76)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %96
79: ; preds = %75
%80 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %8, i64 0, i64 0, i64 1
%81 = load i32, i32* %80
%82 = call i64 @close(i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %96
84: ; preds = %79
%85 = load i32, i32* %43
%86 = call i64 @close(i32 %85)
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %96
88: ; preds = %84
%89 = load i32, i32* %20
%90 = call i64 @close(i32 %89)
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %88
%93 = load i32, i32* %18
%94 = call i64 @close(i32 %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %100, label %96
96: ; preds = %92, %88, %84, %79, %75, %70
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %92
%101 = or i32 %54, %52
ret i32 %101
}