#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 /*<<< orphan*/ log_printf(int, char *, unsigned int const);
int resctrl_alloc_assoc_get(unsigned int const, unsigned int *);
int resctrl_alloc_get_grps_num(struct pqos_cap const *, unsigned int *);
int alloc_assoc_get(const unsigned lcore, unsigned *class_id) {
  int ret;
  unsigned max_cos;
  const struct pqos_cap *cap;
  ;
  _pqos_cap_get(&cap, NULL);
  ret = resctrl_alloc_get_grps_num(cap, &max_cos);
  if (ret != 0)
    return ret;
  if (max_cos == 0) {
    *class_id = 0;
    return 0;
  }
  ret = resctrl_alloc_assoc_get(lcore, class_id);
  if (ret != 0)
    log_printf((1 << 2),
               "ERROR: "
               "Failed to retrieve core %u association\n",
               lcore);
  return ret;
}


x86 assembly (clang, -O0):
<alloc_assoc_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <_pqos_cap_get@plt>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <resctrl_alloc_get_grps_num@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1181 <alloc_assoc_get+0x41>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <alloc_assoc_get+0x94>
cmpl   $0x0,-0x18(%rbp)
jne    11a1 <alloc_assoc_get+0x61>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d4 <alloc_assoc_get+0x94>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <resctrl_alloc_assoc_get@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ce <alloc_assoc_get+0x8e>
mov    -0x8(%rbp),%edx
mov    $0x4,%edi
lea    0xe37(%rip),%rsi
call   1030 <log_printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_assoc_get>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
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>
mov    %eax,%ebp
test   %eax,%eax
jne    11a5 <alloc_assoc_get+0x65>
cmpl   $0x0,0x4(%rsp)
je     119d <alloc_assoc_get+0x5d>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <resctrl_alloc_assoc_get@plt>
test   %eax,%eax
je     11a3 <alloc_assoc_get+0x63>
mov    %eax,%ebp
lea    0xe72(%rip),%rsi
mov    $0x4,%edi
mov    %r14d,%edx
call   1030 <log_printf@plt>
jmp    11a5 <alloc_assoc_get+0x65>
movl   $0x0,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.pqos_cap = type { i32 }
@.str = [47 x i8] c"ERROR: Failed to retrieve core %u association\0A\00"
define i32 @alloc_assoc_get(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.pqos_cap*
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = call i32 @_pqos_cap_get(%struct.pqos_cap** %8, i32* null)
%10 = load %struct.pqos_cap*, %struct.pqos_cap** %8
%11 = call i32 @resctrl_alloc_get_grps_num(%struct.pqos_cap* %10, i32* %7)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %32
16: ; preds = %2
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32*, i32** %5
store i32 0, i32* %20
store i32 0, i32* %3
br label %32
21: ; preds = %16
%22 = load i32, i32* %4
%23 = load i32*, i32** %5
%24 = call i32 @resctrl_alloc_assoc_get(i32 %22, i32* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* %4
%29 = call i32 @log_printf(i32 4, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %21
%31 = load i32, i32* %6
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %19, %14
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.pqos_cap = type { i32 }
@.str = [47 x i8] c"ERROR: Failed to retrieve core %u association\0A\00"
define i32 @alloc_assoc_get(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
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 0, i32* %1
br label %20
15: ; preds = %11
%16 = call i32 @resctrl_alloc_assoc_get(i32 %0, i32* %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @log_printf(i32 4, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %20
20: ; preds = %15, %18, %2, %14
%21 = phi i32 [ 0, %14 ], [ %9, %2 ], [ %16, %18 ], [ 0, %15 ]
ret i32 %21
}