#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 /*<<< orphan*/ next_id;
  int /*<<< orphan*/ start_id;
};
typedef int /*<<< orphan*/ attr;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ BPF_MAP_GET_NEXT_ID;
int /*<<< orphan*/ bzero(union bpf_attr *, int);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_map_get_next_id(__u32 start_id, __u32 *next_id) {
  union bpf_attr attr;
  int err;
  bzero(&attr, sizeof(attr));
  attr.start_id = start_id;
  err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr));
  if (!err)
    *next_id = attr.next_id;
  return err;
}


x86 assembly (clang, -O0):
<bpf_map_get_next_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1040 <bzero@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1170 <bpf_map_get_next_id+0x50>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_map_get_next_id>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,0x8(%rsp)
mov    0x2ed5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
test   %eax,%eax
jne    113e <bpf_map_get_next_id+0x2e>
mov    0x8(%rsp),%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%union.bpf_attr = type { i32 }
@BPF_MAP_GET_NEXT_ID = global i32 0
define i32 @bpf_map_get_next_id(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %union.bpf_attr
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = call i32 @bzero(%union.bpf_attr* %5, i32 4)
%8 = load i32, i32* %3
%9 = bitcast %union.bpf_attr* %5 to i32*
store i32 %8, i32* %9
%10 = load i32, i32* @BPF_MAP_GET_NEXT_ID
%11 = call i32 @sys_bpf(i32 %10, %union.bpf_attr* %5, i32 4)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = bitcast %union.bpf_attr* %5 to i32*
%16 = load i32, i32* %15
%17 = load i32*, i32** %4
store i32 %16, i32* %17
br label %18
18: ; preds = %14, %2
%19 = load i32, i32* %6
ret i32 %19
}

LLVM IR (-O2):
%union.bpf_attr = type { i32 }
@BPF_MAP_GET_NEXT_ID = global i32 0
define i32 @bpf_map_get_next_id(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca %union.bpf_attr
%4 = bitcast %union.bpf_attr* %3 to i8*
%5 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %3, i64 0, i32 0
store i32 %0, i32* %5
%6 = load i32, i32* @BPF_MAP_GET_NEXT_ID
%7 = call i32 @sys_bpf(i32 %6, %union.bpf_attr* %3, i32 4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i32, i32* %5
store i32 %10, i32* %1
br label %11
11: ; preds = %9, %2
ret i32 %7
}