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

/* Variables and functions */
int /*<<< orphan*/ BPF_MAP_LOOKUP_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_lookup_elem(int fd, void *key, void *value) {
  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);
  return syscall(321, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
}


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

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

LLVM IR (-O0):
%union.bpf_attr = type { i8* }
@BPF_MAP_LOOKUP_ELEM = global i32 0
define i32 @bpf_lookup_elem(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %union.bpf_attr
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = call i32 @memset(%union.bpf_attr* %7, i32 0, i32 8)
%9 = load i32, i32* %4
%10 = bitcast %union.bpf_attr* %7 to i32*
store i32 %9, i32* %10
%11 = load i8*, i8** %5
%12 = call i8* @ptr_to_u64(i8* %11)
%13 = bitcast %union.bpf_attr* %7 to i8**
store i8* %12, i8** %13
%14 = load i8*, i8** %6
%15 = call i8* @ptr_to_u64(i8* %14)
%16 = bitcast %union.bpf_attr* %7 to i8**
store i8* %15, i8** %16
%17 = load i32, i32* @BPF_MAP_LOOKUP_ELEM
%18 = call i32 @syscall(i32 321, i32 %17, %union.bpf_attr* %7, i32 8)
ret i32 %18
}

LLVM IR (-O2):
%union.bpf_attr = type { i8* }
@BPF_MAP_LOOKUP_ELEM = global i32 0
define i32 @bpf_lookup_elem(i32 %0, i8* %1, i8* %2) {
%4 = alloca %union.bpf_attr
%5 = bitcast %union.bpf_attr* %4 to i8*
%6 = call i32 @memset(%union.bpf_attr* %4, i32 0, i32 8)
%7 = bitcast %union.bpf_attr* %4 to i32*
store i32 %0, i32* %7
%8 = call i8* @ptr_to_u64(i8* %1)
%9 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %4, i64 0, i32 0
store i8* %8, i8** %9
%10 = call i8* @ptr_to_u64(i8* %2)
store i8* %10, i8** %9
%11 = load i32, i32* @BPF_MAP_LOOKUP_ELEM
%12 = call i32 @syscall(i32 321, i32 %11, %union.bpf_attr* %4, i32 8)
ret i32 %12
}