#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;
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;
  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)
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    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    $0x141,%edi
lea    -0x28(%rbp),%rdx
mov    $0x8,%ecx
call   1040 <syscall@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_update_elem>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rdi
call   1030 <ptr_to_u64@plt>
mov    %rbx,%rdi
call   1030 <ptr_to_u64@plt>
mov    %r14,(%rsp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    $0x141,%edi
mov    $0x8,%ecx
call   1040 <syscall@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = load i32, i32* %5
%11 = bitcast %union.bpf_attr* %9 to i32*
store i32 %10, i32* %11
%12 = load i8*, i8** %6
%13 = call i8* @ptr_to_u64(i8* %12)
%14 = bitcast %union.bpf_attr* %9 to i8**
store i8* %13, i8** %14
%15 = load i8*, i8** %7
%16 = call i8* @ptr_to_u64(i8* %15)
%17 = bitcast %union.bpf_attr* %9 to i8**
store i8* %16, i8** %17
%18 = load i64, i64* %8
%19 = bitcast %union.bpf_attr* %9 to i64*
store i64 %18, i64* %19
%20 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%21 = call i32 @syscall(i32 321, i32 %20, %union.bpf_attr* %9, i32 8)
ret i32 %21
}

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 = tail call i8* @ptr_to_u64(i8* %1)
%8 = tail call i8* @ptr_to_u64(i8* %2)
%9 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %5, i64 0, i32 0
store i64 %3, i64* %9
%10 = load i32, i32* @BPF_MAP_UPDATE_ELEM
%11 = call i32 @syscall(i32 321, i32 %10, %union.bpf_attr* %5, i32 8)
ret i32 %11
}