#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 int /*<<< orphan*/ values;
typedef int /*<<< orphan*/ key;

/* Variables and functions */
int /*<<< orphan*/ BPF_ANY;
int /*<<< orphan*/ BPF_EXIST;
int /*<<< orphan*/ BPF_MAP_TYPE_PERCPU_ARRAY;
int /*<<< orphan*/ BPF_NOEXIST;
scalar_t__ E2BIG;
scalar_t__ EEXIST;
scalar_t__ EINVAL;
scalar_t__ ENOENT;
int /*<<< orphan*/ _SC_NPROCESSORS_CONF;
int /*<<< orphan*/ assert(int);
int bpf_create_map(int /*<<< orphan*/, int, int, int, int /*<<< orphan*/);
int bpf_delete_elem(int, int *);
int bpf_get_next_key(int, int *, int *);
int bpf_lookup_elem(int, int *, long *);
int bpf_update_elem(int, int *, long *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(scalar_t__);
unsigned int sysconf(int /*<<< orphan*/);
void test_percpu_arraymap_sanity(int i, void *data) {
  unsigned nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
  long values[nr_cpus];
  int key, next_key, map_fd;
  map_fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key),
                          sizeof(values[0]), 2, 0);
  if (map_fd < 0) {
    printf("failed to create arraymap '%s'\n", strerror(errno));
    exit(1);
  }
  for (i = 0; i < nr_cpus; i++) {
    values[i] = i + 100;
  }
  key = 1;
  assert(bpf_update_elem(map_fd, &key, values, BPF_ANY) == 0);
  values[0] = 0;
  assert(bpf_update_elem(map_fd, &key, values, BPF_NOEXIST) == -1 &&
         errno == EEXIST);
  assert(bpf_lookup_elem(map_fd, &key, values) == 0 && values[0] == 100);
  key = 0;
  assert(bpf_lookup_elem(map_fd, &key, values) == 0 && values[0] == 0 &&
         values[nr_cpus - 1] == 0);
  key = 2;
  assert(bpf_update_elem(map_fd, &key, values, BPF_EXIST) == -1 &&
         errno == E2BIG);
  assert(bpf_lookup_elem(map_fd, &key, values) == -1 && errno == ENOENT);
  assert(bpf_get_next_key(map_fd, &key, &next_key) == 0 && next_key == 0);
  assert(bpf_get_next_key(map_fd, &next_key, &next_key) == 0 && next_key == 1);
  assert(bpf_get_next_key(map_fd, &next_key, &next_key) == -1 &&
         errno == ENOENT);
  key = 1;
  assert(bpf_delete_elem(map_fd, &key) == -1 && errno == EINVAL);
  close(map_fd);
}


