#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 */
typedef int /*<<< orphan*/ uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ cat(char *, int /*<<< orphan*/);
int def_region(int, char *, int /*<<< orphan*/, int);
int enter_stacks(int, int /*<<< orphan*/, int);
int exit_stacks(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_category(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int test_dvfs(uint64_t bid, int message) {
  char *category = "dvfs";
  int error = 0;
  uint32_t rid = 2;
  print_category(message, category);
  if (message == 1)
    printf("\nFile %s \n",
           "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
  if (message == 1)
    printf("\nFreq:\n");
  printf("init_dvfs_freq_before=");
  cat("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", 0);
  printf("\n");
  error |= def_region(message, category, bid, rid);
  error |= enter_stacks(message, bid, rid);
  if (message == 1)
    printf("\nFreq:\n");
  printf("bin_dvfs_freq_before=");
  cat("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", 0);
  printf("\n");
  error |= exit_stacks(message, bid, rid);
  if (message == 1)
    printf("\nFreq:\n");
  printf("bin_dvfs_freq_after=");
  cat("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", 0);
  printf("\n");
  if (message == 1)
    printf("*********\n");
  return error;
}


x86 assembly (clang, -O0):
<test_dvfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe8b(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <print_category@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11b2 <test_dvfs+0x52>
lea    0xe61(%rip),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11ca <test_dvfs+0x6a>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe31(%rip),%rdi
xor    %esi,%esi
call   1080 <cat@plt>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <def_region@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <enter_stacks@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1238 <test_dvfs+0xd8>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc3(%rip),%rdi
xor    %esi,%esi
call   1080 <cat@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <exit_stacks@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    128e <test_dvfs+0x12e>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd6d(%rip),%rdi
xor    %esi,%esi
call   1080 <cat@plt>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    12d0 <test_dvfs+0x170>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_dvfs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r15d
lea    0xe6d(%rip),%rsi
mov    %ebx,%edi
call   1090 <print_category@plt>
cmp    $0x1,%ebx
jne    11c0 <test_dvfs+0x40>
lea    0xe5f(%rip),%rdi
lea    0xe63(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xed7(%rip),%rdi
call   1050 <puts@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe3b(%rip),%rdi
xor    %esi,%esi
call   10a0 <cat@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe13(%rip),%rsi
mov    %ebx,%edi
mov    %r15d,%edx
mov    $0x2,%ecx
call   1070 <def_region@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %r15d,%esi
mov    $0x2,%edx
call   1080 <enter_stacks@plt>
mov    %eax,%ebp
cmp    $0x1,%ebx
jne    1221 <test_dvfs+0xa1>
lea    0xe76(%rip),%rdi
call   1050 <puts@plt>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdda(%rip),%rdi
xor    %esi,%esi
call   10a0 <cat@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    $0x2,%edx
call   1040 <exit_stacks@plt>
mov    %eax,%r15d
cmp    $0x1,%ebx
jne    129e <test_dvfs+0x11e>
lea    0xe2d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd91(%rip),%rdi
xor    %esi,%esi
call   10a0 <cat@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdf1(%rip),%rdi
call   1050 <puts@plt>
jmp    12c4 <test_dvfs+0x144>
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd5d(%rip),%rdi
xor    %esi,%esi
call   10a0 <cat@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
or     %r14d,%ebp
or     %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"dvfs\00"
@.str.1 = [11 x i8] c"\0AFile %s \0A\00"
@.str.2 = [54 x i8] c"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq\00"
@.str.3 = [8 x i8] c"\0AFreq:\0A\00"
@.str.4 = [23 x i8] c"init_dvfs_freq_before=\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [22 x i8] c"bin_dvfs_freq_before=\00"
@.str.7 = [21 x i8] c"bin_dvfs_freq_after=\00"
@.str.8 = [11 x i8] c"*********\0A\00"
define i32 @test_dvfs(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %6
store i32 2, i32* %7
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = call i32 @print_category(i32 %8, i8* %9)
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32, i32* %4
%25 = load i8*, i8** %5
%26 = load i32, i32* %3
%27 = load i32, i32* %7
%28 = call i32 @def_region(i32 %24, i8* %25, i32 %26, i32 %27)
%29 = load i32, i32* %6
%30 = or i32 %29, %28
store i32 %30, i32* %6
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = load i32, i32* %7
%34 = call i32 @enter_stacks(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* %6
%36 = or i32 %35, %34
store i32 %36, i32* %6
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %20
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %20
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%45 = load i32, i32* %4
%46 = load i32, i32* %3
%47 = load i32, i32* %7
%48 = call i32 @exit_stacks(i32 %45, i32 %46, i32 %47)
%49 = load i32, i32* %6
%50 = or i32 %49, %48
store i32 %50, i32* %6
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %41
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %41
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%57 = call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* %4
%60 = icmp eq i32 %59, 1
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %63
63: ; preds = %61, %55
%64 = load i32, i32* %6
ret i32 %64
}

LLVM IR (-O2):
@.str = [5 x i8] c"dvfs\00"
@.str.1 = [11 x i8] c"\0AFile %s \0A\00"
@.str.2 = [54 x i8] c"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq\00"
@.str.4 = [23 x i8] c"init_dvfs_freq_before=\00"
@.str.6 = [22 x i8] c"bin_dvfs_freq_before=\00"
@.str.7 = [21 x i8] c"bin_dvfs_freq_after=\00"
@str = [10 x i8] c"*********\00"
@str.11 = [7 x i8] c"\0AFreq:\00"
define i32 @test_dvfs(i32 %0, i32 %1) {
%3 = tail call i32 @print_category(i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %1, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
br label %8
8: ; preds = %2, %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @def_region(i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0, i32 2)
%13 = tail call i32 @enter_stacks(i32 %1, i32 %0, i32 2)
br i1 %4, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%18 = tail call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%19 = tail call i32 @putchar(i32 10)
%20 = tail call i32 @exit_stacks(i32 %1, i32 %0, i32 2)
br i1 %4, label %21, label %27
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%24 = tail call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%25 = tail call i32 @putchar(i32 10)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %31
27: ; preds = %16
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%29 = tail call i32 @cat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 0)
%30 = tail call i32 @putchar(i32 10)
br label %31
31: ; preds = %27, %21
%32 = or i32 %13, %12
%33 = or i32 %32, %20
ret i32 %33
}