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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
char *StrApp(char **, char *, int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
char *find_temperature_proc_file(void) {
  DIR *dir;
  char *basedir = "/proc/acpi/thermal_zone/";
  struct dirent *entry;
  dir = opendir(basedir);
  if (!dir)
    return NULL;
  while ((entry = readdir(dir))) {
    char *temp;
    if (!strcmp(entry->d_name, "."))
      continue;
    if (!strcmp(entry->d_name, ".."))
      continue;
    temp = StrApp((char **)NULL, basedir, entry->d_name, "/temperature",
                  (char *)NULL);
    if (!access(temp, R_OK)) {
      closedir(dir);
      return temp;
    }
    free(temp);
  }
  closedir(dir);
  return NULL;
}


x86 assembly (clang, -O0):
<find_temperature_proc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <find_temperature_proc_file+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1276 <find_temperature_proc_file+0x106>
jmp    11ad <find_temperature_proc_file+0x3d>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1265 <find_temperature_proc_file+0xf5>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11e4 <find_temperature_proc_file+0x74>
jmp    11ad <find_temperature_proc_file+0x3d>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1204 <find_temperature_proc_file+0x94>
jmp    11ad <find_temperature_proc_file+0x3d>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%r8d
lea    0xe02(%rip),%rcx
mov    %r8,%rdi
call   1090 <StrApp@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%eax
jne    1257 <find_temperature_proc_file+0xe7>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1276 <find_temperature_proc_file+0x106>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11ad <find_temperature_proc_file+0x3d>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_temperature_proc_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     123e <find_temperature_proc_file+0xce>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1232 <find_temperature_proc_file+0xc2>
mov    %rax,%rbp
lea    0xe6c(%rip),%r14
lea    0xe64(%rip),%r15
lea    0xe60(%rip),%r13
mov    0x2e1d(%rip),%r12
jmp    11e8 <find_temperature_proc_file+0x78>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1232 <find_temperature_proc_file+0xc2>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11d8 <find_temperature_proc_file+0x68>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11d8 <find_temperature_proc_file+0x68>
mov    0x0(%rbp),%edx
xor    %edi,%edi
lea    0xdee(%rip),%rsi
mov    %r13,%rcx
xor    %r8d,%r8d
call   1090 <StrApp@plt>
mov    %rax,%rbp
mov    (%r12),%esi
mov    %rax,%rdi
call   1080 <access@plt>
test   %eax,%eax
jne    11d0 <find_temperature_proc_file+0x60>
jmp    1234 <find_temperature_proc_file+0xc4>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <closedir@plt>
jmp    1240 <find_temperature_proc_file+0xd0>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%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"/proc/acpi/thermal_zone/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [13 x i8] c"/temperature\00"
@R_OK = global i32 0
define i8* @find_temperature_proc_file() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca %struct.dirent*
%5 = alloca i8*
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %0
store i8* null, i8** %1
br label %50
11: ; preds = %0
br label %12
12: ; preds = %44, %29, %22, %11
%13 = load i32*, i32** %2
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %4
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %47
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %4
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @strcmp(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
br label %12
23: ; preds = %16
%24 = load %struct.dirent*, %struct.dirent** %4
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @strcmp(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %23
br label %12
30: ; preds = %23
%31 = load i8*, i8** %3
%32 = load %struct.dirent*, %struct.dirent** %4
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i8* @StrApp(i8** null, i8* %31, i32 %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* null)
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = load i32, i32* @R_OK
%38 = call i32 @access(i8* %36, i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %30
%41 = load i32*, i32** %2
%42 = call i32 @closedir(i32* %41)
%43 = load i8*, i8** %5
store i8* %43, i8** %1
br label %50
44: ; preds = %30
%45 = load i8*, i8** %5
%46 = call i32 @free(i8* %45)
br label %12
47: ; preds = %12
%48 = load i32*, i32** %2
%49 = call i32 @closedir(i32* %48)
store i8* null, i8** %1
br label %50
50: ; preds = %47, %40, %10
%51 = load i8*, i8** %1
ret i8* %51
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [25 x i8] c"/proc/acpi/thermal_zone/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [13 x i8] c"/temperature\00"
@R_OK = global i32 0
define i8* @find_temperature_proc_file() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %30, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %27, label %6
6: ; preds = %3, %24
%7 = phi %struct.dirent* [ %25, %24 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @strcmp(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %6
%13 = load i32, i32* %8
%14 = tail call i32 @strcmp(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = load i32, i32* %8
%18 = tail call i8* @StrApp(i8** null, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* null)
%19 = load i32, i32* @R_OK
%20 = tail call i32 @access(i8* %18, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = tail call i32 @free(i8* %18)
br label %24
24: ; preds = %12, %6, %22
%25 = tail call %struct.dirent* @readdir(i32* %1)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %27, label %6
27: ; preds = %24, %16, %3
%28 = phi i8* [ null, %3 ], [ %18, %16 ], [ null, %24 ]
%29 = tail call i32 @closedir(i32* %1)
br label %30
30: ; preds = %27, %0
%31 = phi i8* [ null, %0 ], [ %28, %27 ]
ret i8* %31
}