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

/* Variables and functions */
int /*<<< orphan*/ BPF_MAP_UPDATE_ELEM;
int /*<<< orphan*/ memset(union bpf_attr *, int /*<<< orphan*/, int);
void *ptr_to_u64(void *);
int syscall(int, int /*<<< orphan*/, union bpf_attr *, int);
int bpf_update_elem(int fd, void *key, void *value, unsigned long long 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 syscall(321, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
}


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

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

LLVM IR (-O0):
%union.bpf_attr = type { i64 }
@BPF_MAP_UPDATE_ELEM = global i32 0
define i32 @bpf_update_elem(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %union.bpf_attr
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %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 i64, i64* %8
%20 = bitcast %union.bpf_attr* %9 to i64*
store i64 %19, i64* %20
%21 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%22 = call i32 @syscall(i32 321, i32 %21, %union.bpf_attr* %9, i32 8)
ret i32 %22
}

LLVM IR (-O2):
%union.bpf_attr = type { i64 }
@BPF_MAP_UPDATE_ELEM = global i32 0
define i32 @bpf_update_elem(i32 %0, i8* %1, i8* %2, i64 %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 = bitcast %union.bpf_attr* %5 to i8**
store i8* %9, i8** %10
%11 = call i8* @ptr_to_u64(i8* %2)
%12 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %5, i64 0, i32 0
store i64 %3, i64* %12
%13 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%14 = call i32 @syscall(i32 321, i32 %13, %union.bpf_attr* %5, i32 8)
ret i32 %14
}