#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int main() {
  int fansLevel = 10;
  int temp, safeTemp = 57, criticalTemp = 60, sleepTime = 120;
  FILE *tempInput;
  printf("----------------------------------------\n");
  printf("   Safe: %d, Critical: %d, Sleep: %d\n", safeTemp, criticalTemp,
         sleepTime);
  printf("----------------------------------------\n");
  while (1) {
    tempInput = fopen("/proc/acpi/ibm/thermal", "r");
    fscanf(tempInput, "temperatures:	%d", &temp);
    fclose(tempInput);
    if (temp >= criticalTemp && fansLevel == 10) {
      system("date '+.:: %H:%M:%S ::.'");
      printf("Temperature is %d, critical is %d\n", temp, criticalTemp);
      printf("Turning fans to full-speed!\n");
      printf("----------------------------------------\n");
      system("echo level full-speed > /proc/acpi/ibm/fan");
      fansLevel = 100;
    } else if (temp <= safeTemp && fansLevel == 100) {
      system("date '+.:: %H:%M:%S ::.'");
      printf("Temperature is %d, safe is %d\n", temp, safeTemp);
      printf("Turning fans to auto!\n");
      printf("----------------------------------------\n");
      system("echo level auto > /proc/acpi/ibm/fan");
      fansLevel = 10;
    }
    sleep(sleepTime);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0x39,-0x10(%rbp)
movl   $0x3c,-0x14(%rbp)
movl   $0x78,-0x18(%rbp)
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     125c <main+0xfc>
cmpl   $0xa,-0x8(%rbp)
jne    125c <main+0xfc>
lea    0xe6b(%rip),%rdi
call   1040 <system@plt>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe88(%rip),%rdi
call   1040 <system@plt>
movl   $0x64,-0x8(%rbp)
jmp    12c6 <main+0x166>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     12c1 <main+0x161>
cmpl   $0x64,-0x8(%rbp)
jne    12c1 <main+0x161>
lea    0xe01(%rip),%rdi
call   1040 <system@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7f(%rip),%rdi
call   1040 <system@plt>
movl   $0xa,-0x8(%rbp)
jmp    12c6 <main+0x166>
mov    -0x18(%rbp),%edi
call   1080 <sleep@plt>
jmp    11be <main+0x5e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xfab(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
mov    $0x39,%esi
mov    $0x3c,%edx
mov    $0x78,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0xa,%r15d
lea    0xe81(%rip),%r12
lea    0xe7c(%rip),%r13
lea    0x4(%rsp),%rbx
jmp    122a <main+0xba>
nopw   0x0(%rax,%rax,1)
lea    0xe79(%rip),%rdi
call   1050 <system@plt>
mov    0x4(%rsp),%esi
lea    0xe82(%rip),%rdi
mov    $0x3c,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x64,%r15d
lea    0xf11(%rip),%rdi
lea    0xe85(%rip),%r14
call   1030 <puts@plt>
lea    0xf1a(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <system@plt>
mov    $0x78,%edi
call   1090 <sleep@plt>
lea    0xdf5(%rip),%rdi
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1070 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%eax
cmp    $0x3c,%eax
jl     1265 <main+0xf5>
cmp    $0xa,%r15d
je     11d0 <main+0x60>
cmp    $0x39,%eax
jg     1220 <main+0xb0>
cmp    $0x64,%r15d
jne    1220 <main+0xb0>
lea    0xdd9(%rip),%rdi
call   1050 <system@plt>
mov    0x4(%rsp),%esi
lea    0xe30(%rip),%rdi
mov    $0x39,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%r15d
lea    0xe5b(%rip),%rdi
lea    0xe2f(%rip),%r14
jmp    1207 <main+0x97>

LLVM IR (-O0):
@.str = [42 x i8] c"----------------------------------------\0A\00"
@.str.1 = [38 x i8] c" Safe: %d, Critical: %d, Sleep: %d\0A\00"
@.str.2 = [23 x i8] c"/proc/acpi/ibm/thermal\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [17 x i8] c"temperatures:\09%d\00"
@.str.5 = [25 x i8] c"date '+.:: %H:%M:%S ::.'\00"
@.str.6 = [35 x i8] c"Temperature is %d, critical is %d\0A\00"
@.str.7 = [29 x i8] c"Turning fans to full-speed!\0A\00"
@.str.8 = [43 x i8] c"echo level full-speed > /proc/acpi/ibm/fan\00"
@.str.9 = [31 x i8] c"Temperature is %d, safe is %d\0A\00"
@.str.10 = [23 x i8] c"Turning fans to auto!\0A\00"
@.str.11 = [37 x i8] c"echo level auto > /proc/acpi/ibm/fan\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
store i32 10, i32* %2
store i32 57, i32* %4
store i32 60, i32* %5
store i32 120, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %0, %50
%15 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%18 = load i32*, i32** %7
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %3
%21 = load i32, i32* %5
%22 = icmp sge i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %14
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* %3
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %28, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @system(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
store i32 100, i32* %2
br label %50
34: ; preds = %23, %14
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i32, i32* %2
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %43, i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @system(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
store i32 10, i32* %2
br label %49
49: ; preds = %41, %38, %34
br label %50
50: ; preds = %49, %26
%51 = load i32, i32* %6
%52 = call i32 @sleep(i32 %51)
br label %14
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c" Safe: %d, Critical: %d, Sleep: %d\0A\00"
@.str.2 = [23 x i8] c"/proc/acpi/ibm/thermal\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [17 x i8] c"temperatures:\09%d\00"
@.str.5 = [25 x i8] c"date '+.:: %H:%M:%S ::.'\00"
@.str.6 = [35 x i8] c"Temperature is %d, critical is %d\0A\00"
@.str.8 = [43 x i8] c"echo level full-speed > /proc/acpi/ibm/fan\00"
@.str.9 = [31 x i8] c"Temperature is %d, safe is %d\0A\00"
@.str.11 = [37 x i8] c"echo level auto > /proc/acpi/ibm/fan\00"
@str.13 = [22 x i8] c"Turning fans to auto!\00"
@str.15 = [28 x i8] c"Turning fans to full-speed!\00"
@str.16 = [41 x i8] c"----------------------------------------\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.16, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 57, i32 60, i32 120)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.16, i64 0, i64 0))
br label %6
6: ; preds = %35, %0
%7 = phi i32 [ 10, %0 ], [ %36, %35 ]
%8 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%10 = call i32 @fclose(i32* %8)
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 59
%13 = icmp eq i32 %7, 10
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %19
15: ; preds = %6
%16 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%17 = load i32, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %17, i32 60)
br label %27
19: ; preds = %6
%20 = icmp slt i32 %11, 58
%21 = icmp eq i32 %7, 100
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* %1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %25, i32 57)
br label %27
27: ; preds = %15, %23
%28 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.13, i64 0, i64 0), %23 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.15, i64 0, i64 0), %15 ]
%29 = phi i8* [ getelementptr inbounds ([41 x i8], [41 x i8]* @str.16, i64 0, i64 0), %23 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @str.16, i64 0, i64 0), %15 ]
%30 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), %23 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), %15 ]
%31 = phi i32 [ 10, %23 ], [ 100, %15 ]
%32 = call i32 @puts(i8* dereferenceable(1) %28)
%33 = call i32 @puts(i8* dereferenceable(1) %29)
%34 = call i32 @system(i8* %30)
br label %35
35: ; preds = %27, %19
%36 = phi i32 [ %7, %19 ], [ %31, %27 ]
%37 = call i32 @sleep(i32 120)
br label %6
}