#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__ __u32;

/* Variables and functions */
int /*<<< orphan*/ BPF_ANY;
scalar_t__ bpf_map_lookup_elem(int, scalar_t__ *, scalar_t__ *);
scalar_t__ bpf_map_update_elem(int, scalar_t__ *, scalar_t__ *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void verify_map(int map_id) {
  __u32 key = 0;
  __u32 val;
  if (bpf_map_lookup_elem(map_id, &key, &val) != 0) {
    fprintf(stderr, "map_lookup failed: %s\n", strerror(errno));
    return;
  }
  if (val == 0) {
    fprintf(stderr, "failed: map #%d returns value 0\n", map_id);
    return;
  }
  val = 0;
  if (bpf_map_update_elem(map_id, &key, &val, BPF_ANY) != 0) {
    fprintf(stderr, "map_update failed: %s\n", strerror(errno));
    return;
  }
}


x86 assembly (clang, -O0):
<verify_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <bpf_map_lookup_elem@plt>
cmp    $0x0,%rax
je     11a0 <verify_map+0x60>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1223 <verify_map+0xe3>
cmpq   $0x0,-0x18(%rbp)
jne    11ca <verify_map+0x8a>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1223 <verify_map+0xe3>
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%ecx
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <bpf_map_update_elem@plt>
cmp    $0x0,%rax
je     1223 <verify_map+0xe3>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_map>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <bpf_map_lookup_elem@plt>
test   %rax,%rax
je     1192 <verify_map+0x52>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe80(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret
cmpq   $0x0,(%rsp)
je     11de <verify_map+0x9e>
movq   $0x0,(%rsp)
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <bpf_map_update_elem@plt>
test   %rax,%rax
je     118c <verify_map+0x4c>
mov    0x2e13(%rip),%rax
mov    (%rax),%ebx
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe5c(%rip),%rsi
jmp    1180 <verify_map+0x40>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    118c <verify_map+0x4c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"map_lookup failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"failed: map #%d returns value 0\0A\00"
@BPF_ANY = global i32 0
@.str.2 = [23 x i8] c"map_update failed: %s\0A\00"
define void @verify_map(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
store i32 %0, i32* %2
store i64 0, i64* %3
%5 = load i32, i32* %2
%6 = call i64 @bpf_map_lookup_elem(i32 %5, i64* %3, i64* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %30
13: ; preds = %1
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %30
20: ; preds = %13
store i64 0, i64* %4
%21 = load i32, i32* %2
%22 = load i32, i32* @BPF_ANY
%23 = call i64 @bpf_map_update_elem(i32 %21, i64* %3, i64* %4, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %8, %16, %25, %20
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"map_lookup failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"failed: map #%d returns value 0\0A\00"
@BPF_ANY = global i32 0
@.str.2 = [23 x i8] c"map_update failed: %s\0A\00"
define void @verify_map(i32 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = bitcast i64* %3 to i8*
%6 = call i64 @bpf_map_lookup_elem(i32 %0, i64* %2, i64* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %28
13: ; preds = %1
%14 = load i64, i64* %3
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %28
19: ; preds = %13
store i64 0, i64* %3
%20 = load i32, i32* @BPF_ANY
%21 = call i64 @bpf_map_update_elem(i32 %0, i64* %2, i64* %3, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %19, %23, %16, %8
ret void
}