#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*/ bzero(union bpf_attr *, int);
void *ptr_to_u64(void *);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_map_update_elem(int fd, void *key, void *value, __u64 flags) {
  union bpf_attr attr;
  bzero(&attr, 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
mov    $0x8,%esi
call   1050 <bzero@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    0x2e5f(%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   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rsi,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rbx,%rdi
call   1040 <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 <sys_bpf@plt>
add    $0x8,%rsp
pop    %rbx
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 @bzero(%union.bpf_attr* %9, 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 = bitcast %union.bpf_attr* %5 to i32*
%8 = tail call i8* @ptr_to_u64(i8* %1)
%9 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %5, i64 0, i32 0
%10 = tail call i8* @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 @sys_bpf(i32 %11, %union.bpf_attr* %5, i32 8)
ret i32 %12
}