#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*/ attr;
typedef int /*<<< orphan*/ __u64;

/* Variables and functions */
int /*<<< orphan*/ BPF_MAP_UPDATE_ELEM;
int /*<<< orphan*/ memset(union bpf_attr *, int /*<<< orphan*/, int);
void *ptr_to_u64(void const *);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_map_update_elem(int fd, const void *key, const void *value,
                        __u64 flags) {
  union bpf_attr attr;
  memset(&attr, 0, sizeof(attr));
  attr.map_fd = fd;
  attr.key = ptr_to_u64(key);
  attr.value = ptr_to_u64(value);
  attr.flags = flags;
  return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
}


x86 assembly (clang, -O0):
<bpf_map_update_elem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1030 <sys_bpf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_map_update_elem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    %ebx,0x8(%rsp)
mov    %rbp,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x8(%rsp)
mov    %r14d,0x8(%rsp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    $0x8,%edx
call   1030 <sys_bpf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.bpf_attr = type { i8* }
@BPF_MAP_UPDATE_ELEM = global i32 0
define i32 @bpf_map_update_elem(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 = call i32 @memset(%union.bpf_attr* %9, i32 0, i32 8)
%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* @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* @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 @sys_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_elem(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %union.bpf_attr
%6 = bitcast %union.bpf_attr* %5 to i8*
%7 = call i32 @memset(%union.bpf_attr* %5, i32 0, i32 8)
%8 = bitcast %union.bpf_attr* %5 to i32*
store i32 %0, i32* %8
%9 = call i8* @ptr_to_u64(i8* %1)
%10 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %5, i64 0, i32 0
store i8* %9, i8** %10
%11 = call i8* @ptr_to_u64(i8* %2)
store i8* %11, i8** %10
store i32 %3, i32* %8
%12 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%13 = call i32 @sys_bpf(i32 %12, %union.bpf_attr* %5, i32 8)
ret i32 %13
}