#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 */

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int powercap_rapl_control_is_enabled();
int powercap_rapl_control_is_supported();
scalar_t__ powercap_rapl_control_set_enabled(int);
int /*<<< orphan*/ printf(char *, ...);
int test_root(int ro) {
  int enabled;
  int supported = powercap_rapl_control_is_supported();
  if (supported < 0) {
    perror("powercap_rapl_control_is_supported");
    return -1;
  } else if (supported == 0) {
    printf("RAPL not supported\n");
    return -1;
  }
  enabled = powercap_rapl_control_is_enabled();
  if (enabled < 0) {
    perror("powercap_rapl_control_is_enabled");
    return -1;
  } else {
    printf("RAPL enabled: %s\n", enabled > 0 ? "yes" : "no");
  }
  if (!ro && powercap_rapl_control_set_enabled(enabled)) {
    perror("powercap_rapl_control_set_enabled");
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <powercap_rapl_control_is_supported@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1187 <test_root+0x37>
lea    0xe8a(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <test_root+0xe1>
cmpl   $0x0,-0x10(%rbp)
jne    11ab <test_root+0x5b>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <test_root+0xe1>
jmp    11b0 <test_root+0x60>
mov    $0x0,%al
call   1070 <powercap_rapl_control_is_enabled@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11dc <test_root+0x8c>
lea    0xe6c(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <test_root+0xe1>
mov    -0xc(%rbp),%ecx
lea    0xe88(%rip),%rsi
lea    0xe7d(%rip),%rax
cmp    $0x0,%ecx
cmovg  %rax,%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    122a <test_root+0xda>
mov    -0xc(%rbp),%edi
call   1050 <powercap_rapl_control_set_enabled@plt>
cmp    $0x0,%rax
je     122a <test_root+0xda>
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_root>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1050 <powercap_rapl_control_is_supported@plt>
test   %eax,%eax
js     11d0 <test_root+0x70>
je     11c2 <test_root+0x62>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <powercap_rapl_control_is_enabled@plt>
test   %eax,%eax
js     11d9 <test_root+0x79>
mov    %eax,%ebp
lea    0xed0(%rip),%rax
lea    0xec5(%rip),%rsi
cmove  %rax,%rsi
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jne    11ea <test_root+0x8a>
mov    %ebp,%edi
call   1060 <powercap_rapl_control_set_enabled@plt>
test   %rax,%rax
je     11ea <test_root+0x8a>
lea    0xea2(%rip),%rdi
call   1070 <perror@plt>
jmp    11ea <test_root+0x8a>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
jmp    11e5 <test_root+0x85>
lea    0xe29(%rip),%rdi
jmp    11e0 <test_root+0x80>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"powercap_rapl_control_is_supported\00"
@.str.1 = [20 x i8] c"RAPL not supported\0A\00"
@.str.2 = [33 x i8] c"powercap_rapl_control_is_enabled\00"
@.str.3 = [18 x i8] c"RAPL enabled: %s\0A\00"
@.str.4 = [4 x i8] c"yes\00"
@.str.5 = [3 x i8] c"no\00"
@.str.6 = [34 x i8] c"powercap_rapl_control_set_enabled\00"
define i32 @test_root(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 (...) @powercap_rapl_control_is_supported()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
11: ; preds = %1
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
16: ; preds = %11
br label %17
17: ; preds = %16
%18 = call i32 (...) @powercap_rapl_control_is_enabled()
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
23: ; preds = %17
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = load i32, i32* %4
%34 = call i64 @powercap_rapl_control_set_enabled(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %32, %29
store i32 0, i32* %2
br label %39
39: ; preds = %38, %21, %14, %9
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [35 x i8] c"powercap_rapl_control_is_supported\00"
@.str.2 = [33 x i8] c"powercap_rapl_control_is_enabled\00"
@.str.3 = [18 x i8] c"RAPL enabled: %s\0A\00"
@.str.4 = [4 x i8] c"yes\00"
@.str.5 = [3 x i8] c"no\00"
@.str.6 = [34 x i8] c"powercap_rapl_control_set_enabled\00"
@str = [19 x i8] c"RAPL not supported\00"
define i32 @test_root(i32 %0) {
%2 = tail call i32 (...) @powercap_rapl_control_is_supported()
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %25
6: ; preds = %1
%7 = icmp eq i32 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %25
10: ; preds = %6
%11 = tail call i32 (...) @powercap_rapl_control_is_enabled()
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %25
15: ; preds = %10
%16 = icmp eq i32 %11, 0
%17 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = icmp eq i32 %0, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = tail call i64 @powercap_rapl_control_set_enabled(i32 %11)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %25
25: ; preds = %15, %20, %23, %13, %8, %4
%26 = phi i32 [ -1, %4 ], [ -1, %8 ], [ -1, %13 ], [ 0, %23 ], [ 0, %20 ], [ 0, %15 ]
ret i32 %26
}