#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 */

/* Variables and functions */
int BUFSIZ;
int convert_time_to_seconds(char *);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ jgraph_header(int, int);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, double *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char input[BUFSIZ];
  char *result;
  char time_string[BUFSIZ];
  double watts;
  int start_seconds = 0;
  int seconds = 0;
  int total_seconds;
  int last_seconds = 0;
  double average_watts = 0.0;
  double total_energy = 0.0;
  jgraph_header(490, 8);
  while (1) {
    result = fgets(input, BUFSIZ, stdin);
    if (result == NULL)
      break;
    sscanf(input, "%s %lf", time_string, &watts);
    seconds = convert_time_to_seconds(time_string);
    if (start_seconds == 0)
      start_seconds = seconds;
    printf("%d %lf\n", seconds - start_seconds, watts);
    if (last_seconds != 0)
      total_energy += watts * (double)(seconds - last_seconds);
    last_seconds = seconds;
  }
  total_seconds = seconds - start_seconds;
  average_watts = total_energy / (double)total_seconds;
  printf("(* Total time = %ds      *)\n", total_seconds);
  printf("(* Average Watts = %.3fW *)\n", average_watts);
  printf("(* Total energy = %.3fJ  *)\n", total_energy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    $0x1ea,%edi
mov    $0x8,%esi
call   1030 <jgraph_header@plt>
jmp    11e9 <main+0x99>
mov    -0x68(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1218 <main+0xc8>
jmp    129f <main+0x14f>
mov    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%rdi
lea    0xdd9(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1070 <sscanf@plt>
mov    -0x60(%rbp),%rdi
call   1060 <convert_time_to_seconds@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    124c <main+0xfc>
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xda5(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x48(%rbp)
je     1294 <main+0x144>
movsd  -0x38(%rbp),%xmm0
mov    -0x40(%rbp),%eax
sub    -0x48(%rbp),%eax
cvtsi2sd %eax,%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11e4 <main+0x94>
mov    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
movsd  -0x58(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm0
lea    0xd48(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x50(%rbp),%xmm0
lea    0xd52(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x58(%rbp),%xmm0
lea    0xd5c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e70(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    $0x1ea,%edi
mov    $0x8,%esi
call   1030 <jgraph_header@plt>
mov    (%r15),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1050 <fgets@plt>
test   %rax,%rax
je     1272 <main+0x122>
xor    %r13d,%r13d
xorpd  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xor    %r12d,%r12d
jmp    11f2 <main+0xa2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1050 <fgets@plt>
mov    %r15d,%r13d
test   %rax,%rax
je     1266 <main+0x116>
mov    %r14,%rdi
lea    0xe04(%rip),%rsi
mov    %rbx,%rdx
lea    -0x40(%rbp),%rcx
call   1070 <sscanf@plt>
mov    %rbx,%rdi
call   1060 <convert_time_to_seconds@plt>
mov    %eax,%r15d
test   %r12d,%r12d
cmove  %eax,%r12d
sub    %r12d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xdd7(%rip),%rdi
movsd  %xmm0,-0x38(%rbp)
mov    $0x2,%al
call   1040 <printf@plt>
test   %r13d,%r13d
je     11d0 <main+0x80>
mov    %r15d,%eax
sub    %r13d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,-0x30(%rbp)
jmp    11d0 <main+0x80>
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
jmp    127a <main+0x12a>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm1,-0x30(%rbp)
divsd  %xmm0,%xmm1
movsd  %xmm1,-0x38(%rbp)
lea    0xd80(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd8f(%rip),%rdi
movsd  -0x38(%rbp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd99(%rip),%rdi
movsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stdin = global i32 0
@.str = [7 x i8] c"%s %lf\00"
@.str.1 = [8 x i8] c"%d %lf\0A\00"
@.str.2 = [29 x i8] c"(* Total time = %ds *)\0A\00"
@.str.3 = [29 x i8] c"(* Average Watts = %.3fW *)\0A\00"
@.str.4 = [29 x i8] c"(* Total energy = %.3fJ *)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* @BUFSIZ
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %6
%20 = alloca i8, i64 %18
store i64 %18, i64* %7
%21 = load i32, i32* @BUFSIZ
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %9
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %14
store double 0.000000e+00, double* %15
store double 0.000000e+00, double* %16
%24 = call i32 @jgraph_header(i32 490, i32 8)
br label %25
25: ; preds = %57, %2
br label %26
26: ; preds = %25
%27 = load i32, i32* @BUFSIZ
%28 = load i32, i32* @stdin
%29 = call i8* @fgets(i8* %20, i32 %27, i32 %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %26
br label %59
33: ; preds = %26
%34 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %23, double* %10)
%35 = call i32 @convert_time_to_seconds(i8* %23)
store i32 %35, i32* %12
%36 = load i32, i32* %11
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i32, i32* %12
store i32 %39, i32* %11
br label %40
40: ; preds = %38, %33
%41 = load i32, i32* %12
%42 = load i32, i32* %11
%43 = sub nsw i32 %41, %42
%44 = sitofp i32 %43 to double
%45 = load double, double* %10
%46 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %44, double %45)
%47 = load i32, i32* %14
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %40
%50 = load double, double* %10
%51 = load i32, i32* %12
%52 = load i32, i32* %14
%53 = sub nsw i32 %51, %52
%54 = sitofp i32 %53 to double
%55 = load double, double* %16
%56 = call double @llvm.fmuladd.f64(double %50, double %54, double %55)
store double %56, double* %16
br label %57
57: ; preds = %49, %40
%58 = load i32, i32* %12
store i32 %58, i32* %14
br label %25
59: ; preds = %32
%60 = load i32, i32* %12
%61 = load i32, i32* %11
%62 = sub nsw i32 %60, %61
store i32 %62, i32* %13
%63 = load double, double* %16
%64 = load i32, i32* %13
%65 = sitofp i32 %64 to double
%66 = fdiv double %63, %65
store double %66, double* %15
%67 = load i32, i32* %13
%68 = sitofp i32 %67 to double
%69 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %68)
%70 = load double, double* %15
%71 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), double %70)
%72 = load double, double* %16
%73 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), double %72)
store i32 0, i32* %3
%74 = load i8*, i8** %6
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stdin = global i32 0
@.str = [7 x i8] c"%s %lf\00"
@.str.1 = [8 x i8] c"%d %lf\0A\00"
@.str.2 = [29 x i8] c"(* Total time = %ds *)\0A\00"
@.str.3 = [29 x i8] c"(* Average Watts = %.3fW *)\0A\00"
@.str.4 = [29 x i8] c"(* Total energy = %.3fJ *)\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = bitcast double* %3 to i8*
%9 = tail call i32 @jgraph_header(i32 490, i32 8)
%10 = load i32, i32* @BUFSIZ
%11 = load i32, i32* @stdin
%12 = call i8* @fgets(i8* %6, i32 %10, i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %41, label %14
14: ; preds = %2, %32
%15 = phi double [ %33, %32 ], [ 0.000000e+00, %2 ]
%16 = phi i32 [ %19, %32 ], [ 0, %2 ]
%17 = phi i32 [ %21, %32 ], [ 0, %2 ]
%18 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %7, double* %3)
%19 = call i32 @convert_time_to_seconds(i8* %7)
%20 = icmp eq i32 %17, 0
%21 = select i1 %20, i32 %19, i32 %17
%22 = sub nsw i32 %19, %21
%23 = sitofp i32 %22 to double
%24 = load double, double* %3
%25 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %23, double %24)
%26 = icmp eq i32 %16, 0
br i1 %26, label %32, label %27
27: ; preds = %14
%28 = load double, double* %3
%29 = sub nsw i32 %19, %16
%30 = sitofp i32 %29 to double
%31 = call double @llvm.fmuladd.f64(double %28, double %30, double %15)
br label %32
32: ; preds = %27, %14
%33 = phi double [ %31, %27 ], [ %15, %14 ]
%34 = load i32, i32* @BUFSIZ
%35 = load i32, i32* @stdin
%36 = call i8* @fgets(i8* %6, i32 %34, i32 %35)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %14
38: ; preds = %32
%39 = sub nsw i32 %19, %21
%40 = sitofp i32 %39 to double
br label %41
41: ; preds = %2, %38
%42 = phi double [ %33, %38 ], [ 0.000000e+00, %2 ]
%43 = phi double [ %40, %38 ], [ 0.000000e+00, %2 ]
%44 = fdiv double %42, %43
%45 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %43)
%46 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), double %44)
%47 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), double %42)
ret i32 0
}