#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 tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct termios {
  int c_cflag;
};

/* Variables and functions */
int B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ close(int);
int get_humid(int);
int get_illum(int);
double get_rwatt(int);
double get_temp(int);
struct tm *localtime(int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double, int, int, ...);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int fd;
  struct termios oldtio, newtio;
  time_t timer;
  struct tm *now;
  double temp, rwatt;
  int humid, illum;
  if (argc < 2) {
    return 1;
  }
  if ((fd = open(argv[1], O_RDWR)) == 1) {
    return 1;
  }
  time(&timer);
  now = localtime(&timer);
  printf("%d/%02d/%02d ", 1900 + now->tm_year, now->tm_mon + 1, now->tm_mday);
  printf("%02d:%02d:%02d,", now->tm_hour, now->tm_min, now->tm_sec);
  tcgetattr(fd, &oldtio);
  newtio = oldtio;
  newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
  tcsetattr(fd, TCSANOW, &newtio);
  temp = get_temp(fd);
  humid = get_humid(fd);
  illum = get_illum(fd);
  rwatt = get_rwatt(fd);
  printf("%f,%d,%d,%f\n", temp, humid, illum, rwatt);
  tcsetattr(fd, TCSANOW, &oldtio);
  close(fd);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11dc <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1333 <main+0x183>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x1,%eax
