#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *opendir(char const *const);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *const,
                           int /*<<< orphan*/);
scalar_t__ strncmp(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  DIR *d;
  FILE *f;
  struct dirent *de;
  const char *const path = "/sys/devices/system/cpu/";
  char filename[255];
  d = opendir(path);
  while ((de = readdir(d)))
    if (strncmp(de->d_name, "cpu", 3) == 0) {
      sprintf(filename, "%s%s/power/runtime_enabled", path, de->d_name);
      f = fopen(filename, "w");
      if (!f && errno != EACCES)
        continue;
      if (f)
        fclose(f);
      printf("%s\n", filename);
    }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe65(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1269 <main+0xf9>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1264 <main+0xf4>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
lea    0xe2d(%rip),%rsi
lea    0xe09(%rip),%rdx
call   1090 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123d <main+0xcd>
mov    0x2db3(%rip),%rax
mov    (%rax),%rax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
je     123d <main+0xcd>
jmp    11a4 <main+0x34>
cmpq   $0x0,-0x20(%rbp)
je     1251 <main+0xe1>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x130(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1060 <printf@plt>
jmp    11a4 <main+0x34>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe78(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1239 <main+0xc9>
mov    %rax,%r15
lea    0xe6e(%rip),%r14
lea    0xe4e(%rip),%r12
mov    %rsp,%r13
lea    0xe7c(%rip),%rbp
jmp    11e7 <main+0x77>
xchg   %ax,%ax
mov    %rax,%rdi
call   1040 <fclose@plt>
lea    0xe6b(%rip),%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     1239 <main+0xc9>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d7 <main+0x67>
mov    (%r15),%ecx
mov    %r13,%rdi
lea    0xe14(%rip),%rsi
mov    %r12,%rdx
call   1090 <sprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11c0 <main+0x50>
mov    0x2db0(%rip),%rax
mov    (%rax),%rax
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%rax
je     11c8 <main+0x58>
jmp    11d7 <main+0x67>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [25 x i8] c"/sys/devices/system/cpu/\00"
@.str.1 = [4 x i8] c"cpu\00"
@.str.2 = [27 x i8] c"%s%s/power/runtime_enabled\00"
@.str.3 = [2 x i8] c"w\00"
@errno = global i64 0
@EACCES = global i64 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i8*
%10 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %9
%11 = call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0))
store i32* %11, i32** %6
br label %12
12: ; preds = %46, %36, %2
%13 = load i32*, i32** %6
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %8
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %47
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %8
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @strncmp(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %46
22: ; preds = %16
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%24 = load %struct.dirent*, %struct.dirent** %8
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i32 %26)
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp ne i32* %30, null
br i1 %31, label %37, label %32
32: ; preds = %22
%33 = load i64, i64* @errno
%34 = load i64, i64* @EACCES
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32
br label %12
37: ; preds = %32, %22
%38 = load i32*, i32** %7
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %40, %37
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %16
br label %12
47: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [25 x i8] c"/sys/devices/system/cpu/\00"
@.str.1 = [4 x i8] c"cpu\00"
@.str.2 = [27 x i8] c"%s%s/power/runtime_enabled\00"
@.str.3 = [2 x i8] c"w\00"
@errno = global i64 0
@EACCES = global i64 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call %struct.dirent* @readdir(i32* %5)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %30, label %8
8: ; preds = %2, %27
%9 = phi %struct.dirent* [ %28, %27 ], [ %6, %2 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @strncmp(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %8
%15 = load i32, i32* %10
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i64, i64* @errno
%21 = load i64, i64* @EACCES
%22 = icmp eq i64 %20, %21
br i1 %22, label %25, label %27
23: ; preds = %14
%24 = call i32 @fclose(i32* %17)
br label %25
25: ; preds = %19, %23
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %27
27: ; preds = %8, %25, %19
%28 = call %struct.dirent* @readdir(i32* %5)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %30, label %8
30: ; preds = %27, %2
ret i32 0
}