#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 stat {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int alloc_assoc_get(unsigned int const, unsigned int *);
int /*<<< orphan*/ log_printf(int, char *, char *);
int resctrl_mon_assoc_get(unsigned int const, char *, int);
int resctrl_mon_assoc_set(unsigned int const, char const *);
int /*<<< orphan*/ resctrl_mon_group_path(unsigned int, char const *,
                                          int /*<<< orphan*/ *, char *, int);
scalar_t__ stat(char *, struct stat *);
int resctrl_mon_assoc_restore(const unsigned lcore, const char *name) {
  int ret;
  char buf[128];
  unsigned class_id;
  struct stat st;
  ;
  ret = resctrl_mon_assoc_get(lcore, buf, sizeof(buf));
  if (ret == 0)
    return 0;
  ret = alloc_assoc_get(lcore, &class_id);
  if (ret != 0)
    return ret;
  resctrl_mon_group_path(class_id, name, NULL, buf, sizeof(buf));
  if (stat(buf, &st) != 0) {
    log_printf((1 << 1),
               "WARN: "
               "Could not restore core association with mon "
               "group %s does not exists\n",
               buf);
    return 3;
  }
  ret = resctrl_mon_assoc_set(lcore, name);
  return ret;
}


x86 assembly (clang, -O0):
<resctrl_mon_assoc_restore>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1050 <resctrl_mon_assoc_get@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    119f <resctrl_mon_assoc_restore+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    123c <resctrl_mon_assoc_restore+0xdc>
mov    -0x8(%rbp),%edi
lea    -0xa4(%rbp),%rsi
call   1040 <alloc_assoc_get@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c6 <resctrl_mon_assoc_restore+0x66>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123c <resctrl_mon_assoc_restore+0xdc>
mov    -0xa4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0xa0(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
mov    $0x80,%r8d
call   1030 <resctrl_mon_group_path@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     1227 <resctrl_mon_assoc_restore+0xc7>
lea    -0xa0(%rbp),%rdx
mov    $0x2,%edi
lea    0xdea(%rip),%rsi
call   1060 <log_printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    123c <resctrl_mon_assoc_restore+0xdc>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <resctrl_mon_assoc_set@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resctrl_mon_assoc_restore>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x10(%rsp),%rsi
mov    $0x80,%edx
call   1050 <resctrl_mon_assoc_get@plt>
test   %eax,%eax
je     11de <resctrl_mon_assoc_restore+0x7e>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
call   1040 <alloc_assoc_get@plt>
test   %eax,%eax
jne    11ec <resctrl_mon_assoc_restore+0x8c>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%r14
mov    %rbx,%rsi
xor    %edx,%edx
mov    %r14,%rcx
mov    $0x80,%r8d
call   1030 <resctrl_mon_group_path@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1070 <stat@plt>
test   %rax,%rax
je     11e2 <resctrl_mon_assoc_restore+0x82>
lea    0xe38(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    $0x2,%edi
call   1060 <log_printf@plt>
mov    $0x3,%eax
jmp    11ec <resctrl_mon_assoc_restore+0x8c>
xor    %eax,%eax
jmp    11ec <resctrl_mon_assoc_restore+0x8c>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <resctrl_mon_assoc_set@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [76 x i8] c"WARN: Could not restore core association with mon group %s does not exists\0A\00"
define i32 @resctrl_mon_assoc_restore(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca %struct.stat
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = load i32, i32* %4
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%12 = call i32 @resctrl_mon_assoc_get(i32 %10, i8* %11, i32 128)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %39
16: ; preds = %2
%17 = load i32, i32* %4
%18 = call i32 @alloc_assoc_get(i32 %17, i32* %8)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %39
23: ; preds = %16
%24 = load i32, i32* %8
%25 = load i8*, i8** %5
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = call i32 @resctrl_mon_group_path(i32 %24, i8* %25, i32* null, i8* %26, i32 128)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%29 = call i64 @stat(i8* %28, %struct.stat* %9)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%33 = call i32 @log_printf(i32 2, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %32)
store i32 3, i32* %3
br label %39
34: ; preds = %23
%35 = load i32, i32* %4
%36 = load i8*, i8** %5
%37 = call i32 @resctrl_mon_assoc_set(i32 %35, i8* %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
store i32 %38, i32* %3
br label %39
39: ; preds = %34, %31, %21, %15
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [76 x i8] c"WARN: Could not restore core association with mon group %s does not exists\0A\00"
define i32 @resctrl_mon_assoc_restore(i32 %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca %struct.stat
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.stat* %5 to i8*
%9 = call i32 @resctrl_mon_assoc_get(i32 %0, i8* %6, i32 128)
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = call i32 @alloc_assoc_get(i32 %0, i32* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i32, i32* %4
%16 = call i32 @resctrl_mon_group_path(i32 %15, i8* %1, i32* null, i8* %6, i32 128)
%17 = call i64 @stat(i8* %6, %struct.stat* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = call i32 @log_printf(i32 2, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %23
21: ; preds = %14
%22 = call i32 @resctrl_mon_assoc_set(i32 %0, i8* %1)
br label %23
23: ; preds = %11, %2, %21, %19
%24 = phi i32 [ 3, %19 ], [ %22, %21 ], [ 0, %2 ], [ %12, %11 ]
ret i32 %24
}