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

/* Variables and functions */
int pqos_cap_get(struct pqos_cap const **, struct pqos_cpuinfo const **);
int pqos_cpu_get_cores(struct pqos_cpuinfo const *, unsigned int, int,
                       unsigned int *, unsigned int *);
int pqos_cpu_get_sockets(struct pqos_cpuinfo const *, int, unsigned int *,
                         unsigned int *);
int pqos_l3ca_assoc_get(unsigned int, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
void print_allocation_config(void) {
  int ret = 0;
  unsigned i;
  unsigned sock_count, sockets[2];
  const struct pqos_cpuinfo *p_cpu = NULL;
  const struct pqos_cap *p_cap = NULL;
  ret = pqos_cap_get(&p_cap, &p_cpu);
  if (ret != 0) {
    printf("Error retrieving PQoS capabilities!\n");
    return;
  }
  ret = pqos_cpu_get_sockets(p_cpu, 2, &sock_count, sockets);
  if (ret != 0) {
    printf("Error retrieving CPU socket information!\n");
    return;
  }
  for (i = 0; i < sock_count; i++) {
    unsigned lcores[64];
    unsigned lcount = 0, n = 0;
    ret = pqos_cpu_get_cores(p_cpu, sockets[i], 64, &lcount, &lcores[0]);
    if (ret != 0) {
      printf("Error retrieving core information!\n");
      return;
    }
    printf("Core information for socket %u:\n", sockets[i]);
    for (n = 0; n < lcount; n++) {
      unsigned class_id = 0;
      ret = pqos_l3ca_assoc_get(lcores[n], &class_id);
      if (ret == 0)
        printf("    Core %u => COS%u\n", lcores[n], class_id);
      else
        printf("    Core %u => ERROR\n", lcores[n]);
    }
  }
}


x86 assembly (clang, -O0):
<print_allocation_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <pqos_cap_get@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     119f <print_allocation_config+0x4f>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    130d <print_allocation_config+0x1bd>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rcx
mov    $0x2,%esi
lea    -0xc(%rbp),%rdx
call   1050 <pqos_cpu_get_sockets@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11d5 <print_allocation_config+0x85>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    130d <print_allocation_config+0x1bd>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    130d <print_allocation_config+0x1bd>
movl   $0x0,-0x134(%rbp)
movl   $0x0,-0x138(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp,%rax,4),%esi
lea    -0x130(%rbp),%r8
mov    $0x40,%edx
lea    -0x134(%rbp),%rcx
call   1070 <pqos_cpu_get_cores@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     123f <print_allocation_config+0xef>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    130d <print_allocation_config+0x1bd>
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp,%rax,4),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%eax
cmp    -0x134(%rbp),%eax
jae    12fa <print_allocation_config+0x1aa>
movl   $0x0,-0x13c(%rbp)
mov    -0x138(%rbp),%eax
mov    -0x130(%rbp,%rax,4),%edi
lea    -0x13c(%rbp),%rsi
call   1040 <pqos_l3ca_assoc_get@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    12c6 <print_allocation_config+0x176>
mov    -0x138(%rbp),%eax
mov    -0x130(%rbp,%rax,4),%esi
mov    -0x13c(%rbp),%edx
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e1 <print_allocation_config+0x191>
mov    -0x138(%rbp),%eax
mov    -0x130(%rbp,%rax,4),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e6 <print_allocation_config+0x196>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    125e <print_allocation_config+0x10e>
jmp    12ff <print_allocation_config+0x1af>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11dc <print_allocation_config+0x8c>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_allocation_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
movq   $0x0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x28(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1070 <pqos_cap_get@plt>
test   %eax,%eax
je     119f <print_allocation_config+0x3f>
lea    0xefc(%rip),%rdi
jmp    11c3 <print_allocation_config+0x63>
mov    0x18(%rsp),%rdi
lea    0x14(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    $0x2,%esi
call   1060 <pqos_cpu_get_sockets@plt>
test   %eax,%eax
je     11da <print_allocation_config+0x7a>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpl   $0x0,0x14(%rsp)
je     11c8 <print_allocation_config+0x68>
lea    0x30(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xe2f(%rip),%r13
lea    0xe3e(%rip),%rbp
xor    %r15d,%r15d
jmp    120d <print_allocation_config+0xad>
xchg   %ax,%ax
add    $0x1,%r15
mov    0x14(%rsp),%eax
cmp    %rax,%r15
jae    11c8 <print_allocation_config+0x68>
movl   $0x0,0xc(%rsp)
mov    0x18(%rsp),%rdi
mov    0x20(%rsp,%r15,4),%esi
mov    $0x40,%edx
lea    0xc(%rsp),%rcx
mov    %r12,%r8
call   1080 <pqos_cpu_get_cores@plt>
test   %eax,%eax
jne    12a5 <print_allocation_config+0x145>
mov    0x20(%rsp,%r15,4),%esi
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
je     1200 <print_allocation_config+0xa0>
xor    %r14d,%r14d
jmp    1277 <print_allocation_config+0x117>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
mov    0xc(%rsp),%eax
cmp    %rax,%r14
jae    1200 <print_allocation_config+0xa0>
movl   $0x0,0x10(%rsp)
mov    0x30(%rsp,%r14,4),%edi
mov    %rbx,%rsi
call   1050 <pqos_l3ca_assoc_get@plt>
mov    0x30(%rsp,%r14,4),%esi
test   %eax,%eax
jne    1260 <print_allocation_config+0x100>
mov    0x10(%rsp),%edx
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    126a <print_allocation_config+0x10a>
lea    0xda1(%rip),%rdi
jmp    11c3 <print_allocation_config+0x63>

LLVM IR (-O0):
%struct.pqos_cpuinfo = type { i32 }
%struct.pqos_cap = type { i32 }
@.str = [37 x i8] c"Error retrieving PQoS capabilities!\0A\00"
@.str.1 = [42 x i8] c"Error retrieving CPU socket information!\0A\00"
@.str.2 = [36 x i8] c"Error retrieving core information!\0A\00"
@.str.3 = [33 x i8] c"Core information for socket %u:\0A\00"
@.str.4 = [22 x i8] c" Core %u => COS%u\0A\00"
@.str.5 = [22 x i8] c" Core %u => ERROR\0A\00"
define void @print_allocation_config() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca %struct.pqos_cpuinfo*
%6 = alloca %struct.pqos_cap*
%7 = alloca [64 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store %struct.pqos_cpuinfo* null, %struct.pqos_cpuinfo** %5
store %struct.pqos_cap* null, %struct.pqos_cap** %6
%11 = call i32 @pqos_cap_get(%struct.pqos_cap** %6, %struct.pqos_cpuinfo** %5)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %80
16: ; preds = %0
%17 = load %struct.pqos_cpuinfo*, %struct.pqos_cpuinfo** %5
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%19 = call i32 @pqos_cpu_get_sockets(%struct.pqos_cpuinfo* %17, i32 2, i32* %3, i32* %18)
store i32 %19, i32* %1
%20 = load i32, i32* %1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %80
24: ; preds = %16
store i32 0, i32* %2
br label %25
25: ; preds = %77, %24
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %80
29: ; preds = %25
store i32 0, i32* %8
store i32 0, i32* %9
%30 = load %struct.pqos_cpuinfo*, %struct.pqos_cpuinfo** %5
%31 = load i32, i32* %2
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%36 = call i32 @pqos_cpu_get_cores(%struct.pqos_cpuinfo* %30, i32 %34, i32 64, i32* %8, i32* %35)
store i32 %36, i32* %1
%37 = load i32, i32* %1
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %80
41: ; preds = %29
%42 = load i32, i32* %2
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %45)
store i32 0, i32* %9
br label %47
47: ; preds = %73, %41
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = icmp ult i32 %48, %49
br i1 %50, label %51, label %76
51: ; preds = %47
store i32 0, i32* %10
%52 = load i32, i32* %9
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = call i32 @pqos_l3ca_assoc_get(i32 %55, i32* %10)
store i32 %56, i32* %1
%57 = load i32, i32* %1
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %51
%60 = load i32, i32* %9
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = load i32, i32* %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %63, i32 %64)
br label %72
66: ; preds = %51
%67 = load i32, i32* %9
%68 = zext i32 %67 to i64
%69 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %68
%70 = load i32, i32* %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %66, %59
br label %73
73: ; preds = %72
%74 = load i32, i32* %9
%75 = add i32 %74, 1
store i32 %75, i32* %9
br label %47
76: ; preds = %47
br label %77
77: ; preds = %76
%78 = load i32, i32* %2
%79 = add i32 %78, 1
store i32 %79, i32* %2
br label %25
80: ; preds = %14, %22, %39, %25
ret void
}

LLVM IR (-O2):
%struct.pqos_cpuinfo = type { i32 }
%struct.pqos_cap = type { i32 }
@.str.3 = [33 x i8] c"Core information for socket %u:\0A\00"
@.str.4 = [22 x i8] c" Core %u => COS%u\0A\00"
@.str.5 = [22 x i8] c" Core %u => ERROR\0A\00"
@str = [35 x i8] c"Error retrieving core information!\00"
@str.6 = [41 x i8] c"Error retrieving CPU socket information!\00"
@str.7 = [36 x i8] c"Error retrieving PQoS capabilities!\00"
define void @print_allocation_config() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca %struct.pqos_cpuinfo*
%4 = alloca %struct.pqos_cap*
%5 = alloca [64 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %1 to i8*
%9 = bitcast [2 x i32]* %2 to i8*
%10 = bitcast %struct.pqos_cpuinfo** %3 to i8*
store %struct.pqos_cpuinfo* null, %struct.pqos_cpuinfo** %3
%11 = bitcast %struct.pqos_cap** %4 to i8*
store %struct.pqos_cap* null, %struct.pqos_cap** %4
%12 = call i32 @pqos_cap_get(%struct.pqos_cap** %4, %struct.pqos_cpuinfo** %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.7, i64 0, i64 0))
br label %67
16: ; preds = %0
%17 = load %struct.pqos_cpuinfo*, %struct.pqos_cpuinfo** %3
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%19 = call i32 @pqos_cpu_get_sockets(%struct.pqos_cpuinfo* %17, i32 2, i32* %1, i32* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 0
br i1 %23, label %67, label %24
24: ; preds = %21
%25 = bitcast [64 x i32]* %5 to i8*
%26 = bitcast i32* %6 to i8*
%27 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 0
%28 = bitcast i32* %7 to i8*
br label %36
29: ; preds = %16
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.6, i64 0, i64 0))
br label %67
31: ; preds = %62, %45
%32 = add nuw nsw i64 %37, 1
%33 = load i32, i32* %1
%34 = zext i32 %33 to i64
%35 = icmp ult i64 %32, %34
br i1 %35, label %36, label %67
36: ; preds = %24, %31
%37 = phi i64 [ 0, %24 ], [ %32, %31 ]
store i32 0, i32* %6
%38 = load %struct.pqos_cpuinfo*, %struct.pqos_cpuinfo** %3
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 %37
%40 = load i32, i32* %39
%41 = call i32 @pqos_cpu_get_cores(%struct.pqos_cpuinfo* %38, i32 %40, i32 64, i32* %6, i32* %27)
%42 = icmp eq i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %67
45: ; preds = %36
%46 = load i32, i32* %39
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 0
br i1 %49, label %31, label %50
50: ; preds = %45, %62
%51 = phi i64 [ %63, %62 ], [ 0, %45 ]
store i32 0, i32* %7
%52 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = call i32 @pqos_l3ca_assoc_get(i32 %53, i32* %7)
%55 = icmp eq i32 %54, 0
%56 = load i32, i32* %52
br i1 %55, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* %7
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %58)
br label %62
60: ; preds = %50
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %56)
br label %62
62: ; preds = %60, %57
%63 = add nuw nsw i64 %51, 1
%64 = load i32, i32* %6
%65 = zext i32 %64 to i64
%66 = icmp ult i64 %63, %65
br i1 %66, label %50, label %31
67: ; preds = %31, %21, %43, %29, %14
ret void
}