#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 */
struct pqos_cap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _pqos_cap_get(struct pqos_cap const **,
                                 int /*<<< orphan*/ *);
int resctrl_alloc_get_grps_num(struct pqos_cap const *, unsigned int *);
unsigned int *resctrl_alloc_task_read(unsigned int const, unsigned int *);
int /*<<< orphan*/ resctrl_lock_release();
int resctrl_lock_shared();
unsigned *os_pid_get_pid_assoc(const unsigned class_id, unsigned *count) {
  unsigned grps;
  int ret;
  unsigned *tasks;
  const struct pqos_cap *cap;
  ;
  _pqos_cap_get(&cap, NULL);
  ret = resctrl_alloc_get_grps_num(cap, &grps);
  if (ret != 0)
    return NULL;
  if (class_id >= grps)
    return NULL;
  ret = resctrl_lock_shared();
  if (ret != 0)
    return NULL;
  tasks = resctrl_alloc_task_read(class_id, count);
  resctrl_lock_release();
  return tasks;
}


x86 assembly (clang, -O0):
<os_pid_get_pid_assoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <_pqos_cap_get@plt>
mov    -0x30(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <resctrl_alloc_get_grps_num@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1193 <os_pid_get_pid_assoc+0x43>
movq   $0x0,-0x8(%rbp)
jmp    11ec <os_pid_get_pid_assoc+0x9c>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jb     11ac <os_pid_get_pid_assoc+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    11ec <os_pid_get_pid_assoc+0x9c>
mov    $0x0,%al
call   1030 <resctrl_lock_shared@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11cd <os_pid_get_pid_assoc+0x7d>
movq   $0x0,-0x8(%rbp)
jmp    11ec <os_pid_get_pid_assoc+0x9c>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <resctrl_alloc_task_read@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <resctrl_lock_release@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_pid_get_pid_assoc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <_pqos_cap_get@plt>
mov    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1050 <resctrl_alloc_get_grps_num@plt>
test   %eax,%eax
jne    11a5 <os_pid_get_pid_assoc+0x55>
cmp    %ebp,0x4(%rsp)
jbe    11a5 <os_pid_get_pid_assoc+0x55>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <resctrl_lock_shared@plt>
test   %eax,%eax
jne    11a5 <os_pid_get_pid_assoc+0x55>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <resctrl_alloc_task_read@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <resctrl_lock_release@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.pqos_cap = type { i32 }
define i32* @os_pid_get_pid_assoc(i32 %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca %struct.pqos_cap*
store i32 %0, i32* %4
store i32* %1, i32** %5
%10 = call i32 @_pqos_cap_get(%struct.pqos_cap** %9, i32* null)
%11 = load %struct.pqos_cap*, %struct.pqos_cap** %9
%12 = call i32 @resctrl_alloc_get_grps_num(%struct.pqos_cap* %11, i32* %6)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32* null, i32** %3
br label %32
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i32, i32* %6
%19 = icmp uge i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32* null, i32** %3
br label %32
21: ; preds = %16
%22 = call i32 (...) @resctrl_lock_shared()
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32* null, i32** %3
br label %32
26: ; preds = %21
%27 = load i32, i32* %4
%28 = load i32*, i32** %5
%29 = call i32* @resctrl_alloc_task_read(i32 %27, i32* %28)
store i32* %29, i32** %8
%30 = call i32 (...) @resctrl_lock_release()
%31 = load i32*, i32** %8
store i32* %31, i32** %3
br label %32
32: ; preds = %26, %25, %20, %15
%33 = load i32*, i32** %3
ret i32* %33
}

LLVM IR (-O2):
%struct.pqos_cap = type { i32 }
define i32* @os_pid_get_pid_assoc(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.pqos_cap*
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.pqos_cap** %4 to i8*
%7 = call i32 @_pqos_cap_get(%struct.pqos_cap** %4, i32* null)
%8 = load %struct.pqos_cap*, %struct.pqos_cap** %4
%9 = call i32 @resctrl_alloc_get_grps_num(%struct.pqos_cap* %8, i32* %3)
%10 = icmp eq i32 %9, 0
%11 = load i32, i32* %3
%12 = icmp ugt i32 %11, %0
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = call i32 (...) @resctrl_lock_shared()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32* @resctrl_alloc_task_read(i32 %0, i32* %1)
%19 = call i32 (...) @resctrl_lock_release()
br label %20
20: ; preds = %14, %2, %17
%21 = phi i32* [ %18, %17 ], [ null, %2 ], [ null, %14 ]
ret i32* %21
}