#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 O_CREAT;
int O_TRUNC;
int atoi(char *);
int /*<<< orphan*/ dprintf(int, char *, int, int, int, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(char **, int *, int /*<<< orphan*/ *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  int fd;
  int sound = 0;
  int vib = 0;
  int t, s, v;
  int count = 0;
  int super_count = 0;
  int temp_sum = 0;
  int temp_min = 100;
  int temp_max = 0;
  int sound_1 = 0;
  int vibs_1 = 0;
  fd = open("sleep_well", O_TRUNC | O_CREAT);
  FILE *file;
  file = fopen("/dev/cu.usbmodem1411", "r");
  char *line = NULL;
  int len = 0;
  int read;
  while (super_count < 25000000) {
    count = 0;
    sound_1 = 0;
    vibs_1 = 0;
    while (count < 850) {
      count++;
      read = getline(&line, &len, file);
      printf("%s", line);
      t = 10 * atoi(&line[0]) + atoi(&line[1]);
      s = atoi(&line[3]);
      v = atoi(&line[5]);
      s = (s - 0.5) * (-1) + 0.5;
      sound_1 += s;
      vibs_1 += v;
      temp_sum += t;
    }
    if (vibs_1 > 25)
      vib++;
    if (sound_1 > 50)
      sound++;
  }
  int temp_avg = temp_sum / 25000000;
  dprintf(fd, "%d,%d,%d,%d,%d\n", temp_max, temp_min, temp_avg, sound, vib);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x64,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    0x2e3a(%rip),%rax
or     (%rax),%esi
lea    0xe41(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe3d(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x17d7840,-0x24(%rbp)
jge    1306 <main+0x1a6>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x352,-0x20(%rbp)
jge    12db <main+0x17b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1070 <atoi@plt>
imul   $0xa,%eax,%eax
mov    %eax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x3,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x5,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xd5c(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd50(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1217 <main+0xb7>
cmpl   $0x19,-0x38(%rbp)
jle    12ee <main+0x18e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x32,-0x34(%rbp)
jle    1301 <main+0x1a1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f5 <main+0x95>
mov    -0x28(%rbp),%eax
mov    $0x17d7840,%ecx
cltd
idiv   %ecx
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x54(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    -0x10(%rbp),%eax
lea    0xcfe(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <dprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e9d(%rip),%rax
mov    0x2e9e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1040 <open@plt>
lea    0xe9a(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xe80(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x352,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x80>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [11 x i8] c"sleep_well\00"
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.1 = [21 x i8] c"/dev/cu.usbmodem1411\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [16 x i8] c"%d,%d,%d,%d,%d\0A\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
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 100, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
%20 = load i32, i32* @O_TRUNC
%21 = load i32, i32* @O_CREAT
%22 = or i32 %20, %21
%23 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %2
%24 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %15
store i8* null, i8** %16
store i32 0, i32* %17
br label %25
25: ; preds = %79, %0
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 25000000
br i1 %27, label %28, label %80
28: ; preds = %25
store i32 0, i32* %8
store i32 0, i32* %13
store i32 0, i32* %14
br label %29
29: ; preds = %32, %28
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 850
br i1 %31, label %32, label %67
32: ; preds = %29
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
%35 = load i32*, i32** %15
%36 = call i32 @getline(i8** %16, i32* %17, i32* %35)
store i32 %36, i32* %18
%37 = load i8*, i8** %16
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %16
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = call i32 @atoi(i8* %40)
%42 = mul nsw i32 10, %41
%43 = load i8*, i8** %16
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i32 @atoi(i8* %44)
%46 = add nsw i32 %42, %45
store i32 %46, i32* %5
%47 = load i8*, i8** %16
%48 = getelementptr inbounds i8, i8* %47, i64 3
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %6
%50 = load i8*, i8** %16
%51 = getelementptr inbounds i8, i8* %50, i64 5
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %7
%53 = load i32, i32* %6
%54 = sitofp i32 %53 to double
%55 = fsub double %54, 5.000000e-01
%56 = call double @llvm.fmuladd.f64(double %55, double -1.000000e+00, double 5.000000e-01)
%57 = fptosi double %56 to i32
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = load i32, i32* %13
%60 = add nsw i32 %59, %58
store i32 %60, i32* %13
%61 = load i32, i32* %7
%62 = load i32, i32* %14
%63 = add nsw i32 %62, %61
store i32 %63, i32* %14
%64 = load i32, i32* %5
%65 = load i32, i32* %10
%66 = add nsw i32 %65, %64
store i32 %66, i32* %10
br label %29
67: ; preds = %29
%68 = load i32, i32* %14
%69 = icmp sgt i32 %68, 25
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i32, i32* %4
%72 = add nsw i32 %71, 1
store i32 %72, i32* %4
br label %73
73: ; preds = %70, %67
%74 = load i32, i32* %13
%75 = icmp sgt i32 %74, 50
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32, i32* %3
%78 = add nsw i32 %77, 1
store i32 %78, i32* %3
br label %79
79: ; preds = %76, %73
br label %25
80: ; preds = %25
%81 = load i32, i32* %10
%82 = sdiv i32 %81, 25000000
store i32 %82, i32* %19
%83 = load i32, i32* %2
%84 = load i32, i32* %12
%85 = load i32, i32* %11
%86 = load i32, i32* %19
%87 = load i32, i32* %3
%88 = load i32, i32* %4
%89 = call i32 @dprintf(i32 %83, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %84, i32 %85, i32 %86, i32 %87, i32 %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"sleep_well\00"
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.1 = [21 x i8] c"/dev/cu.usbmodem1411\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i32
%3 = load i32, i32* @O_TRUNC
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%9 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %10
10: ; preds = %11, %0
br label %11
11: ; preds = %10, %11
%12 = phi i32 [ 0, %10 ], [ %13, %11 ]
%13 = add nuw nsw i32 %12, 1
%14 = call i32 @getline(i8** %1, i32* %2, i32* %7)
%15 = load i8*, i8** %1
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = icmp eq i32 %13, 850
br i1 %17, label %10, label %11
}