#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int get_numCPUs();
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int main(int argn, char **argv) {
  int cpuid;
  int freq;
  int numCPUs = 0;
  char *gov;
  char *gpath = malloc(100);
  char *fpath = malloc(100);
  if (argn < 3 || argn > 4) {
    fprintf(stderr, "Usage: %s <processorID> <frequency> [<governor>] \n",
            argv[0]);
    free(gpath);
    free(fpath);
    exit(EXIT_FAILURE);
  }
  cpuid = atoi(argv[1]);
  numCPUs = get_numCPUs();
  if (cpuid < 0 || cpuid > numCPUs) {
    fprintf(stderr, "CPU %d not a valid CPU ID. Range from 0 to %d.\n", cpuid,
            numCPUs);
    free(gpath);
    free(fpath);
    exit(EXIT_FAILURE);
  }
  freq = atoi(argv[2]);
  if (freq <= 0) {
    fprintf(stderr, "Frequency must be greater than 0.\n");
    free(gpath);
    free(fpath);
    exit(EXIT_FAILURE);
  }
  if (argn == 4) {
    gov = argv[3];
    if ((strncmp(gov, "ondemand", 8)) && (strncmp(gov, "performance", 11)) &&
        (strncmp(gov, "conservative", 12)) && (strncmp(gov, "powersave", 9))) {
      fprintf(stderr, "Invalid governor %s!\n", gov);
      free(gpath);
      free(fpath);
      return (EXIT_FAILURE);
    }
    snprintf(gpath, 60,
             "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpuid);
    FILE *f = fopen(gpath, "w");
    if (f == NULL) {
      fprintf(stderr, "Unable to open path for writing\n");
      free(gpath);
      free(fpath);
      return (EXIT_FAILURE);
    }
    fprintf(f, "%s", gov);
    fclose(f);
    free(gpath);
    free(fpath);
    return (EXIT_SUCCESS);
  }
  snprintf(gpath, 60, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor",
           cpuid);
  snprintf(fpath, 60, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_setspeed",
           cpuid);
  FILE *f = fopen(gpath, "w");
  if (f == NULL) {
    fprintf(stderr, "Unable to open path for writing\n");
    free(gpath);
    free(fpath);
    return (EXIT_FAILURE);
  }
  fprintf(f, "userspace");
  fclose(f);
  f = fopen(fpath, "w");
  if (f == NULL) {
    fprintf(stderr, "Unable to open path for writing\n");
    free(gpath);
    free(fpath);
    return (EXIT_FAILURE);
  }
  fprintf(f, "%d", freq);
  fclose(f);
  free(gpath);
  free(fpath);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11ed <main+0x4d>
cmpl   $0x4,-0x8(%rbp)
jle    122c <main+0x8c>
mov    0x2dec(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   10b0 <get_numCPUs@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     125c <main+0xbc>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    129a <main+0xfa>
mov    0x2d7d(%rip),%rax
movslq (%rax),%rdi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     12ec <main+0x14c>
mov    0x2d25(%rip),%rax
movslq (%rax),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jne    1471 <main+0x2d1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd79(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13bd <main+0x21d>
mov    -0x28(%rbp),%rdi
lea    0xd63(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13bd <main+0x21d>
mov    -0x28(%rbp),%rdi
lea    0xd50(%rip),%rsi
mov    $0xc,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13bd <main+0x21d>
mov    -0x28(%rbp),%rdi
lea    0xd3e(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13bd <main+0x21d>
mov    0x2c5b(%rip),%rax
movslq (%rax),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd1f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15ac <main+0x40c>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3c,%esi
lea    0xcf8(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    142f <main+0x28f>
mov    0x2be5(%rip),%rax
movslq (%rax),%rdi
lea    0xcfc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2bb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15ac <main+0x40c>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15ac <main+0x40c>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3c,%esi
lea    0xc44(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3c,%esi
lea    0xc89(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xc53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    14fb <main+0x35b>
mov    0x2b19(%rip),%rax
movslq (%rax),%rdi
lea    0xc30(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2ae7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15ac <main+0x40c>
mov    -0x48(%rbp),%rdi
lea    0xc56(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
lea    0xbde(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1570 <main+0x3d0>
mov    0x2aa4(%rip),%rax
movslq (%rax),%rdi
lea    0xbbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    15ac <main+0x40c>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xbe8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    -0x5(%rbp),%eax
cmp    $0xfffffffd,%eax
jbe    13fc <main+0x23c>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   10c0 <get_numCPUs@plt>
test   %r13d,%r13d
js     1419 <main+0x259>
cmp    %eax,%r13d
jg     1419 <main+0x259>
mov    0x10(%rbx),%rdi
call   10b0 <atoi@plt>
test   %eax,%eax
jle    1438 <main+0x278>
cmp    $0x4,%ebp
jne    12cd <main+0x10d>
mov    0x18(%rbx),%rbx
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     136a <main+0x1aa>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     136a <main+0x1aa>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     136a <main+0x1aa>
lea    0xe11(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     136a <main+0x1aa>
mov    0x2d2c(%rip),%rax
movslq (%rax),%rdi
lea    0xdf4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    13d4 <main+0x214>
mov    %eax,%r12d
lea    0xdf1(%rip),%rdx
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %r13d,%ecx
call   1060 <snprintf@plt>
lea    0xe34(%rip),%rdx
mov    %r14,%rdi
mov    $0x3c,%esi
mov    %r13d,%ecx
call   1060 <snprintf@plt>
lea    0xdfa(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13b4 <main+0x1f4>
mov    %rax,%rbx
lea    0xe39(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdbe(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13b4 <main+0x1f4>
mov    %rax,%rbx
lea    0xe0b(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
jmp    13a6 <main+0x1e6>
lea    0xd57(%rip),%rdx
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %r13d,%ecx
call   1060 <snprintf@plt>
lea    0xd77(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13b4 <main+0x1f4>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <fputs@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x2c1e(%rip),%rbx
jmp    13db <main+0x21b>
mov    0x2c25(%rip),%rax
movslq (%rax),%rcx
lea    0xd3c(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    0x2bfd(%rip),%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bdd(%rip),%rax
movslq (%rax),%rdi
mov    (%rbx),%rdx
lea    0xbf0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1458 <main+0x298>
mov    0x2bc0(%rip),%rcx
movslq (%rcx),%rdi
lea    0xc09(%rip),%rsi
mov    %r13d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1458 <main+0x298>
mov    0x2ba1(%rip),%rax
movslq (%rax),%rcx
lea    0xc1a(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"Usage: %s <processorID> <frequency> [<governor>] \0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [48 x i8] c"CPU %d not a valid CPU ID. Range from 0 to %d.\0A\00"
@.str.2 = [35 x i8] c"Frequency must be greater than 0.\0A\00"
@.str.3 = [9 x i8] c"ondemand\00"
@.str.4 = [12 x i8] c"performance\00"
@.str.5 = [13 x i8] c"conservative\00"
@.str.6 = [10 x i8] c"powersave\00"
@.str.7 = [22 x i8] c"Invalid governor %s!\0A\00"
@.str.8 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [33 x i8] c"Unable to open path for writing\0A\00"
@.str.11 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
@.str.12 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_setspeed\00"
@.str.13 = [10 x i8] c"userspace\00"
@.str.14 = [3 x i8] c"%d\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 i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%14 = call i8* @malloc(i32 100)
store i8* %14, i8** %10
%15 = call i8* @malloc(i32 100)
store i8* %15, i8** %11
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 4
br i1 %20, label %21, label %35
21: ; preds = %18, %2
%22 = load i32, i32* @stderr
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %10
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %11
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %18
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %6
%40 = call i32 (...) @get_numCPUs()
store i32 %40, i32* %8
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %35
%44 = load i32, i32* %6
%45 = load i32, i32* %8
%46 = icmp sgt i32 %44, %45
br i1 %46, label %47, label %60
47: ; preds = %43, %35
%48 = load i32, i32* @stderr
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i32*
%51 = load i32, i32* %6
%52 = load i32, i32* %8
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %51, i32 %52)
%54 = load i8*, i8** %10
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %11
%57 = call i32 @free(i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %43
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = call i32 @atoi(i8* %63)
store i32 %64, i32* %7
%65 = load i32, i32* %7
%66 = icmp sle i32 %65, 0
br i1 %66, label %67, label %78
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = sext i32 %68 to i64
%70 = inttoptr i64 %69 to i32*
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%72 = load i8*, i8** %10
%73 = call i32 @free(i8* %72)
%74 = load i8*, i8** %11
%75 = call i32 @free(i8* %74)
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %60
%79 = load i32, i32* %4
%80 = icmp eq i32 %79, 4
br i1 %80, label %81, label %140
81: ; preds = %78
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 3
%84 = load i8*, i8** %83
store i8* %84, i8** %9
%85 = load i8*, i8** %9
%86 = call i64 @strncmp(i8* %85, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %111
88: ; preds = %81
%89 = load i8*, i8** %9
%90 = call i64 @strncmp(i8* %89, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 11)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %111
92: ; preds = %88
%93 = load i8*, i8** %9
%94 = call i64 @strncmp(i8* %93, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %111
96: ; preds = %92
%97 = load i8*, i8** %9
%98 = call i64 @strncmp(i8* %97, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 9)
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %111
100: ; preds = %96
%101 = load i32, i32* @stderr
%102 = sext i32 %101 to i64
%103 = inttoptr i64 %102 to i32*
%104 = load i8*, i8** %9
%105 = call i32 (i32*, i8*, ...) @fprintf(i32* %103, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %104)
%106 = load i8*, i8** %10
%107 = call i32 @free(i8* %106)
%108 = load i8*, i8** %11
%109 = call i32 @free(i8* %108)
%110 = load i32, i32* @EXIT_FAILURE
store i32 %110, i32* %3
br label %191
111: ; preds = %96, %92, %88, %81
%112 = load i8*, i8** %10
%113 = load i32, i32* %6
%114 = call i32 @snprintf(i8* %112, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %113)
%115 = load i8*, i8** %10
%116 = call i32* @fopen(i8* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %116, i32** %12
%117 = load i32*, i32** %12
%118 = icmp eq i32* %117, null
br i1 %118, label %119, label %129
119: ; preds = %111
%120 = load i32, i32* @stderr
%121 = sext i32 %120 to i64
%122 = inttoptr i64 %121 to i32*
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %122, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%124 = load i8*, i8** %10
%125 = call i32 @free(i8* %124)
%126 = load i8*, i8** %11
%127 = call i32 @free(i8* %126)
%128 = load i32, i32* @EXIT_FAILURE
store i32 %128, i32* %3
br label %191
129: ; preds = %111
%130 = load i32*, i32** %12
%131 = load i8*, i8** %9
%132 = call i32 (i32*, i8*, ...) @fprintf(i32* %130, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %131)
%133 = load i32*, i32** %12
%134 = call i32 @fclose(i32* %133)
%135 = load i8*, i8** %10
%136 = call i32 @free(i8* %135)
%137 = load i8*, i8** %11
%138 = call i32 @free(i8* %137)
%139 = load i32, i32* @EXIT_SUCCESS
store i32 %139, i32* %3
br label %191
140: ; preds = %78
%141 = load i8*, i8** %10
%142 = load i32, i32* %6
%143 = call i32 @snprintf(i8* %141, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %142)
%144 = load i8*, i8** %11
%145 = load i32, i32* %6
%146 = call i32 @snprintf(i8* %144, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.12, i64 0, i64 0), i32 %145)
%147 = load i8*, i8** %10
%148 = call i32* @fopen(i8* %147, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %148, i32** %13
%149 = load i32*, i32** %13
%150 = icmp eq i32* %149, null
br i1 %150, label %151, label %161
151: ; preds = %140
%152 = load i32, i32* @stderr
%153 = sext i32 %152 to i64
%154 = inttoptr i64 %153 to i32*
%155 = call i32 (i32*, i8*, ...) @fprintf(i32* %154, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%156 = load i8*, i8** %10
%157 = call i32 @free(i8* %156)
%158 = load i8*, i8** %11
%159 = call i32 @free(i8* %158)
%160 = load i32, i32* @EXIT_FAILURE
store i32 %160, i32* %3
br label %191
161: ; preds = %140
%162 = load i32*, i32** %13
%163 = call i32 (i32*, i8*, ...) @fprintf(i32* %162, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0))
%164 = load i32*, i32** %13
%165 = call i32 @fclose(i32* %164)
%166 = load i8*, i8** %11
%167 = call i32* @fopen(i8* %166, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %167, i32** %13
%168 = load i32*, i32** %13
%169 = icmp eq i32* %168, null
br i1 %169, label %170, label %180
170: ; preds = %161
%171 = load i32, i32* @stderr
%172 = sext i32 %171 to i64
%173 = inttoptr i64 %172 to i32*
%174 = call i32 (i32*, i8*, ...) @fprintf(i32* %173, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%175 = load i8*, i8** %10
%176 = call i32 @free(i8* %175)
%177 = load i8*, i8** %11
%178 = call i32 @free(i8* %177)
%179 = load i32, i32* @EXIT_FAILURE
store i32 %179, i32* %3
br label %191
180: ; preds = %161
%181 = load i32*, i32** %13
%182 = load i32, i32* %7
%183 = call i32 (i32*, i8*, ...) @fprintf(i32* %181, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 %182)
%184 = load i32*, i32** %13
%185 = call i32 @fclose(i32* %184)
%186 = load i8*, i8** %10
%187 = call i32 @free(i8* %186)
%188 = load i8*, i8** %11
%189 = call i32 @free(i8* %188)
%190 = load i32, i32* @EXIT_SUCCESS
store i32 %190, i32* %3
br label %191
191: ; preds = %180, %170, %151, %129, %119, %100
%192 = load i32, i32* %3
ret i32 %192
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"Usage: %s <processorID> <frequency> [<governor>] \0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [48 x i8] c"CPU %d not a valid CPU ID. Range from 0 to %d.\0A\00"
@.str.2 = [35 x i8] c"Frequency must be greater than 0.\0A\00"
@.str.3 = [9 x i8] c"ondemand\00"
@.str.4 = [12 x i8] c"performance\00"
@.str.5 = [13 x i8] c"conservative\00"
@.str.6 = [10 x i8] c"powersave\00"
@.str.7 = [22 x i8] c"Invalid governor %s!\0A\00"
@.str.8 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [33 x i8] c"Unable to open path for writing\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.12 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_setspeed\00"
@.str.13 = [10 x i8] c"userspace\00"
@.str.14 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%4 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i32*
%11 = load i8*, i8** %1
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @free(i8* %3)
%14 = tail call i32 @free(i8* %4)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32 (...) @get_numCPUs()
%22 = icmp slt i32 %20, 0
%23 = icmp sgt i32 %20, %21
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %25, label %34
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
%30 = tail call i32 @free(i8* %3)
%31 = tail call i32 @free(i8* %4)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %17
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i32 @atoi(i8* %36)
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %48
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i32*
%43 = tail call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i64 34, i64 1, i32* %42)
%44 = tail call i32 @free(i8* %3)
%45 = tail call i32 @free(i8* %4)
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %34
%49 = icmp eq i32 %0, 4
br i1 %49, label %50, label %81
50: ; preds = %48
%51 = getelementptr inbounds i8*, i8** %1, i64 3
%52 = load i8*, i8** %51
%53 = tail call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%54 = icmp eq i64 %53, 0
br i1 %54, label %69, label %55
55: ; preds = %50
%56 = tail call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 11)
%57 = icmp eq i64 %56, 0
br i1 %57, label %69, label %58
58: ; preds = %55
%59 = tail call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%60 = icmp eq i64 %59, 0
br i1 %60, label %69, label %61
61: ; preds = %58
%62 = tail call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 9)
%63 = icmp eq i64 %62, 0
br i1 %63, label %69, label %64
64: ; preds = %61
%65 = load i32, i32* @stderr
%66 = sext i32 %65 to i64
%67 = inttoptr i64 %66 to i32*
%68 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %52)
br label %104
69: ; preds = %61, %58, %55, %50
%70 = tail call i32 @snprintf(i8* %3, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %20)
%71 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %78
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = sext i32 %74 to i64
%76 = inttoptr i64 %75 to i32*
%77 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i64 32, i64 1, i32* %76)
br label %104
78: ; preds = %69
%79 = tail call i32 @fputs(i8* %52, i32* %71)
%80 = tail call i32 @fclose(i32* %71)
br label %104
81: ; preds = %48
%82 = tail call i32 @snprintf(i8* %3, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %20)
%83 = tail call i32 @snprintf(i8* %4, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.12, i64 0, i64 0), i32 %20)
%84 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = load i32, i32* @stderr
%88 = sext i32 %87 to i64
%89 = inttoptr i64 %88 to i32*
%90 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i64 32, i64 1, i32* %89)
br label %104
91: ; preds = %81
%92 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i64 9, i64 1, i32* %84)
%93 = tail call i32 @fclose(i32* %84)
%94 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%95 = icmp eq i32* %94, null
br i1 %95, label %96, label %101
96: ; preds = %91
%97 = load i32, i32* @stderr
%98 = sext i32 %97 to i64
%99 = inttoptr i64 %98 to i32*
%100 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i64 32, i64 1, i32* %99)
br label %104
101: ; preds = %91
%102 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 %37)
%103 = tail call i32 @fclose(i32* %94)
br label %104
104: ; preds = %86, %96, %101, %73, %78, %64
%105 = phi i32* [ @EXIT_FAILURE, %64 ], [ @EXIT_FAILURE, %73 ], [ @EXIT_SUCCESS, %78 ], [ @EXIT_FAILURE, %86 ], [ @EXIT_FAILURE, %96 ], [ @EXIT_SUCCESS, %101 ]
%106 = tail call i32 @free(i8* %3)
%107 = tail call i32 @free(i8* %4)
%108 = load i32, i32* %105
ret i32 %108
}