jne    120a <main+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    1333 <main+0x183>
lea    -0x24(%rbp),%rdi
call   1080 <time@plt>
lea    -0x24(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
add    $0x76c,%eax
cvtsi2sd %eax,%xmm0
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
add    $0x1,%esi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xdb9(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rax
cvtsi2sdl 0xc(%rax),%xmm0
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%edx
lea    0xda2(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10a0 <tcgetattr@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    0x2d33(%rip),%rcx
or     (%rcx),%eax
mov    0x2d12(%rip),%rcx
or     (%rcx),%eax
mov    0x2d29(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   10b0 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
call   1030 <get_temp@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <get_humid@plt>
mov    %eax,-0x44(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <get_illum@plt>
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   10d0 <get_rwatt@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
movsd  -0x40(%rbp),%xmm1
lea    0xd16(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   10b0 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    $0x1,%ebp
cmp    $0x2,%edi
jl     12e7 <main+0x137>
mov    0x8(%rsi),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
cmp    $0x1,%eax
je     12e7 <main+0x137>
mov    %eax,%ebx
lea    0x1c(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <time@plt>
mov    %rbp,%rdi
call   1040 <localtime@plt>
mov    %rax,%rbp
mov    $0x76c,%eax
add    0x0(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    0x4(%rbp),%esi
mov    0x8(%rbp),%edx
add    $0x1,%esi
lea    0xde5(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rbp),%xmm0
mov    0x10(%rbp),%esi
mov    0x14(%rbp),%edx
lea    0xdd7(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0x18(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   10a0 <tcgetattr@plt>
mov    0x2d84(%rip),%rax
mov    0x2d6d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d4a(%rip),%rax
or     (%rax),%ecx
mov    0x2d61(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d64(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   10b0 <tcsetattr@plt>
mov    %ebx,%edi
call   1030 <get_temp@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   1090 <get_humid@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1050 <get_illum@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   10d0 <get_rwatt@plt>
movapd %xmm0,%xmm1
lea    0xd60(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    %r15d,%esi
mov    %ebp,%edx
mov    $0x2,%al
call   1060 <printf@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   10b0 <tcsetattr@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@O_RDWR = global i32 0
@.str = [14 x i8] c"%d/%02d/%02d \00"
@.str.1 = [16 x i8] c"%02d:%02d:%02d,\00"
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@TCSANOW = global i32 0
@.str.2 = [13 x i8] c"%f,%d,%d,%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.termios
%8 = alloca %struct.termios
%9 = alloca i32
%10 = alloca %struct.tm*
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 1, i32* %3
br label %86
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 1, i32* %3
br label %86
26: ; preds = %18
%27 = call i32 @time(i32* %9)
%28 = call %struct.tm* @localtime(i32* %9)
store %struct.tm* %28, %struct.tm** %10
%29 = load %struct.tm*, %struct.tm** %10
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = add nsw i32 1900, %31
%33 = sitofp i32 %32 to double
%34 = load %struct.tm*, %struct.tm** %10
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
%38 = load %struct.tm*, %struct.tm** %10
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 (i8*, double, i32, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %33, i32 %37, i32 %40)
%42 = load %struct.tm*, %struct.tm** %10
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 3
%44 = load i32, i32* %43
%45 = sitofp i32 %44 to double
%46 = load %struct.tm*, %struct.tm** %10
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 4
%48 = load i32, i32* %47
%49 = load %struct.tm*, %struct.tm** %10
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 5
%51 = load i32, i32* %50
%52 = call i32 (i8*, double, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %45, i32 %48, i32 %51)
%53 = load i32, i32* %6
%54 = call i32 @tcgetattr(i32 %53, %struct.termios* %7)
%55 = bitcast %struct.termios* %8 to i8*
%56 = bitcast %struct.termios* %7 to i8*
%57 = load i32, i32* @B9600
%58 = load i32, i32* @CS8
%59 = or i32 %57, %58
%60 = load i32, i32* @CLOCAL
%61 = or i32 %59, %60
%62 = load i32, i32* @CREAD
%63 = or i32 %61, %62
%64 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
store i32 %63, i32* %64
%65 = load i32, i32* %6
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 %65, i32 %66, %struct.termios* %8)
%68 = load i32, i32* %6
%69 = call double @get_temp(i32 %68)
store double %69, double* %11
%70 = load i32, i32* %6
%71 = call i32 @get_humid(i32 %70)
store i32 %71, i32* %13
%72 = load i32, i32* %6
%73 = call i32 @get_illum(i32 %72)
store i32 %73, i32* %14
%74 = load i32, i32* %6
%75 = call double @get_rwatt(i32 %74)
store double %75, double* %12
%76 = load double, double* %11
%77 = load i32, i32* %13
%78 = load i32, i32* %14
%79 = load double, double* %12
%80 = call i32 (i8*, double, i32, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %76, i32 %77, i32 %78, double %79)
%81 = load i32, i32* %6
%82 = load i32, i32* @TCSANOW
%83 = call i32 @tcsetattr(i32 %81, i32 %82, %struct.termios* %7)
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
store i32 0, i32* %3
br label %86
86: ; preds = %26, %25, %17
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@O_RDWR = global i32 0
@.str = [14 x i8] c"%d/%02d/%02d \00"
@.str.1 = [16 x i8] c"%02d:%02d:%02d,\00"
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@TCSANOW = global i32 0
@.str.2 = [13 x i8] c"%f,%d,%d,%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = alloca i32
%6 = bitcast %struct.termios* %3 to i8*
%7 = bitcast %struct.termios* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %56, label %10
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %56, label %16
16: ; preds = %10
%17 = call i32 @time(i32* %5)
%18 = call %struct.tm* @localtime(i32* %5)
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 0
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1900
%22 = sitofp i32 %21 to double
%23 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 2
%27 = load i32, i32* %26
%28 = call i32 (i8*, double, i32, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %22, i32 %25, i32 %27)
%29 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 3
%30 = load i32, i32* %29
%31 = sitofp i32 %30 to double
%32 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 4
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 5
%35 = load i32, i32* %34
%36 = call i32 (i8*, double, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %31, i32 %33, i32 %35)
%37 = call i32 @tcgetattr(i32 %14, %struct.termios* %3)
%38 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%39 = load i32, i32* @B9600
%40 = load i32, i32* @CS8
%41 = or i32 %40, %39
%42 = load i32, i32* @CLOCAL
%43 = or i32 %41, %42
%44 = load i32, i32* @CREAD
%45 = or i32 %43, %44
store i32 %45, i32* %38
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %14, i32 %46, %struct.termios* %4)
%48 = call double @get_temp(i32 %14)
%49 = call i32 @get_humid(i32 %14)
%50 = call i32 @get_illum(i32 %14)
%51 = call double @get_rwatt(i32 %14)
%52 = call i32 (i8*, double, i32, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %48, i32 %49, i32 %50, double %51)
%53 = load i32, i32* @TCSANOW
%54 = call i32 @tcsetattr(i32 %14, i32 %53, %struct.termios* %3)
%55 = call i32 @close(i32 %14)
br label %56
56: ; preds = %10, %2, %16
%57 = phi i32 [ 0, %16 ], [ 1, %2 ], [ 1, %10 ]
ret i32 %57
}