#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 atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  FILE *pp;
  char cmd[] = "cat /sys/devices/virtual/thermal/thermal_zone0/temp";
  int in = 0;
  float temp;
  float prev = -99.9;
  int count = 0;
  char s[8];
  printf("Practice 08\n");
  do {
    pp = popen(cmd, "r");
    if (pp == NULL) {
      printf("ERROR\n");
      return -1;
    }
    fgets(s, 8, pp);
    in = atoi(s);
    temp = (float)in / 1000.;
    printf("Temp=%.1f[C]\n", temp);
    pclose(pp);
    if (temp < prev) {
      count++;
    } else {
      count = 0;
    }
    prev = temp;
    system("sleep 1");
  } while (count < 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x34,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x54(%rbp)
movss  0xe5d(%rip),%xmm0
movss  %xmm0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f6 <main+0x86>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <main+0x131>
lea    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x8,%esi
call   1060 <fgets@plt>
lea    -0x68(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x54(%rbp)
cvtsi2ssl -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde3(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x58(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe18(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
movss  -0x58(%rbp),%xmm1
movss  -0x5c(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1273 <main+0x103>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    127a <main+0x10a>
movl   $0x0,-0x60(%rbp)
movss  -0x58(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
lea    0xddd(%rip),%rdi
call   1030 <system@plt>
cmpl   $0x2,-0x60(%rbp)
jl     11bd <main+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movaps 0xeab(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe73(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x706d65,0x40(%rsp)
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
movss  0xe3f(%rip),%xmm0
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%rbx
lea    0xe74(%rip),%r12
lea    0xe7b(%rip),%r13
nopl   0x0(%rax)
movss  %xmm0,0x4(%rsp)
mov    %r15,%rdi
lea    0xe54(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
je     126c <main+0xfc>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xde0(%rip),%xmm0
movss  %xmm0,(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1060 <pclose@plt>
add    $0x1,%r14d
xor    %ebp,%ebp
movss  0x4(%rsp),%xmm0
ucomiss (%rsp),%xmm0
cmovbe %ebp,%r14d
mov    %r13,%rdi
call   1040 <system@plt>
movss  (%rsp),%xmm0
cmp    $0x2,%r14d
jl     11e0 <main+0x70>
jmp    127d <main+0x10d>
lea    0xdf5(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.cmd = [52 x i8] c"cat /sys/devices/virtual/thermal/thermal_zone0/temp\00"
@.str = [13 x i8] c"Practice 08\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"ERROR\0A\00"
@.str.3 = [14 x i8] c"Temp=%.1f[C]\0A\00"
@.str.4 = [8 x i8] c"sleep 1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [52 x i8]
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca [8 x i8]
store i32 0, i32* %1
%9 = bitcast [52 x i8]* %3 to i8*
store i32 0, i32* %4
store float 0xC058F999A0000000, float* %6
store i32 0, i32* %7
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %44, %0
%12 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%13 = call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %48
18: ; preds = %11
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %2
%21 = call i32 @fgets(i8* %19, i32 8, i32* %20)
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = sitofp i32 %24 to float
%26 = fpext float %25 to double
%27 = fdiv double %26, 1.000000e+03
%28 = fptrunc double %27 to float
store float %28, float* %5
%29 = load float, float* %5
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %30)
%32 = load i32*, i32** %2
%33 = call i32 @pclose(i32* %32)
%34 = load float, float* %5
%35 = load float, float* %6
%36 = fcmp olt float %34, %35
br i1 %36, label %37, label %40
37: ; preds = %18
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %41
40: ; preds = %18
store i32 0, i32* %7
br label %41
41: ; preds = %40, %37
%42 = load float, float* %5
store float %42, float* %6
%43 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %41
%45 = load i32, i32* %7
%46 = icmp slt i32 %45, 2
br i1 %46, label %11, label %47
47: ; preds = %44
store i32 0, i32* %1
br label %48
48: ; preds = %47, %16
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@__const.main.cmd = [52 x i8] c"cat /sys/devices/virtual/thermal/thermal_zone0/temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [14 x i8] c"Temp=%.1f[C]\0A\00"
@.str.4 = [8 x i8] c"sleep 1\00"
@str = [12 x i8] c"Practice 08\00"
@str.5 = [6 x i8] c"ERROR\00"
define i32 @main() {
%1 = alloca [52 x i8]
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %13, %0
%7 = phi float [ 0xC058F999A0000000, %0 ], [ %17, %13 ]
%8 = phi i32 [ 0, %0 ], [ %23, %13 ]
%9 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.5, i64 0, i64 0))
br label %26
13: ; preds = %6
%14 = call i32 @fgets(i8* %4, i32 8, i32* %9)
%15 = call i32 @atoi(i8* %4)
%16 = sitofp i32 %15 to float
%17 = fdiv float %16, 1.000000e+03
%18 = fpext float %17 to double
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %18)
%20 = call i32 @pclose(i32* %9)
%21 = fcmp olt float %17, %7
%22 = add nsw i32 %8, 1
%23 = select i1 %21, i32 %22, i32 0
%24 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp slt i32 %23, 2
br i1 %25, label %6, label %26
26: ; preds = %13, %11
%27 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %27
}