#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 */
union bpf_attr {
  void *flags;
  void *value;
  void *key;
  int /*<<< orphan*/ map_fd;
};
typedef int /*<<< orphan*/ attr;
typedef void *__u64;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ SYS_bpf;
int errno;
scalar_t__ syscall(int /*<<< orphan*/, int, union bpf_attr *, int);
int bpf_map_call(int cmd, __u32 map_fd, void *pointer_to_key,
                 void *pointer_to_value, __u64 flags) {
  union bpf_attr attr = {};
  attr.map_fd = map_fd;
  attr.key = (__u64)(unsigned long)pointer_to_key;
  attr.value = (__u64)(unsigned long)pointer_to_value;
  attr.flags = flags;
  return syscall(SYS_bpf, cmd, &attr, sizeof(attr)) == 0 ? 0 : errno;
}


x86 assembly (clang, -O0):
<bpf_map_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
lea    -0x28(%rbp),%rdx
mov    $0x8,%ecx
call   1040 <syscall@plt>
cmp    $0x0,%rax
jne    1196 <bpf_map_call+0x76>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a2 <bpf_map_call+0x82>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_map_call>:
push   %rax
mov    %edi,%esi
mov    %r8,(%rsp)
mov    0x2eca(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
mov    $0x8,%ecx
call   1030 <syscall@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1140 <bpf_map_call+0x30>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
%union.bpf_attr = type { i8* }
@SYS_bpf = global i32 0
@errno = global i32 0
define i32 @bpf_map_call(i32 %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %union.bpf_attr
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = bitcast %union.bpf_attr* %11 to i8*
%13 = load i32, i32* %7
%14 = bitcast %union.bpf_attr* %11 to i32*
store i32 %13, i32* %14
%15 = load i8*, i8** %8
%16 = ptrtoint i8* %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = bitcast %union.bpf_attr* %11 to i8**
store i8* %17, i8** %18
%19 = load i8*, i8** %9
%20 = ptrtoint i8* %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = bitcast %union.bpf_attr* %11 to i8**
store i8* %21, i8** %22
%23 = load i8*, i8** %10
%24 = bitcast %union.bpf_attr* %11 to i8**
store i8* %23, i8** %24
%25 = load i32, i32* @SYS_bpf
%26 = load i32, i32* %6
%27 = call i64 @syscall(i32 %25, i32 %26, %union.bpf_attr* %11, i32 8)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %5
br label %32
30: ; preds = %5
%31 = load i32, i32* @errno
br label %32
32: ; preds = %30, %29
%33 = phi i32 [ 0, %29 ], [ %31, %30 ]
ret i32 %33
}

LLVM IR (-O2):
%union.bpf_attr = type { i8* }
@SYS_bpf = global i32 0
@errno = global i32 0
define i32 @bpf_map_call(i32 %0, i32 %1, i8* nocapture readnone %2, i8* nocapture readnone %3, i8* %4) {
%6 = alloca %union.bpf_attr
%7 = bitcast %union.bpf_attr* %6 to i8*
%8 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %6, i64 0, i32 0
store i8* %4, i8** %8
%9 = load i32, i32* @SYS_bpf
%10 = call i64 @syscall(i32 %9, i32 %0, %union.bpf_attr* %6, i32 8)
%11 = icmp eq i64 %10, 0
%12 = load i32, i32* @errno
%13 = select i1 %11, i32 0, i32 %12
ret i32 %13
}