#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 os_alloc_assoc_set(unsigned int const, unsigned int);
int resctrl_alloc_get_grps_num(struct pqos_cap const *, unsigned int *);
int resctrl_alloc_get_unused_group(unsigned int, unsigned int *);
int os_alloc_assign(const unsigned technology, const unsigned *core_array,
                    const unsigned core_num, unsigned *class_id) {
  unsigned i, num_rctl_grps = 0;
  int ret;
  const struct pqos_cap *cap;
  ;
  ;
  ;
  (void)(technology);
  _pqos_cap_get(&cap, NULL);
  ret = resctrl_alloc_get_grps_num(cap, &num_rctl_grps);
  if (ret != 0)
    return ret;
  if (num_rctl_grps == 0)
    return 1;
  ret = resctrl_alloc_get_unused_group(num_rctl_grps, class_id);
  if (ret != 0)
    return ret;
  for (i = 0; i < core_num; i++) {
    ret = os_alloc_assoc_set(core_array[i], *class_id);
    if (ret != 0)
      return ret;
  }
  return ret;
}


x86 assembly (clang, -O0):
<os_alloc_assign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <_pqos_cap_get@plt>
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <resctrl_alloc_get_grps_num@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     118f <os_alloc_assign+0x4f>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1222 <os_alloc_assign+0xe2>
cmpl   $0x0,-0x28(%rbp)
jne    11a5 <os_alloc_assign+0x65>
movl   $0x1,-0x4(%rbp)
jmp    1222 <os_alloc_assign+0xe2>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <resctrl_alloc_get_unused_group@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11c9 <os_alloc_assign+0x89>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1222 <os_alloc_assign+0xe2>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    121c <os_alloc_assign+0xdc>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1040 <os_alloc_assoc_set@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1209 <os_alloc_assign+0xc9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1222 <os_alloc_assign+0xe2>
jmp    120e <os_alloc_assign+0xce>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d0 <os_alloc_assign+0x90>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_alloc_assign>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r14
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <_pqos_cap_get@plt>
mov    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1050 <resctrl_alloc_get_grps_num@plt>
test   %eax,%eax
je     1184 <os_alloc_assign+0x44>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%edi
test   %edi,%edi
je     11cc <os_alloc_assign+0x8c>
mov    %rbx,%rsi
call   1030 <resctrl_alloc_get_unused_group@plt>
test   %eax,%eax
jne    1179 <os_alloc_assign+0x39>
test   %ebp,%ebp
je     11d3 <os_alloc_assign+0x93>
mov    %ebp,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbp,4),%edi
mov    (%rbx),%esi
call   1040 <os_alloc_assoc_set@plt>
test   %eax,%eax
jne    1179 <os_alloc_assign+0x39>
add    $0x1,%rbp
xor    %eax,%eax
cmp    %rbp,%r15
jne    11b0 <os_alloc_assign+0x70>
jmp    1179 <os_alloc_assign+0x39>
mov    $0x1,%eax
jmp    1179 <os_alloc_assign+0x39>
xor    %eax,%eax
jmp    1179 <os_alloc_assign+0x39>

LLVM IR (-O0):
%struct.pqos_cap = type { i32 }
define i32 @os_alloc_assign(i32 %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.pqos_cap*
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %11
%14 = load i32, i32* %6
%15 = call i32 @_pqos_cap_get(%struct.pqos_cap** %13, i32* null)
%16 = load %struct.pqos_cap*, %struct.pqos_cap** %13
%17 = call i32 @resctrl_alloc_get_grps_num(%struct.pqos_cap* %16, i32* %11)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = load i32, i32* %12
store i32 %21, i32* %5
br label %58
22: ; preds = %4
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %5
br label %58
26: ; preds = %22
%27 = load i32, i32* %11
%28 = load i32*, i32** %9
%29 = call i32 @resctrl_alloc_get_unused_group(i32 %27, i32* %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = load i32, i32* %12
store i32 %33, i32* %5
br label %58
34: ; preds = %26
store i32 0, i32* %10
br label %35
35: ; preds = %53, %34
%36 = load i32, i32* %10
%37 = load i32, i32* %8
%38 = icmp ult i32 %36, %37
br i1 %38, label %39, label %56
39: ; preds = %35
%40 = load i32*, i32** %7
%41 = load i32, i32* %10
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = load i32*, i32** %9
%46 = load i32, i32* %45
%47 = call i32 @os_alloc_assoc_set(i32 %44, i32 %46)
store i32 %47, i32* %12
%48 = load i32, i32* %12
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %39
%51 = load i32, i32* %12
store i32 %51, i32* %5
br label %58
52: ; preds = %39
br label %53
53: ; preds = %52
%54 = load i32, i32* %10
%55 = add i32 %54, 1
store i32 %55, i32* %10
br label %35
56: ; preds = %35
%57 = load i32, i32* %12
store i32 %57, i32* %5
br label %58
58: ; preds = %56, %50, %32, %25, %20
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
%struct.pqos_cap = type { i32 }
define i32 @os_alloc_assign(i32 %0, i32* nocapture %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.pqos_cap*
%7 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%8 = bitcast %struct.pqos_cap** %6 to i8*
%9 = call i32 @_pqos_cap_get(%struct.pqos_cap** %6, i32* null)
%10 = load %struct.pqos_cap*, %struct.pqos_cap** %6
%11 = call i32 @resctrl_alloc_get_grps_num(%struct.pqos_cap* %10, i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %4
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %13
%17 = call i32 @resctrl_alloc_get_unused_group(i32 %14, i32* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = icmp eq i32 %2, 0
br i1 %20, label %33, label %21
21: ; preds = %19
%22 = zext i32 %2 to i64
br label %25
23: ; preds = %25
%24 = icmp eq i64 %32, %22
br i1 %24, label %33, label %25
25: ; preds = %21, %23
%26 = phi i64 [ 0, %21 ], [ %32, %23 ]
%27 = getelementptr inbounds i32, i32* %1, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %3
%30 = call i32 @os_alloc_assoc_set(i32 %28, i32 %29)
%31 = icmp eq i32 %30, 0
%32 = add nuw nsw i64 %26, 1
br i1 %31, label %23, label %33
33: ; preds = %25, %23, %19, %16, %13, %4
%34 = phi i32 [ %11, %4 ], [ 1, %13 ], [ %17, %16 ], [ 0, %19 ], [ %30, %25 ], [ 0, %23 ]
ret i32 %34
}