#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 */
scalar_t__ read_int(char *, int *);
scalar_t__ read_string(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strncmp(char *, char *, int);
int system_uses_frequencyscaling() {
  int cpu = 0, done = 0, min, max;
  char filename[256], buf[256];
  while (!done) {
    (void)snprintf(filename, 256,
                   "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor",
                   cpu);
    if (0 < read_string(filename, buf, 256)) {
      if ((0 != strncmp("performance", buf, 11)) &&
          (0 != strncmp("powersafe", buf, 9))) {
        (void)snprintf(filename, 256,
                       "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq",
                       cpu);
        if (read_int(filename, &min)) {
          (void)snprintf(
              filename, 256,
              "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
          if (read_int(filename, &max)) {
            if (min != max) {
              return 1;
            }
          }
        }
      }
    } else {
      done = 1;
    }
    cpu++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<system_uses_frequencyscaling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116f <system_uses_frequencyscaling+0x2f>
jmp    12a7 <system_uses_frequencyscaling+0x167>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe7b(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read_string@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    1292 <system_uses_frequencyscaling+0x152>
lea    -0x220(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0xb,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     128d <system_uses_frequencyscaling+0x14d>
lea    -0x220(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     128d <system_uses_frequencyscaling+0x14d>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe3b(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <read_int@plt>
cmp    $0x0,%rax
je     1288 <system_uses_frequencyscaling+0x148>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe3d(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <read_int@plt>
cmp    $0x0,%rax
je     1283 <system_uses_frequencyscaling+0x143>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     127e <system_uses_frequencyscaling+0x13e>
movl   $0x1,-0x4(%rbp)
jmp    12ae <system_uses_frequencyscaling+0x16e>
jmp    1283 <system_uses_frequencyscaling+0x143>
jmp    1288 <system_uses_frequencyscaling+0x148>
jmp    128d <system_uses_frequencyscaling+0x14d>
jmp    1299 <system_uses_frequencyscaling+0x159>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1159 <system_uses_frequencyscaling+0x19>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_uses_frequencyscaling>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
lea    0xea8(%rip),%rdx
lea    0x110(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    $0x100,%esi
xor    %ecx,%ecx
call   1040 <snprintf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x100,%edx
call   1060 <read_string@plt>
test   %rax,%rax
jle    1281 <system_uses_frequencyscaling+0x141>
mov    $0x1,%ebx
lea    0xe9f(%rip),%r15
lea    0x10(%rsp),%r13
lea    0xe5c(%rip),%r12
lea    0x110(%rsp),%rbp
jmp    11de <system_uses_frequencyscaling+0x9e>
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1040 <snprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1060 <read_string@plt>
add    $0x1,%ebx
test   %rax,%rax
jle    127f <system_uses_frequencyscaling+0x13f>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b0 <system_uses_frequencyscaling+0x70>
lea    0xe49(%rip),%rdi
mov    %r13,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b0 <system_uses_frequencyscaling+0x70>
lea    -0x1(%rbx),%r14d
mov    %rbp,%rdi
mov    $0x100,%esi
lea    0xe2e(%rip),%rdx
mov    %r14d,%ecx
call   1040 <snprintf@plt>
mov    %rbp,%rdi
lea    0xc(%rsp),%rsi
call   1050 <read_int@plt>
test   %rax,%rax
je     11b0 <system_uses_frequencyscaling+0x70>
mov    %rbp,%rdi
mov    $0x100,%esi
lea    0xe38(%rip),%rdx
mov    %r14d,%ecx
call   1040 <snprintf@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <read_int@plt>
test   %rax,%rax
je     11b0 <system_uses_frequencyscaling+0x70>
mov    0xc(%rsp),%eax
cmp    0x8(%rsp),%eax
je     11b0 <system_uses_frequencyscaling+0x70>
mov    $0x1,%ebp
jmp    1281 <system_uses_frequencyscaling+0x141>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor\00"
@.str.1 = [12 x i8] c"performance\00"
@.str.2 = [10 x i8] c"powersafe\00"
@.str.3 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq\00"
@.str.4 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq\00"
define i32 @system_uses_frequencyscaling() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
store i32 0, i32* %2
store i32 0, i32* %3
br label %8
8: ; preds = %52, %0
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %55
12: ; preds = %8
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* %2
%15 = call i32 @snprintf(i8* %13, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = call i64 @read_string(i8* %16, i8* %17, i32 256)
%19 = icmp slt i64 0, %18
br i1 %19, label %20, label %51
20: ; preds = %12
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = call i64 @strncmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 11)
%23 = icmp ne i64 0, %22
br i1 %23, label %24, label %50
24: ; preds = %20
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i64 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 9)
%27 = icmp ne i64 0, %26
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %2
%31 = call i32 @snprintf(i8* %29, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%33 = call i64 @read_int(i8* %32, i32* %4)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %28
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%37 = load i32, i32* %2
%38 = call i32 @snprintf(i8* %36, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = call i64 @read_int(i8* %39, i32* %5)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %35
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 1, i32* %1
br label %56
47: ; preds = %42
br label %48
48: ; preds = %47, %35
br label %49
49: ; preds = %48, %28
br label %50
50: ; preds = %49, %24, %20
br label %52
51: ; preds = %12
store i32 1, i32* %3
br label %52
52: ; preds = %51, %50
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %8
55: ; preds = %8
store i32 0, i32* %1
br label %56
56: ; preds = %55, %46
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor\00"
@.str.1 = [12 x i8] c"performance\00"
@.str.2 = [10 x i8] c"powersafe\00"
@.str.3 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq\00"
@.str.4 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq\00"
define i32 @system_uses_frequencyscaling() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = call i64 @read_string(i8* %7, i8* %8, i32 256)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %36
12: ; preds = %0, %31
%13 = phi i32 [ %32, %31 ], [ 0, %0 ]
%14 = call i64 @strncmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %31, label %16
16: ; preds = %12
%17 = call i64 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32 9)
%18 = icmp eq i64 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %16
%20 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%21 = call i64 @read_int(i8* %7, i32* %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%25 = call i64 @read_int(i8* %7, i32* %2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %12, %16, %23, %27, %19
%32 = add nuw nsw i32 %13, 1
%33 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = call i64 @read_string(i8* %7, i8* %8, i32 256)
%35 = icmp sgt i64 %34, 0
br i1 %35, label %12, label %36
36: ; preds = %27, %31, %0
%37 = phi i32 [ 0, %0 ], [ 1, %27 ], [ 0, %31 ]
ret i32 %37
}