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

/* Variables and functions */
int /*<<< orphan*/ fan_off();
int /*<<< orphan*/ fan_on();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
float get_temp();
int getdelim(char **, size_t *, char, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
float strtof(char *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp;
  fp = fopen("/etc/fanadmin", "r");
  if (fp != NULL) {
    puts("/etc/fanadmin set, aborting\n");
    fclose(fp);
    return 0;
  }
  fp = fopen("/etc/goodtemp", "r");
  if (fp == NULL) {
    puts("Couldn't open /etc/goodtemp\n");
    return 1;
  }
  char *buf;
  size_t len;
  ssize_t ret = getdelim(&buf, &len, '\0', fp);
  fclose(fp);
  if (ret == -1) {
    puts("Couldn't read /etc/goodtemp\n");
    return 1;
  }
  float good_temp = strtof(buf, NULL);
  float cur_temp = get_temp();
  if (cur_temp > good_temp) {
    fan_on();
  } else {
    fan_off();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d9 <main+0x59>
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    129b <main+0x11b>
lea    0xe4d(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1213 <main+0x93>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    129b <main+0x11b>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   10a0 <getdelim@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1254 <main+0xd4>
lea    0xe15(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    129b <main+0x11b>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <strtof@plt>
movss  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <get_temp@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
ucomiss -0x30(%rbp),%xmm0
jbe    128d <main+0x10d>
mov    $0x0,%al
call   1050 <fan_on@plt>
jmp    1294 <main+0x114>
mov    $0x0,%al
call   1080 <fan_off@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe73(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11bc <main+0x3c>
mov    %rax,%rbx
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %ebx,%ebx
jmp    124a <main+0xca>
lea    0xe6a(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1227 <main+0xa7>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
mov    %rax,%rcx
call   10a0 <getdelim@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
cmp    $0xffffffff,%ebp
je     1230 <main+0xb0>
mov    0x8(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1070 <strtof@plt>
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1030 <get_temp@plt>
ucomiss 0x4(%rsp),%xmm0
jbe    1243 <main+0xc3>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fan_on@plt>
jmp    124a <main+0xca>
lea    0xe0d(%rip),%rdi
jmp    1237 <main+0xb7>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    124a <main+0xca>
xor    %eax,%eax
call   1080 <fan_off@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/etc/fanadmin\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"/etc/fanadmin set, aborting\0A\00"
@.str.3 = [14 x i8] c"/etc/goodtemp\00"
@.str.4 = [29 x i8] c"Couldn't open /etc/goodtemp\0A\00"
@.str.5 = [29 x i8] c"Couldn't read /etc/goodtemp\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca float
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32*, i32** %6
%18 = call i32 @fclose(i32* %17)
store i32 0, i32* %3
br label %46
19: ; preds = %2
%20 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %46
25: ; preds = %19
%26 = load i32*, i32** %6
%27 = call i32 @getdelim(i8** %7, i64* %8, i8 signext 0, i32* %26)
store i32 %27, i32* %9
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %46
34: ; preds = %25
%35 = load i8*, i8** %7
%36 = call float @strtof(i8* %35, i32* null)
store float %36, float* %10
%37 = call float (...) @get_temp()
store float %37, float* %11
%38 = load float, float* %11
%39 = load float, float* %10
%40 = fcmp ogt float %38, %39
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 (...) @fan_on()
br label %45
43: ; preds = %34
%44 = call i32 (...) @fan_off()
br label %45
45: ; preds = %43, %41
store i32 0, i32* %3
br label %46
46: ; preds = %45, %32, %23, %15
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"/etc/fanadmin\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"/etc/fanadmin set, aborting\0A\00"
@.str.3 = [14 x i8] c"/etc/goodtemp\00"
@.str.4 = [29 x i8] c"Couldn't open /etc/goodtemp\0A\00"
@.str.5 = [29 x i8] c"Couldn't read /etc/goodtemp\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @fclose(i32* %5)
br label %34
10: ; preds = %2
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %34
15: ; preds = %10
%16 = bitcast i8** %3 to i8*
%17 = bitcast i64* %4 to i8*
%18 = call i32 @getdelim(i8** %3, i64* %4, i8 signext 0, i32* %11)
%19 = call i32 @fclose(i32* %11)
%20 = icmp eq i32 %18, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %32
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = call float @strtof(i8* nocapture %24, i32* null)
%26 = call float (...) @get_temp()
%27 = fcmp ogt float %26, %25
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 (...) @fan_on()
br label %32
30: ; preds = %23
%31 = call i32 (...) @fan_off()
br label %32
32: ; preds = %28, %30, %21
%33 = phi i32 [ 1, %21 ], [ 0, %30 ], [ 0, %28 ]
br label %34
34: ; preds = %32, %13, %7
%35 = phi i32 [ 0, %7 ], [ 1, %13 ], [ %33, %32 ]
ret i32 %35
}