#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 stat {
  int dummy;
};
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, unsigned int,
                            char const *);
scalar_t__ stat(char *, struct stat *);
unsigned int cpuidle_state_file_exists(unsigned int cpu, unsigned int idlestate,
                                       const char *fname) {
  char path[255];
  struct stat statbuf;
  snprintf(path, sizeof(path),
           "/sys/devices/system/cpu/"
           "cpu%u/cpuidle/state%u/%s",
           cpu, idlestate, fname);
  if (stat(path, &statbuf) != 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<cpuidle_state_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x18(%rbp),%r9
mov    $0xff,%esi
lea    0xead(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x128(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1181 <cpuidle_state_file_exists+0x61>
movl   $0x0,-0x4(%rbp)
jmp    1188 <cpuidle_state_file_exists+0x68>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuidle_state_file_exists>:
push   %rbx
sub    $0x110,%rsp
mov    %rdx,%r9
mov    %esi,%r8d
mov    %edi,%ecx
lea    0xec9(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1030 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [49 x i8] c"/sys/devices/system/cpu/cpu%u/cpuidle/state%u/%s\00"
define i32 @cpuidle_state_file_exists(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [255 x i8]
%9 = alloca %struct.stat
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = call i32 @snprintf(i8* %10, i32 255, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i8* %13)
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%16 = call i64 @stat(i8* %15, %struct.stat* %9)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 0, i32* %4
br label %20
19: ; preds = %3
store i32 1, i32* %4
br label %20
20: ; preds = %19, %18
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [49 x i8] c"/sys/devices/system/cpu/cpu%u/cpuidle/state%u/%s\00"
define i32 @cpuidle_state_file_exists(i32 %0, i32 %1, i8* %2) {
%4 = alloca [255 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.stat* %5 to i8*
%8 = call i32 @snprintf(i8* %6, i32 255, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i8* %2)
%9 = call i64 @stat(i8* %6, %struct.stat* %5)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
ret i32 %11
}