#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 */

/* Variables and functions */
int /*<<< orphan*/ BPF_NOEXIST;
int /*<<< orphan*/ assert(int);
scalar_t__ bpf_delete_elem(int, int *);
scalar_t__ bpf_update_elem(int, int *, int *, int /*<<< orphan*/);
void do_work(int fn, void *data) {
  int map_fd = ((int *)data)[0];
  int do_update = ((int *)data)[1];
  int i;
  int key, value;
  for (i = fn; i < (32 * 1024); i += 1024) {
    key = value = i;
    if (do_update)
      assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == 0);
    else
      assert(bpf_delete_elem(map_fd, &key) == 0);
  }
}


x86 assembly (clang, -O0):
<do_work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x8000,-0x1c(%rbp)
jge    11d9 <do_work+0xa9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a7 <do_work+0x77>
mov    -0x14(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <bpf_update_elem@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    11c4 <do_work+0x94>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <bpf_delete_elem@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    11c9 <do_work+0x99>
mov    -0x1c(%rbp),%eax
add    $0x400,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <do_work+0x28>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_work>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x7fff,%edi
jg     11a8 <do_work+0x78>
mov    %edi,%ebx
mov    (%rsi),%r12d
mov    0x4(%rsi),%ebp
lea    0x4(%rsp),%r14
mov    0x2e89(%rip),%r13
mov    %rsp,%r15
jmp    1189 <do_work+0x59>
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r14,%rsi
call   1050 <bpf_delete_elem@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
lea    0x400(%rbx),%eax
cmp    $0x7c00,%ebx
mov    %eax,%ebx
jge    11a8 <do_work+0x78>
mov    %ebx,(%rsp)
mov    %ebx,0x4(%rsp)
test   %ebp,%ebp
je     1160 <do_work+0x30>
mov    0x0(%r13),%ecx
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <bpf_update_elem@plt>
jmp    116b <do_work+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BPF_NOEXIST = global i32 0
define void @do_work(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i32*
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i32*
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
store i32 %17, i32* %6
%18 = load i32, i32* %3
store i32 %18, i32* %7
br label %19
19: ; preds = %40, %2
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 32768
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load i32, i32* %7
store i32 %23, i32* %9
store i32 %23, i32* %8
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i32, i32* %5
%28 = load i32, i32* @BPF_NOEXIST
%29 = call i64 @bpf_update_elem(i32 %27, i32* %8, i32* %9, i32 %28)
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
br label %39
33: ; preds = %22
%34 = load i32, i32* %5
%35 = call i64 @bpf_delete_elem(i32 %34, i32* %8)
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
br label %39
39: ; preds = %33, %26
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1024
store i32 %42, i32* %7
br label %19
43: ; preds = %19
ret void
}

LLVM IR (-O2):
@BPF_NOEXIST = global i32 0
define void @do_work(i32 %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i8* %1 to i32*
%6 = load i32, i32* %5
%7 = getelementptr inbounds i8, i8* %1, i64 4
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = icmp slt i32 %0, 32768
br i1 %12, label %13, label %29
13: ; preds = %2
%14 = icmp eq i32 %9, 0
br label %15
15: ; preds = %13, %22
%16 = phi i32 [ %0, %13 ], [ %27, %22 ]
store i32 %16, i32* %4
store i32 %16, i32* %3
br i1 %14, label %20, label %17
17: ; preds = %15
%18 = load i32, i32* @BPF_NOEXIST
%19 = call i64 @bpf_update_elem(i32 %6, i32* %3, i32* %4, i32 %18)
br label %22
20: ; preds = %15
%21 = call i64 @bpf_delete_elem(i32 %6, i32* %3)
br label %22
22: ; preds = %17, %20
%23 = phi i64 [ %19, %17 ], [ %21, %20 ]
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = add nsw i32 %16, 1024
%28 = icmp slt i32 %16, 31744
br i1 %28, label %15, label %29
29: ; preds = %22, %2
ret void
}