x86 assembly (clang, -O0):
<test_percpu_arraymap_sanity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    $0x4,%esi
mov    $0x8,%edx
mov    $0x2,%ecx
xor    %r8d,%r8d
call   1060 <bpf_create_map@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    124c <test_percpu_arraymap_sanity+0x9c>
mov    0x2d95(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xdc3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1282 <test_percpu_arraymap_sanity+0xd2>
mov    -0x40(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x64,%ecx
movslq %ecx,%rdx
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <test_percpu_arraymap_sanity+0xa3>
mov    -0x40(%rbp),%rdx
movl   $0x1,-0x2c(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%ecx
lea    -0x2c(%rbp),%rsi
call   1070 <bpf_update_elem@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rdx
movq   $0x0,(%rdx)
mov    -0x34(%rbp),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%ecx
lea    -0x2c(%rbp),%rsi
call   1070 <bpf_update_elem@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x41(%rbp)
jne    12fc <test_percpu_arraymap_sanity+0x14c>
mov    0x2cd7(%rip),%rax
mov    (%rax),%rax
mov    0x2cdd(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1080 <bpf_lookup_elem@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x42(%rbp)
jne    1337 <test_percpu_arraymap_sanity+0x187>
mov    -0x40(%rbp),%rax
cmpq   $0x64,(%rax)
sete   %al
mov    %al,-0x42(%rbp)
mov    -0x42(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rdx
movl   $0x0,-0x2c(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1080 <bpf_lookup_elem@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x43(%rbp)
jne    1395 <test_percpu_arraymap_sanity+0x1e5>
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x43(%rbp)
jne    1395 <test_percpu_arraymap_sanity+0x1e5>
mov    -0x40(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
cmpq   $0x0,(%rax,%rcx,8)
sete   %al
mov    %al,-0x43(%rbp)
mov    -0x43(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rdx
movl   $0x2,-0x2c(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2c01(%rip),%rax
mov    (%rax),%ecx
lea    -0x2c(%rbp),%rsi
call   1070 <bpf_update_elem@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x44(%rbp)
jne    13ec <test_percpu_arraymap_sanity+0x23c>
mov    0x2be7(%rip),%rax
mov    (%rax),%rax
mov    0x2c05(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x44(%rbp)
mov    -0x44(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1080 <bpf_lookup_elem@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x45(%rbp)
jne    1433 <test_percpu_arraymap_sanity+0x283>
mov    0x2ba0(%rip),%rax
mov    (%rax),%rax
mov    0x2b66(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   10d0 <bpf_get_next_key@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x46(%rbp)
jne    146a <test_percpu_arraymap_sanity+0x2ba>
cmpl   $0x0,-0x30(%rbp)
sete   %al
mov    %al,-0x46(%rbp)
mov    -0x46(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rdx
mov    %rdx,%rsi
call   10d0 <bpf_get_next_key@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x47(%rbp)
jne    14a0 <test_percpu_arraymap_sanity+0x2f0>
cmpl   $0x1,-0x30(%rbp)
sete   %al
mov    %al,-0x47(%rbp)
mov    -0x47(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rdx
mov    %rdx,%rsi
call   10d0 <bpf_get_next_key@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x48(%rbp)
jne    14e6 <test_percpu_arraymap_sanity+0x336>
mov    0x2aed(%rip),%rax
mov    (%rax),%rax
mov    0x2ab3(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x48(%rbp)
mov    -0x48(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   10b0 <bpf_delete_elem@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x49(%rbp)
jne    1530 <test_percpu_arraymap_sanity+0x380>
mov    0x2aa3(%rip),%rax
mov    (%rax),%rax
mov    0x2a81(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_percpu_arraymap_sanity>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
mov    %eax,%r12d
mov    %rsp,%rbx
lea    0xf(,%r12,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    $0x4,%esi
mov    $0x8,%edx
mov    $0x2,%ecx
xor    %r8d,%r8d
call   1060 <bpf_create_map@plt>
test   %eax,%eax
js     15b7 <test_percpu_arraymap_sanity+0x407>
mov    %eax,%r14d
test   %r12,%r12
je     13ba <test_percpu_arraymap_sanity+0x20a>
cmp    $0x4,%r12d
jae    1225 <test_percpu_arraymap_sanity+0x75>
xor    %eax,%eax
jmp    138d <test_percpu_arraymap_sanity+0x1dd>
mov    %r12d,%eax
and    $0xfffffffc,%eax
lea    -0x4(%rax),%rsi
mov    %rsi,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0xc,%rsi
jae    1254 <test_percpu_arraymap_sanity+0xa4>
movdqa 0xdb3(%rip),%xmm0
xor    %esi,%esi
jmp    1335 <test_percpu_arraymap_sanity+0x185>
and    $0xfffffffffffffffc,%rdx
movdqa 0xda0(%rip),%xmm0
xor    %esi,%esi
movdqa 0xda5(%rip),%xmm8
movdqa 0xdac(%rip),%xmm9
movdqa 0xdb3(%rip),%xmm10
movdqa 0xdba(%rip),%xmm11
movdqa 0xdc2(%rip),%xmm5
movdqa 0xdca(%rip),%xmm6
movdqa 0xdd2(%rip),%xmm7
movdqa 0xdda(%rip),%xmm1
movdqa 0xde2(%rip),%xmm2
xchg   %ax,%ax
movdqa %xmm0,%xmm3
paddq  %xmm8,%xmm3
movdqa %xmm0,%xmm4
paddq  %xmm9,%xmm4
movdqa %xmm3,(%rbx,%rsi,8)
movdqa %xmm4,0x10(%rbx,%rsi,8)
movdqa %xmm0,%xmm3
paddq  %xmm10,%xmm3
movdqa %xmm0,%xmm4
paddq  %xmm11,%xmm4
movdqa %xmm3,0x20(%rbx,%rsi,8)
movdqa %xmm4,0x30(%rbx,%rsi,8)
movdqa %xmm0,%xmm3
paddq  %xmm5,%xmm3
movdqa %xmm0,%xmm4
paddq  %xmm6,%xmm4
movdqa %xmm3,0x40(%rbx,%rsi,8)
movdqa %xmm4,0x50(%rbx,%rsi,8)
movdqa %xmm0,%xmm3
paddq  %xmm7,%xmm3
movdqa %xmm0,%xmm4
paddq  %xmm1,%xmm4
movdqa %xmm3,0x60(%rbx,%rsi,8)
movdqa %xmm4,0x70(%rbx,%rsi,8)
add    $0x10,%rsi
paddq  %xmm2,%xmm0
add    $0xfffffffffffffffc,%rdx
jne    12b0 <test_percpu_arraymap_sanity+0x100>
test   %rcx,%rcx
je     1388 <test_percpu_arraymap_sanity+0x1d8>
lea    (%rbx,%rsi,8),%rdx
add    $0x10,%rdx
shl    $0x5,%rcx
xor    %esi,%esi
movdqa 0xcc0(%rip),%xmm1
movdqa 0xcc8(%rip),%xmm2
movdqa 0xd40(%rip),%xmm3
movdqa %xmm0,%xmm4
paddq  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddq  %xmm2,%xmm5
movdqa %xmm4,-0x10(%rdx,%rsi,1)
movdqa %xmm5,(%rdx,%rsi,1)
paddq  %xmm3,%xmm0
add    $0x20,%rsi
cmp    %rsi,%rcx
jne    1360 <test_percpu_arraymap_sanity+0x1b0>
cmp    %r12,%rax
je     13ba <test_percpu_arraymap_sanity+0x20a>
add    $0x64,%rax
mov    %r12,%rcx
neg    %rcx
nopw   0x0(%rax,%rax,1)
mov    %rax,-0x320(%rbx,%rax,8)
ff
lea    (%rcx,%rax,1),%rdx
add    $0x1,%rdx
add    $0x1,%rax
cmp    $0x64,%rdx
jne    13a0 <test_percpu_arraymap_sanity+0x1f0>
movl   $0x1,-0x2c(%rbp)
mov    0x2c10(%rip),%rax
mov    (%rax),%ecx
lea    -0x2c(%rbp),%r15
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <bpf_update_elem@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
movq   $0x0,(%rbx)
mov    0x2bd1(%rip),%rax
mov    (%rax),%ecx
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <bpf_update_elem@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2bac(%rip),%r13
mov    0x0(%r13),%rcx
mov    0x2bb1(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <bpf_lookup_elem@plt>
xor    %r15d,%r15d
mov    $0x0,%edi
test   %eax,%eax
jne    1453 <test_percpu_arraymap_sanity+0x2a3>
xor    %edi,%edi
cmpq   $0x64,(%rbx)
sete   %dil
call   1050 <assert@plt>
movl   $0x0,-0x2c(%rbp)
lea    -0x2c(%rbp),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1080 <bpf_lookup_elem@plt>
test   %eax,%eax
jne    1488 <test_percpu_arraymap_sanity+0x2d8>
cmpq   $0x0,(%rbx)
jne    1488 <test_percpu_arraymap_sanity+0x2d8>
add    $0xffffffff,%r12d
xor    %r15d,%r15d
cmpq   $0x0,(%rbx,%r12,8)
sete   %r15b
mov    %r15d,%edi
call   1050 <assert@plt>
movl   $0x2,-0x2c(%rbp)
mov    0x2b1a(%rip),%rax
mov    (%rax),%ecx
lea    -0x2c(%rbp),%r15
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <bpf_update_elem@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x0(%r13),%rcx
mov    0x2b25(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <bpf_lookup_elem@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x0(%r13),%rcx
mov    0x2a9e(%rip),%r12
cmp    (%r12),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
lea    -0x30(%rbp),%rbx
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10d0 <bpf_get_next_key@plt>
xor    %edi,%edi
or     -0x30(%rbp),%eax
sete   %dil
call   1050 <assert@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   10d0 <bpf_get_next_key@plt>
mov    -0x30(%rbp),%ecx
xor    $0x1,%ecx
xor    %edi,%edi
or     %eax,%ecx
sete   %dil
call   1050 <assert@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   10d0 <bpf_get_next_key@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x0(%r13),%rcx
cmp    (%r12),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
movl   $0x1,-0x2c(%rbp)
mov    %r14d,%edi
mov    %r15,%rsi
call   10b0 <bpf_delete_elem@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x0(%r13),%rcx
mov    0x2a18(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %r14d,%edi
call   1040 <close@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a02(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xae3(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@_SC_NPROCESSORS_CONF = global i32 0
@BPF_MAP_TYPE_PERCPU_ARRAY = global i32 0
@.str = [32 x i8] c"failed to create arraymap '%s'\0A\00"
@errno = global i64 0
@BPF_ANY = global i32 0
@BPF_NOEXIST = global i32 0
@EEXIST = global i64 0
@BPF_EXIST = global i32 0
@E2BIG = global i64 0
@ENOENT = global i64 0
@EINVAL = global i64 0
define void @test_percpu_arraymap_sanity(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%11 = load i32, i32* @_SC_NPROCESSORS_CONF
%12 = call i32 @sysconf(i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i64, i64 %14
store i64 %14, i64* %7
%17 = load i32, i32* @BPF_MAP_TYPE_PERCPU_ARRAY
%18 = call i32 @bpf_create_map(i32 %17, i32 4, i32 8, i32 2, i32 0)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
store i32 0, i32* %3
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 100
%34 = sext i32 %33 to i64
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i64, i64* %16, i64 %36
store i64 %34, i64* %37
br label %38
38: ; preds = %31
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %27
41: ; preds = %27
store i32 1, i32* %8
%42 = load i32, i32* %10
%43 = load i32, i32* @BPF_ANY
%44 = call i32 @bpf_update_elem(i32 %42, i32* %8, i64* %16, i32 %43)
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = getelementptr inbounds i64, i64* %16, i64 0
store i64 0, i64* %48
%49 = load i32, i32* %10
%50 = load i32, i32* @BPF_NOEXIST
%51 = call i32 @bpf_update_elem(i32 %49, i32* %8, i64* %16, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %41
%54 = load i64, i64* @errno
%55 = load i64, i64* @EEXIST
%56 = icmp eq i64 %54, %55
br label %57
57: ; preds = %53, %41
%58 = phi i1 [ false, %41 ], [ %56, %53 ]
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i32, i32* %10
%62 = call i32 @bpf_lookup_elem(i32 %61, i32* %8, i64* %16)
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %57
%65 = getelementptr inbounds i64, i64* %16, i64 0
%66 = load i64, i64* %65
%67 = icmp eq i64 %66, 100
br label %68
68: ; preds = %64, %57
%69 = phi i1 [ false, %57 ], [ %67, %64 ]
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
store i32 0, i32* %8
%72 = load i32, i32* %10
%73 = call i32 @bpf_lookup_elem(i32 %72, i32* %8, i64* %16)
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %86
75: ; preds = %68
%76 = getelementptr inbounds i64, i64* %16, i64 0
%77 = load i64, i64* %76
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %86
79: ; preds = %75
%80 = load i32, i32* %5
%81 = sub i32 %80, 1
%82 = zext i32 %81 to i64
%83 = getelementptr inbounds i64, i64* %16, i64 %82
%84 = load i64, i64* %83
%85 = icmp eq i64 %84, 0
br label %86
86: ; preds = %79, %75, %68
%87 = phi i1 [ false, %75 ], [ false, %68 ], [ %85, %79 ]
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
store i32 2, i32* %8
%90 = load i32, i32* %10
%91 = load i32, i32* @BPF_EXIST
%92 = call i32 @bpf_update_elem(i32 %90, i32* %8, i64* %16, i32 %91)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %98
94: ; preds = %86
%95 = load i64, i64* @errno
%96 = load i64, i64* @E2BIG
%97 = icmp eq i64 %95, %96
br label %98
98: ; preds = %94, %86
%99 = phi i1 [ false, %86 ], [ %97, %94 ]
%100 = zext i1 %99 to i32
%101 = call i32 @assert(i32 %100)
%102 = load i32, i32* %10
%103 = call i32 @bpf_lookup_elem(i32 %102, i32* %8, i64* %16)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %109
105: ; preds = %98
%106 = load i64, i64* @errno
%107 = load i64, i64* @ENOENT
%108 = icmp eq i64 %106, %107
br label %109
109: ; preds = %105, %98
%110 = phi i1 [ false, %98 ], [ %108, %105 ]
%111 = zext i1 %110 to i32
%112 = call i32 @assert(i32 %111)
%113 = load i32, i32* %10
%114 = call i32 @bpf_get_next_key(i32 %113, i32* %8, i32* %9)
%115 = icmp eq i32 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %109
%117 = load i32, i32* %9
%118 = icmp eq i32 %117, 0
br label %119
119: ; preds = %116, %109
%120 = phi i1 [ false, %109 ], [ %118, %116 ]
%121 = zext i1 %120 to i32
%122 = call i32 @assert(i32 %121)
%123 = load i32, i32* %10
%124 = call i32 @bpf_get_next_key(i32 %123, i32* %9, i32* %9)
%125 = icmp eq i32 %124, 0
br i1 %125, label %126, label %129
126: ; preds = %119
%127 = load i32, i32* %9
%128 = icmp eq i32 %127, 1
br label %129
129: ; preds = %126, %119
%130 = phi i1 [ false, %119 ], [ %128, %126 ]
%131 = zext i1 %130 to i32
%132 = call i32 @assert(i32 %131)
%133 = load i32, i32* %10
%134 = call i32 @bpf_get_next_key(i32 %133, i32* %9, i32* %9)
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %140
136: ; preds = %129
%137 = load i64, i64* @errno
%138 = load i64, i64* @ENOENT
%139 = icmp eq i64 %137, %138
br label %140
140: ; preds = %136, %129
%141 = phi i1 [ false, %129 ], [ %139, %136 ]
%142 = zext i1 %141 to i32
%143 = call i32 @assert(i32 %142)
store i32 1, i32* %8
%144 = load i32, i32* %10
%145 = call i32 @bpf_delete_elem(i32 %144, i32* %8)
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %151
147: ; preds = %140
%148 = load i64, i64* @errno
%149 = load i64, i64* @EINVAL
%150 = icmp eq i64 %148, %149
br label %151
151: ; preds = %147, %140
%152 = phi i1 [ false, %140 ], [ %150, %147 ]
%153 = zext i1 %152 to i32
%154 = call i32 @assert(i32 %153)
%155 = load i32, i32* %10
%156 = call i32 @close(i32 %155)
%157 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@_SC_NPROCESSORS_CONF = global i32 0
@BPF_MAP_TYPE_PERCPU_ARRAY = global i32 0
@.str = [32 x i8] c"failed to create arraymap '%s'\0A\00"
@errno = global i64 0
@BPF_ANY = global i32 0
@BPF_NOEXIST = global i32 0
@EEXIST = global i64 0
@BPF_EXIST = global i32 0
@E2BIG = global i64 0
@ENOENT = global i64 0
@EINVAL = global i64 0
define void @test_percpu_arraymap_sanity(i32 %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @_SC_NPROCESSORS_CONF
%6 = tail call i32 @sysconf(i32 %5)
%7 = zext i32 %6 to i64
%8 = alloca i64, i64 %7
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = load i32, i32* @BPF_MAP_TYPE_PERCPU_ARRAY
%12 = tail call i32 @bpf_create_map(i32 %11, i32 4, i32 8, i32 2, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %84, label %14
14: ; preds = %2
%15 = icmp eq i32 %6, 0
br i1 %15, label %95, label %16
16: ; preds = %14
%17 = icmp ult i32 %6, 4
br i1 %17, label %82, label %18
18: ; preds = %16
%19 = and i64 %7, 4294967292
%20 = add nsw i64 %19, -4
%21 = lshr exact i64 %20, 2
%22 = add nuw nsw i64 %21, 1
%23 = and i64 %22, 3
%24 = icmp ult i64 %20, 12
br i1 %24, label %62, label %25
25: ; preds = %18
%26 = and i64 %22, 9223372036854775804
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %58, %27 ]
%29 = phi <2 x i64> [ <i64 0, i64 1>, %25 ], [ %59, %27 ]
%30 = phi i64 [ 0, %25 ], [ %60, %27 ]
%31 = add nuw nsw <2 x i64> %29, <i64 100, i64 100>
%32 = add <2 x i64> %29, <i64 102, i64 102>
%33 = getelementptr inbounds i64, i64* %8, i64 %28
%34 = bitcast i64* %33 to <2 x i64>*
store <2 x i64> %31, <2 x i64>* %34
%35 = getelementptr inbounds i64, i64* %33, i64 2
%36 = bitcast i64* %35 to <2 x i64>*
store <2 x i64> %32, <2 x i64>* %36
%37 = or i64 %28, 4
%38 = add <2 x i64> %29, <i64 104, i64 104>
%39 = add <2 x i64> %29, <i64 106, i64 106>
%40 = getelementptr inbounds i64, i64* %8, i64 %37
%41 = bitcast i64* %40 to <2 x i64>*
store <2 x i64> %38, <2 x i64>* %41
%42 = getelementptr inbounds i64, i64* %40, i64 2
%43 = bitcast i64* %42 to <2 x i64>*
store <2 x i64> %39, <2 x i64>* %43
%44 = or i64 %28, 8
%45 = add <2 x i64> %29, <i64 108, i64 108>
%46 = add <2 x i64> %29, <i64 110, i64 110>
%47 = getelementptr inbounds i64, i64* %8, i64 %44
%48 = bitcast i64* %47 to <2 x i64>*
store <2 x i64> %45, <2 x i64>* %48
%49 = getelementptr inbounds i64, i64* %47, i64 2
%50 = bitcast i64* %49 to <2 x i64>*
store <2 x i64> %46, <2 x i64>* %50
%51 = or i64 %28, 12
%52 = add <2 x i64> %29, <i64 112, i64 112>
%53 = add <2 x i64> %29, <i64 114, i64 114>
%54 = getelementptr inbounds i64, i64* %8, i64 %51
%55 = bitcast i64* %54 to <2 x i64>*
store <2 x i64> %52, <2 x i64>* %55
%56 = getelementptr inbounds i64, i64* %54, i64 2
%57 = bitcast i64* %56 to <2 x i64>*
store <2 x i64> %53, <2 x i64>* %57
%58 = add nuw i64 %28, 16
%59 = add <2 x i64> %29, <i64 16, i64 16>
%60 = add nuw i64 %30, 4
%61 = icmp eq i64 %60, %26
br i1 %61, label %62, label %27
62: ; preds = %27, %18
%63 = phi i64 [ 0, %18 ], [ %58, %27 ]
%64 = phi <2 x i64> [ <i64 0, i64 1>, %18 ], [ %59, %27 ]
%65 = icmp eq i64 %23, 0
br i1 %65, label %80, label %66
66: ; preds = %62, %66
%67 = phi i64 [ %76, %66 ], [ %63, %62 ]
%68 = phi <2 x i64> [ %77, %66 ], [ %64, %62 ]
%69 = phi i64 [ %78, %66 ], [ 0, %62 ]
%70 = add nuw nsw <2 x i64> %68, <i64 100, i64 100>
%71 = add <2 x i64> %68, <i64 102, i64 102>
%72 = getelementptr inbounds i64, i64* %8, i64 %67
%73 = bitcast i64* %72 to <2 x i64>*
store <2 x i64> %70, <2 x i64>* %73
%74 = getelementptr inbounds i64, i64* %72, i64 2
%75 = bitcast i64* %74 to <2 x i64>*
store <2 x i64> %71, <2 x i64>* %75
%76 = add nuw i64 %67, 4
%77 = add <2 x i64> %68, <i64 4, i64 4>
%78 = add i64 %69, 1
%79 = icmp eq i64 %78, %23
br i1 %79, label %80, label %66
80: ; preds = %66, %62
%81 = icmp eq i64 %19, %7
br i1 %81, label %95, label %82
82: ; preds = %16, %80
%83 = phi i64 [ 0, %16 ], [ %19, %80 ]
br label %89
84: ; preds = %2
%85 = load i64, i64* @errno
%86 = tail call i8* @strerror(i64 %85)
%87 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %86)
%88 = tail call i32 @exit(i32 1)
unreachable
89: ; preds = %82, %89
%90 = phi i64 [ %93, %89 ], [ %83, %82 ]
%91 = add nuw nsw i64 %90, 100
%92 = getelementptr inbounds i64, i64* %8, i64 %90
store i64 %91, i64* %92
%93 = add nuw nsw i64 %90, 1
%94 = icmp eq i64 %93, %7
br i1 %94, label %95, label %89
95: ; preds = %89, %80, %14
store i32 1, i32* %3
%96 = load i32, i32* @BPF_ANY
%97 = call i32 @bpf_update_elem(i32 %12, i32* %3, i64* %8, i32 %96)
%98 = icmp eq i32 %97, 0
%99 = zext i1 %98 to i32
%100 = call i32 @assert(i32 %99)
store i64 0, i64* %8
%101 = load i32, i32* @BPF_NOEXIST
%102 = call i32 @bpf_update_elem(i32 %12, i32* %3, i64* %8, i32 %101)
%103 = icmp eq i32 %102, -1
%104 = load i64, i64* @errno
%105 = load i64, i64* @EEXIST
%106 = icmp eq i64 %104, %105
%107 = select i1 %103, i1 %106, i1 false
%108 = zext i1 %107 to i32
%109 = call i32 @assert(i32 %108)
%110 = call i32 @bpf_lookup_elem(i32 %12, i32* %3, i64* %8)
%111 = icmp eq i32 %110, 0
br i1 %111, label %112, label %116
112: ; preds = %95
%113 = load i64, i64* %8
%114 = icmp eq i64 %113, 100
%115 = zext i1 %114 to i32
br label %116
116: ; preds = %112, %95
%117 = phi i32 [ 0, %95 ], [ %115, %112 ]
%118 = call i32 @assert(i32 %117)
store i32 0, i32* %3
%119 = call i32 @bpf_lookup_elem(i32 %12, i32* %3, i64* %8)
%120 = icmp eq i32 %119, 0
br i1 %120, label %121, label %131
121: ; preds = %116
%122 = load i64, i64* %8
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %131
124: ; preds = %121
%125 = add i32 %6, -1
%126 = zext i32 %125 to i64
%127 = getelementptr inbounds i64, i64* %8, i64 %126
%128 = load i64, i64* %127
%129 = icmp eq i64 %128, 0
%130 = zext i1 %129 to i32
br label %131
131: ; preds = %124, %121, %116
%132 = phi i32 [ 0, %121 ], [ 0, %116 ], [ %130, %124 ]
%133 = call i32 @assert(i32 %132)
store i32 2, i32* %3
%134 = load i32, i32* @BPF_EXIST
%135 = call i32 @bpf_update_elem(i32 %12, i32* %3, i64* %8, i32 %134)
%136 = icmp eq i32 %135, -1
%137 = load i64, i64* @errno
%138 = load i64, i64* @E2BIG
%139 = icmp eq i64 %137, %138
%140 = select i1 %136, i1 %139, i1 false
%141 = zext i1 %140 to i32
%142 = call i32 @assert(i32 %141)
%143 = call i32 @bpf_lookup_elem(i32 %12, i32* %3, i64* %8)
%144 = icmp eq i32 %143, -1
%145 = load i64, i64* @errno
%146 = load i64, i64* @ENOENT
%147 = icmp eq i64 %145, %146
%148 = select i1 %144, i1 %147, i1 false
%149 = zext i1 %148 to i32
%150 = call i32 @assert(i32 %149)
%151 = call i32 @bpf_get_next_key(i32 %12, i32* %3, i32* %4)
%152 = icmp eq i32 %151, 0
%153 = load i32, i32* %4
%154 = icmp eq i32 %153, 0
%155 = select i1 %152, i1 %154, i1 false
%156 = zext i1 %155 to i32
%157 = call i32 @assert(i32 %156)
%158 = call i32 @bpf_get_next_key(i32 %12, i32* %4, i32* %4)
%159 = icmp eq i32 %158, 0
%160 = load i32, i32* %4
%161 = icmp eq i32 %160, 1
%162 = select i1 %159, i1 %161, i1 false
%163 = zext i1 %162 to i32
%164 = call i32 @assert(i32 %163)
%165 = call i32 @bpf_get_next_key(i32 %12, i32* %4, i32* %4)
%166 = icmp eq i32 %165, -1
%167 = load i64, i64* @errno
%168 = load i64, i64* @ENOENT
%169 = icmp eq i64 %167, %168
%170 = select i1 %166, i1 %169, i1 false
%171 = zext i1 %170 to i32
%172 = call i32 @assert(i32 %171)
store i32 1, i32* %3
%173 = call i32 @bpf_delete_elem(i32 %12, i32* %3)
%174 = icmp eq i32 %173, -1
%175 = load i64, i64* @errno
%176 = load i64, i64* @EINVAL
%177 = icmp eq i64 %175, %176
%178 = select i1 %174, i1 %177, i1 false
%179 = zext i1 %178 to i32
%180 = call i32 @assert(i32 %179)
%181 = call i32 @close(i32 %12)
ret void
}