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

/* Variables and functions */
int /*<<< orphan*/ BPF_MAP_LOOKUP_ELEM;
int /*<<< orphan*/ SYS_bpf;
int /*<<< orphan*/ assert(int);
scalar_t__ syscall(int /*<<< orphan*/, int /*<<< orphan*/, union bpf_attr *,
                   int);
uint64_t read_map(int mapfd) {
  uint64_t out = 0;
  uint64_t key = 0;
  union bpf_attr attr = {
      .map_fd = mapfd,
      .key = (uint64_t)&key,
      .value = (uint64_t)&out,
  };
  assert(syscall(SYS_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)) >= 0);
  return out;
}


x86 assembly (clang, -O0):
<read_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x8(%rbp),%rax
mov    %eax,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
mov    $0x4,%ecx
call   1040 <syscall@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_map>:
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rax
mov    %eax,0x10(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    $0x4,%ecx
call   1040 <syscall@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1030 <assert@plt>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%union.bpf_attr = type { i32 }
@SYS_bpf = global i32 0
@BPF_MAP_LOOKUP_ELEM = global i32 0
define i32 @read_map(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %union.bpf_attr
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = bitcast %union.bpf_attr* %5 to i32*
%7 = ptrtoint i32* %3 to i32
store i32 %7, i32* %6
%8 = load i32, i32* @SYS_bpf
%9 = load i32, i32* @BPF_MAP_LOOKUP_ELEM
%10 = call i64 @syscall(i32 %8, i32 %9, %union.bpf_attr* %5, i32 4)
%11 = icmp sge i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %3
ret i32 %14
}

LLVM IR (-O2):
%union.bpf_attr = type { i32 }
@SYS_bpf = global i32 0
@BPF_MAP_LOOKUP_ELEM = global i32 0
define i32 @read_map(i32 %0) {
%2 = alloca i32
%3 = alloca %union.bpf_attr
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast %union.bpf_attr* %3 to i8*
%6 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %3, i64 0, i32 0
%7 = ptrtoint i32* %2 to i64
%8 = trunc i64 %7 to i32
store i32 %8, i32* %6
%9 = load i32, i32* @SYS_bpf
%10 = load i32, i32* @BPF_MAP_LOOKUP_ELEM
%11 = call i64 @syscall(i32 %9, i32 %10, %union.bpf_attr* %3, i32 4)
%12 = lshr i64 %11, 63
%13 = trunc i64 %12 to i32
%14 = xor i32 %13, 1
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %2
ret i32 %16
}