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


x86 assembly (clang, -O0):
<bpf_prog_get_next_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e9c(%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    1172 <bpf_prog_get_next_id+0x52>
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_prog_get_next_id>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebp,0x8(%rsp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
test   %eax,%eax
jne    1166 <bpf_prog_get_next_id+0x46>
mov    0x8(%rsp),%ecx
mov    %ecx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%union.bpf_attr = type { i32 }
@BPF_PROG_GET_NEXT_ID = global i32 0
define i32 @bpf_prog_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 @memset(%union.bpf_attr* %5, i32 0, 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_PROG_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_PROG_GET_NEXT_ID = global i32 0
define i32 @bpf_prog_get_next_id(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca %union.bpf_attr
%4 = bitcast %union.bpf_attr* %3 to i8*
%5 = call i32 @memset(%union.bpf_attr* %3, i32 0, i32 4)
%6 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %3, i64 0, i32 0
store i32 %0, i32* %6
%7 = load i32, i32* @BPF_PROG_GET_NEXT_ID
%8 = call i32 @sys_bpf(i32 %7, %union.bpf_attr* %3, i32 4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* %6
store i32 %11, i32* %1
br label %12
12: ; preds = %10, %2
ret i32 %8
}