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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
void activate_runtime_suspend_path(char *path) {
  DIR *dir;
  struct dirent *dirent;
  FILE *file;
  char filename[PATH_MAX];
  dir = opendir(path);
  if (!dir)
    return;
  while ((dirent = readdir(dir))) {
    if (dirent->d_name[0] == '.')
      continue;
    sprintf(filename, "%s/%s/power/control", path, dirent->d_name);
    file = fopen(filename, "w");
    if (!file)
      continue;
    fprintf(file, "auto\n");
    fclose(file);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<activate_runtime_suspend_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cc <activate_runtime_suspend_path+0x5c>
movl   $0x1,-0x34(%rbp)
jmp    126d <activate_runtime_suspend_path+0xfd>
jmp    11d1 <activate_runtime_suspend_path+0x61>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     125d <activate_runtime_suspend_path+0xed>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1200 <activate_runtime_suspend_path+0x90>
jmp    11d1 <activate_runtime_suspend_path+0x61>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xdea(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123f <activate_runtime_suspend_path+0xcf>
jmp    11d1 <activate_runtime_suspend_path+0x61>
mov    -0x20(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d1 <activate_runtime_suspend_path+0x61>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<activate_runtime_suspend_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
call   1040 <opendir@plt>
test   %rax,%rax
je     1243 <activate_runtime_suspend_path+0xd3>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     122d <activate_runtime_suspend_path+0xbd>
lea    0xe54(%rip),%r13
jmp    11dd <activate_runtime_suspend_path+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     122d <activate_runtime_suspend_path+0xbd>
mov    (%rax),%rcx
cmpb   $0x2e,(%rcx)
je     11d0 <activate_runtime_suspend_path+0x60>
mov    %r15,%rdi
lea    0xe11(%rip),%rsi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d0 <activate_runtime_suspend_path+0x60>
mov    %rax,%r12
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xdfb(%rip),%rdi
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    11d0 <activate_runtime_suspend_path+0x60>
mov    %rbx,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [20 x i8] c"%s/%s/power/control\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"auto\0A\00"
define void @activate_runtime_suspend_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %2
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %1
store i32 1, i32* %8
br label %50
18: ; preds = %1
br label %19
19: ; preds = %42, %41, %31, %18
%20 = load i32*, i32** %3
%21 = call %struct.dirent* @readdir(i32* %20)
store %struct.dirent* %21, %struct.dirent** %4
%22 = icmp ne %struct.dirent* %21, null
br i1 %22, label %23, label %47
23: ; preds = %19
%24 = load %struct.dirent*, %struct.dirent** %4
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 46
br i1 %30, label %31, label %32
31: ; preds = %23
br label %19
32: ; preds = %23
%33 = load i8*, i8** %2
%34 = load %struct.dirent*, %struct.dirent** %4
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %36)
%38 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %5
%39 = load i32*, i32** %5
%40 = icmp ne i32* %39, null
br i1 %40, label %42, label %41
41: ; preds = %32
br label %19
42: ; preds = %32
%43 = load i32*, i32** %5
%44 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32*, i32** %5
%46 = call i32 @fclose(i32* %45)
br label %19
47: ; preds = %19
%48 = load i32*, i32** %3
%49 = call i32 @closedir(i32* %48)
store i32 0, i32* %8
br label %50
50: ; preds = %47, %17
%51 = load i8*, i8** %6
%52 = load i32, i32* %8
switch i32 %52, label %54 [
i32 0, label %53
i32 1, label %53
]
53: ; preds = %50, %50
ret void
54: ; preds = %50
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [20 x i8] c"%s/%s/power/control\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"auto\0A\00"
define void @activate_runtime_suspend_path(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %28, label %7
7: ; preds = %1
%8 = tail call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %26, label %10
10: ; preds = %7, %23
%11 = phi %struct.dirent* [ %24, %23 ], [ %8, %7 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 46
br i1 %15, label %23, label %16
16: ; preds = %10
%17 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %13)
%18 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %18)
%22 = tail call i32 @fclose(i32* %18)
br label %23
23: ; preds = %20, %10, %16
%24 = tail call %struct.dirent* @readdir(i32* %5)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %10
26: ; preds = %23, %7
%27 = tail call i32 @closedir(i32* %5)
br label %28
28: ; preds = %1, %26
ret void
}