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

/* Variables and functions */
int /*<<< orphan*/ BPF_MAP_UPDATE_ELEM;
int bpf(int /*<<< orphan*/, union bpf_attr *, int);
void *bpf_ptr_to_u64(void const *);
int bpf_map_update(int fd, const void *key, const void *value, uint64_t flags) {
  union bpf_attr attr = {};
  attr.map_fd = fd;
  attr.key = bpf_ptr_to_u64(key);
  attr.value = bpf_ptr_to_u64(value);
  attr.flags = flags;
  return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
}


x86 assembly (clang, -O0):
<bpf_map_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <bpf_ptr_to_u64@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <bpf_ptr_to_u64@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1030 <bpf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_map_update>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rsi,%rdi
call   1040 <bpf_ptr_to_u64@plt>
mov    %rbx,%rdi
call   1040 <bpf_ptr_to_u64@plt>
mov    %rax,(%rsp)
mov    %ebp,(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1030 <bpf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%union.bpf_attr = type { i8* }
@__const.bpf_map_update.attr = { i32, [4 x i8] } { i32 0, [4 x i8] undef }
@BPF_MAP_UPDATE_ELEM = global i32 0
define i32 @bpf_map_update(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %union.bpf_attr
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = bitcast %union.bpf_attr* %9 to i8*
%11 = load i32, i32* %5
%12 = bitcast %union.bpf_attr* %9 to i32*
store i32 %11, i32* %12
%13 = load i8*, i8** %6
%14 = call i8* @bpf_ptr_to_u64(i8* %13)
%15 = bitcast %union.bpf_attr* %9 to i8**
store i8* %14, i8** %15
%16 = load i8*, i8** %7
%17 = call i8* @bpf_ptr_to_u64(i8* %16)
%18 = bitcast %union.bpf_attr* %9 to i8**
store i8* %17, i8** %18
%19 = load i32, i32* %8
%20 = bitcast %union.bpf_attr* %9 to i32*
store i32 %19, i32* %20
%21 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%22 = call i32 @bpf(i32 %21, %union.bpf_attr* %9, i32 8)
ret i32 %22
}

LLVM IR (-O2):
%union.bpf_attr = type { i8* }
@BPF_MAP_UPDATE_ELEM = global i32 0
define i32 @bpf_map_update(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %union.bpf_attr
%6 = bitcast %union.bpf_attr* %5 to i8*
%7 = bitcast %union.bpf_attr* %5 to i32*
%8 = tail call i8* @bpf_ptr_to_u64(i8* %1)
%9 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %5, i64 0, i32 0
%10 = tail call i8* @bpf_ptr_to_u64(i8* %2)
store i8* %10, i8** %9
store i32 %3, i32* %7
%11 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%12 = call i32 @bpf(i32 %11, %union.bpf_attr* %5, i32 8)
ret i32 %12
}