#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))) {
      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    1433 <main+0x293>
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     137f <main+0x1df>
mov    -0x28(%rbp),%rdi
lea    0xd63(%rip),%rsi
mov    $0xb,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     137f <main+0x1df>
mov    0x2c99(%rip),%rax
movslq (%rax),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd46(%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    0x2c63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    156e <main+0x3ce>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3c,%esi
lea    0xd1f(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd46(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    13f1 <main+0x251>
mov    0x2c23(%rip),%rax
movslq (%rax),%rdi
lea    0xd23(%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    0x2bf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    156e <main+0x3ce>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd0b(%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    0x2ba7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    156e <main+0x3ce>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3c,%esi
lea    0xc6b(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x3c,%esi
lea    0xcb0(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xc7a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    14bd <main+0x31d>
mov    0x2b57(%rip),%rax
movslq (%rax),%rdi
lea    0xc57(%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    0x2b25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    156e <main+0x3ce>
mov    -0x48(%rbp),%rdi
lea    0xc7d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
lea    0xc05(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1532 <main+0x392>
mov    0x2ae2(%rip),%rax
movslq (%rax),%rdi
lea    0xbe2(%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    0x2ab0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    156e <main+0x3ce>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xc0f(%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    0x2a67(%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    13be <main+0x1fe>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   10c0 <get_numCPUs@plt>
test   %r13d,%r13d
js     13db <main+0x21b>
cmp    %eax,%r13d
jg     13db <main+0x21b>
mov    0x10(%rbx),%rdi
call   10b0 <atoi@plt>
test   %eax,%eax
jle    13fa <main+0x23a>
cmp    $0x4,%ebp
jne    128f <main+0xcf>
mov    0x18(%rbx),%rbx
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     132c <main+0x16c>
lea    0xe36(%rip),%rsi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     132c <main+0x16c>
mov    0x2d6a(%rip),%rax
movslq (%rax),%rdi
lea    0xe1b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1396 <main+0x1d6>
mov    %eax,%r12d
lea    0xe18(%rip),%rdx
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %r13d,%ecx
call   1060 <snprintf@plt>
lea    0xe5b(%rip),%rdx
mov    %r14,%rdi
mov    $0x3c,%esi
mov    %r13d,%ecx
call   1060 <snprintf@plt>
lea    0xe21(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1376 <main+0x1b6>
mov    %rax,%rbx
lea    0xe60(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xde5(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1376 <main+0x1b6>
mov    %rax,%rbx
lea    0xe32(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
jmp    1368 <main+0x1a8>
lea    0xd7e(%rip),%rdx
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %r13d,%ecx
call   1060 <snprintf@plt>
lea    0xd9e(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1376 <main+0x1b6>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <fputs@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x2c5c(%rip),%rbx
jmp    139d <main+0x1dd>
mov    0x2c63(%rip),%rax
movslq (%rax),%rcx
lea    0xd63(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    0x2c3b(%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    0x2c1b(%rip),%rax
movslq (%rax),%rdi
mov    (%rbx),%rdx
lea    0xc2e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    141a <main+0x25a>
mov    0x2bfe(%rip),%rcx
movslq (%rcx),%rdi
lea    0xc47(%rip),%rsi
mov    %r13d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    141a <main+0x25a>
mov    0x2bdf(%rip),%rax
movslq (%rax),%rcx
lea    0xc58(%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    0x2ba7(%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 = [22 x i8] c"Invalid governor %s!\0A\00"
@.str.6 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [33 x i8] c"Unable to open path for writing\0A\00"
@.str.9 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
@.str.10 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_setspeed\00"
@.str.11 = [10 x i8] c"userspace\00"
@.str.12 = [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 %132
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 %103
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 %103
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = sext i32 %93 to i64
%95 = inttoptr i64 %94 to i32*
%96 = load i8*, i8** %9
%97 = call i32 (i32*, i8*, ...) @fprintf(i32* %95, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %96)
%98 = load i8*, i8** %10
%99 = call i32 @free(i8* %98)
%100 = load i8*, i8** %11
%101 = call i32 @free(i8* %100)
%102 = load i32, i32* @EXIT_FAILURE
store i32 %102, i32* %3
br label %183
103: ; preds = %88, %81
%104 = load i8*, i8** %10
%105 = load i32, i32* %6
%106 = call i32 @snprintf(i8* %104, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %105)
%107 = load i8*, i8** %10
%108 = call i32* @fopen(i8* %107, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %108, i32** %12
%109 = load i32*, i32** %12
%110 = icmp eq i32* %109, null
br i1 %110, label %111, label %121
111: ; preds = %103
%112 = load i32, i32* @stderr
%113 = sext i32 %112 to i64
%114 = inttoptr i64 %113 to i32*
%115 = call i32 (i32*, i8*, ...) @fprintf(i32* %114, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%116 = load i8*, i8** %10
%117 = call i32 @free(i8* %116)
%118 = load i8*, i8** %11
%119 = call i32 @free(i8* %118)
%120 = load i32, i32* @EXIT_FAILURE
store i32 %120, i32* %3
br label %183
121: ; preds = %103
%122 = load i32*, i32** %12
%123 = load i8*, i8** %9
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %122, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %123)
%125 = load i32*, i32** %12
%126 = call i32 @fclose(i32* %125)
%127 = load i8*, i8** %10
%128 = call i32 @free(i8* %127)
%129 = load i8*, i8** %11
%130 = call i32 @free(i8* %129)
%131 = load i32, i32* @EXIT_SUCCESS
store i32 %131, i32* %3
br label %183
132: ; preds = %78
%133 = load i8*, i8** %10
%134 = load i32, i32* %6
%135 = call i32 @snprintf(i8* %133, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %134)
%136 = load i8*, i8** %11
%137 = load i32, i32* %6
%138 = call i32 @snprintf(i8* %136, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.10, i64 0, i64 0), i32 %137)
%139 = load i8*, i8** %10
%140 = call i32* @fopen(i8* %139, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %140, i32** %13
%141 = load i32*, i32** %13
%142 = icmp eq i32* %141, null
br i1 %142, label %143, label %153
143: ; preds = %132
%144 = load i32, i32* @stderr
%145 = sext i32 %144 to i64
%146 = inttoptr i64 %145 to i32*
%147 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%148 = load i8*, i8** %10
%149 = call i32 @free(i8* %148)
%150 = load i8*, i8** %11
%151 = call i32 @free(i8* %150)
%152 = load i32, i32* @EXIT_FAILURE
store i32 %152, i32* %3
br label %183
153: ; preds = %132
%154 = load i32*, i32** %13
%155 = call i32 (i32*, i8*, ...) @fprintf(i32* %154, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%156 = load i32*, i32** %13
%157 = call i32 @fclose(i32* %156)
%158 = load i8*, i8** %11
%159 = call i32* @fopen(i8* %158, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %159, i32** %13
%160 = load i32*, i32** %13
%161 = icmp eq i32* %160, null
br i1 %161, label %162, label %172
162: ; preds = %153
%163 = load i32, i32* @stderr
%164 = sext i32 %163 to i64
%165 = inttoptr i64 %164 to i32*
%166 = call i32 (i32*, i8*, ...) @fprintf(i32* %165, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%167 = load i8*, i8** %10
%168 = call i32 @free(i8* %167)
%169 = load i8*, i8** %11
%170 = call i32 @free(i8* %169)
%171 = load i32, i32* @EXIT_FAILURE
store i32 %171, i32* %3
br label %183
172: ; preds = %153
%173 = load i32*, i32** %13
%174 = load i32, i32* %7
%175 = call i32 (i32*, i8*, ...) @fprintf(i32* %173, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %174)
%176 = load i32*, i32** %13
%177 = call i32 @fclose(i32* %176)
%178 = load i8*, i8** %10
%179 = call i32 @free(i8* %178)
%180 = load i8*, i8** %11
%181 = call i32 @free(i8* %180)
%182 = load i32, i32* @EXIT_SUCCESS
store i32 %182, i32* %3
br label %183
183: ; preds = %172, %162, %143, %121, %111, %92
%184 = load i32, i32* %3
ret i32 %184
}

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 = [22 x i8] c"Invalid governor %s!\0A\00"
@.str.6 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [33 x i8] c"Unable to open path for writing\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.10 = [55 x i8] c"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_setspeed\00"
@.str.11 = [10 x i8] c"userspace\00"
@.str.12 = [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 %75
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 %63, 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 %63, label %58
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = sext i32 %59 to i64
%61 = inttoptr i64 %60 to i32*
%62 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %52)
br label %98
63: ; preds = %55, %50
%64 = tail call i32 @snprintf(i8* %3, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%65 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%66 = icmp eq i32* %65, null
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = sext i32 %68 to i64
%70 = inttoptr i64 %69 to i32*
%71 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 32, i64 1, i32* %70)
br label %98
72: ; preds = %63
%73 = tail call i32 @fputs(i8* %52, i32* %65)
%74 = tail call i32 @fclose(i32* %65)
br label %98
75: ; preds = %48
%76 = tail call i32 @snprintf(i8* %3, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%77 = tail call i32 @snprintf(i8* %4, i32 60, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.10, i64 0, i64 0), i32 %20)
%78 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%79 = icmp eq i32* %78, null
br i1 %79, label %80, label %85
80: ; preds = %75
%81 = load i32, i32* @stderr
%82 = sext i32 %81 to i64
%83 = inttoptr i64 %82 to i32*
%84 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 32, i64 1, i32* %83)
br label %98
85: ; preds = %75
%86 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i64 9, i64 1, i32* %78)
%87 = tail call i32 @fclose(i32* %78)
%88 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %95
90: ; preds = %85
%91 = load i32, i32* @stderr
%92 = sext i32 %91 to i64
%93 = inttoptr i64 %92 to i32*
%94 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i64 32, i64 1, i32* %93)
br label %98
95: ; preds = %85
%96 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 %37)
%97 = tail call i32 @fclose(i32* %88)
br label %98
98: ; preds = %80, %90, %95, %67, %72, %58
%99 = phi i32* [ @EXIT_FAILURE, %58 ], [ @EXIT_FAILURE, %67 ], [ @EXIT_SUCCESS, %72 ], [ @EXIT_FAILURE, %80 ], [ @EXIT_FAILURE, %90 ], [ @EXIT_SUCCESS, %95 ]
%100 = tail call i32 @free(i8* %3)
%101 = tail call i32 @free(i8* %4)
%102 = load i32, i32* %99
ret i32 %102
}