#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*/ time_t;
struct winsize {
  int ws_col;
};
struct tm {
  int dummy;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
double atof(char *);
scalar_t__ daemon(int /*<<< orphan*/, int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[], char *env[]) {
  pid_t pid = daemon(0, 1);
  if (pid) {
    fprintf(stderr, "Can't fork process: %s\n", strerror(errno));
    return (errno);
  }
  struct tm *currTime;
  struct winsize xy;
  char timeStr[21];
  char tempStr[8];
  const char *tempPath = "/sys/class/hwmon/hwmon0/temp1_input";
  float tempC = 0.0;
  float tempF = 0.0;
  int x = 0;
  int textColor = 36;
  int textStyle = 1;
  FILE *infoFile;
  time_t raw;
  while (1) {
    time(&raw);
    currTime = localtime(&raw);
    strftime(timeStr, 21, "%a %b %d, %X", currTime);
    infoFile = fopen(tempPath, "r");
    if (infoFile == NULL) {
      perror("Error opening temperature file:");
      return (errno);
    }
    if (fgets(tempStr, 6, infoFile) == NULL) {
      perror("Error retrieving temperature:");
      return (errno);
    }
    fclose(infoFile);
    tempC = atof(tempStr) / 1000.0;
    tempF = (tempC + 32.0) * (9.0 / 5.0);
    fprintf(stderr, "Error, could not retrieve terminal size.\n");
    return (EXIT_FAILURE);
    x = xy.ws_col - 21;
    printf("\033[?25l\0337\033[1;%dH\033[K\033[B\033[K", x);
    printf("\033[%d;%dm\033[1;%dH[%s]", textStyle, textColor, x, timeStr);
    printf("\033[B\033[%dD[%2.1fC] [%3.1fF]", 21 - (tempF >= 100.0 ? 2 : 3),
           tempC, tempF);
    printf("\033[0m\0338\033[?25h");
    fflush(stdout);
    usleep(5000);
  }
  return (EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1090 <daemon@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     122d <main+0x7d>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137b <main+0x1cb>
lea    0xdfc(%rip),%rax
mov    %rax,-0x60(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x64(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x24,-0x70(%rbp)
movl   $0x1,-0x74(%rbp)
lea    -0x84(%rbp),%rdi
call   1080 <time@plt>
lea    -0x84(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x15,%esi
lea    0xdc7(%rip),%rdx
call   10a0 <strftime@plt>
mov    -0x60(%rbp),%rdi
lea    0xdc4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jne    12ce <main+0x11e>
lea    0xdab(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137b <main+0x1cb>
lea    -0x58(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x6,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1307 <main+0x157>
lea    0xd92(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137b <main+0x1cb>
mov    -0x80(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x58(%rbp),%rdi
call   1040 <atof@plt>
movsd  0xcef(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x64(%rbp)
movss  -0x64(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xcc9(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xcb5(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x68(%rbp)
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %edi,%edi
mov    $0x1,%esi
call   1080 <daemon@plt>
test   %rax,%rax
je     11eb <main+0x4b>
mov    0x2e21(%rip),%rax
mov    (%rax),%ebx
mov    0x2e10(%rip),%r14
mov    (%r14),%edi
call   10c0 <strerror@plt>
lea    0xe29(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%eax
jmp    1273 <main+0xd3>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
lea    0xe35(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x15,%esi
mov    %rax,%rcx
call   1090 <strftime@plt>
lea    0xdf8(%rip),%rdi
lea    0xe22(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127b <main+0xdb>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x6,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1284 <main+0xe4>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdc9(%rip),%rdi
jmp    128b <main+0xeb>
lea    0xde0(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d41(%rip),%rax
jmp    1271 <main+0xd1>

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.winsize = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Can't fork process: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"/sys/class/hwmon/hwmon0/temp1_input\00"
@.str.2 = [13 x i8] c"%a %b %d, %X\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [32 x i8] c"Error opening temperature file:\00"
@.str.5 = [30 x i8] c"Error retrieving temperature:\00"
@.str.6 = [42 x i8] c"Error, could not retrieve terminal size.\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca %struct.tm*
%10 = alloca %struct.winsize
%11 = alloca [21 x i8]
%12 = alloca [8 x i8]
%13 = alloca i8*
%14 = alloca float
%15 = alloca float
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%21 = call i64 @daemon(i32 0, i32 1)
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @errno
store i32 %29, i32* %4
br label %67
30: ; preds = %3
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8** %13
store float 0.000000e+00, float* %14
store float 0.000000e+00, float* %15
store i32 0, i32* %16
store i32 36, i32* %17
store i32 1, i32* %18
br label %31
31: ; preds = %30
%32 = call i32 @time(i32* %20)
%33 = call %struct.tm* @localtime(i32* %20)
store %struct.tm* %33, %struct.tm** %9
%34 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%35 = load %struct.tm*, %struct.tm** %9
%36 = call i32 @strftime(i8* %34, i32 21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %35)
%37 = load i8*, i8** %13
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %19
%39 = load i32*, i32** %19
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %31
%42 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32, i32* @errno
store i32 %43, i32* %4
br label %67
44: ; preds = %31
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%46 = load i32*, i32** %19
%47 = call i32* @fgets(i8* %45, i32 6, i32* %46)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* @errno
store i32 %51, i32* %4
br label %67
52: ; preds = %44
%53 = load i32*, i32** %19
%54 = call i32 @fclose(i32* %53)
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%56 = call double @atof(i8* %55)
%57 = fdiv double %56, 1.000000e+03
%58 = fptrunc double %57 to float
store float %58, float* %14
%59 = load float, float* %14
%60 = fpext float %59 to double
%61 = fadd double %60, 3.200000e+01
%62 = fmul double %61, 1.800000e+00
%63 = fptrunc double %62 to float
store float %63, float* %15
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %4
br label %67
67: ; preds = %52, %49, %41, %24
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Can't fork process: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"/sys/class/hwmon/hwmon0/temp1_input\00"
@.str.2 = [13 x i8] c"%a %b %d, %X\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [32 x i8] c"Error opening temperature file:\00"
@.str.5 = [30 x i8] c"Error retrieving temperature:\00"
@.str.6 = [42 x i8] c"Error, could not retrieve terminal size.\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [21 x i8]
%5 = alloca [8 x i8]
%6 = alloca i32
%7 = tail call i64 @daemon(i32 0, i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @errno
br label %38
15: ; preds = %3
%16 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%18 = bitcast i32* %6 to i8*
%19 = call i32 @time(i32* %6)
%20 = call %struct.tm* @localtime(i32* %6)
%21 = call i32 @strftime(i8* %16, i32 21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %20)
%22 = call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %35
26: ; preds = %15
%27 = call i32* @fgets(i8* %17, i32 6, i32* %22)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %35
31: ; preds = %26
%32 = call i32 @fclose(i32* %22)
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %31, %29, %24
%36 = phi i32* [ @errno, %24 ], [ @errno, %29 ], [ @EXIT_FAILURE, %31 ]
%37 = load i32, i32* %36
br label %38
38: ; preds = %35, %9
%39 = phi i32 [ %14, %9 ], [ %37, %35 ]
ret i32 %39
}