#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, char const *);
int /*<<< orphan*/ stderr;
FILE *openCPUFreqFile(unsigned int coreID, const char *fileName,
                      const char *mode) {
  char filePathBuffer[100] = {'\0'};
  snprintf(filePathBuffer, 100, "/sys/devices/system/cpu/cpu%d/cpufreq/%s",
           coreID, fileName);
  FILE *pFile = fopen(filePathBuffer, mode);
  if (pFile == NULL) {
    fprintf(stderr, "Fail to open %s\n", filePathBuffer);
  }
  return pFile;
}


x86 assembly (clang, -O0):
<openCPUFreqFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    $0x64,%esi
lea    0xe83(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11bd <openCPUFreqFile+0x7d>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xe71(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x88(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openCPUFreqFile>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r14
mov    %rsi,%r8
mov    %edi,%ecx
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe92(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <openCPUFreqFile+0x79>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    %rsp,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/%s\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Fail to open %s\0A\00"
define i32* @openCPUFreqFile(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [100 x i8]
%8 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = bitcast [100 x i8]* %7 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* %4
%12 = load i8*, i8** %5
%13 = call i32 @snprintf(i8* %10, i32 100, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %14, i8* %15)
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %3
%24 = load i32*, i32** %8
ret i32* %24
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/%s\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Fail to open %s\0A\00"
define noalias i32* @openCPUFreqFile(i32 %0, i8* %1, i8* nocapture %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 100, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %1)
%7 = call i32* @fopen(i8* %5, i8* %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %12
12: ; preds = %9, %3
ret i32* %7
}