#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*/ memset(union bpf_attr *, int /*<<< orphan*/, int);
int sys_bpf(int, union bpf_attr *, int);
int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd) {
  union bpf_attr attr;
  int err;
  memset(&attr, 0, sizeof(attr));
  attr.start_id = start_id;
  err = sys_bpf(cmd, &attr, sizeof(attr));
  if (!err)
    *next_id = attr.next_id;
  return err;
}


x86 assembly (clang, -O0):
<bpf_obj_get_next_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    116f <bpf_obj_get_next_id+0x4f>
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_obj_get_next_id>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebx,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
test   %eax,%eax
jne    115c <bpf_obj_get_next_id+0x3c>
mov    (%rsp),%ecx
mov    %ecx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%union.bpf_attr = type { i32 }
define i32 @bpf_obj_get_next_id(i32 %0, i32* nocapture writeonly %1, i32 %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 4)
%7 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %4, i64 0, i32 0
store i32 %0, i32* %7
%8 = call i32 @sys_bpf(i32 %2, %union.bpf_attr* %4, i32 4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = load i32, i32* %7
store i32 %11, i32* %1
br label %12
12: ; preds = %10, %3
ret i32 %8
}