#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, double, double, double);
double read_voltage(int, int, int, int, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  struct timeval t1, t2;
  double elapsedTime;
  double samplearray[1000];
  gettimeofday(&t1, NULL);
  int x;
  for (x = 0; x < 1000; x++) {
    samplearray[x] = read_voltage(0x68, 1, 12, 1, 1);
  }
  gettimeofday(&t2, NULL);
  double average = 0;
  double sum = 0;
  for (x = 0; x < 1000; x++) {
    sum += samplearray[x];
  }
  average = sum / 1000;
  elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
  elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
  double samplerate = (1000 / elapsedTime) * 1000;
  printf("%d samples in %G ms.\nThe sample rate was %G samples per second\nThe "
         "average voltage was %Gv",
         1000, elapsedTime, samplerate, average);
  (void)argc;
  (void)argv;
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1fa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x1f84(%rbp)
cmpl   $0x3e8,-0x1f84(%rbp)
jge    11dc <main+0x9c>
mov    $0x68,%edi
mov    $0x1,%r8d
mov    $0xc,%edx
mov    %r8d,%esi
mov    %r8d,%ecx
call   1050 <read_voltage@plt>
movslq -0x1f84(%rbp),%rax
movsd  %xmm0,-0x1f80(%rbp,%rax,8)
ff ff
mov    -0x1f84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f84(%rbp)
jmp    118d <main+0x4d>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f90(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f98(%rbp)
ff
movl   $0x0,-0x1f84(%rbp)
cmpl   $0x3e8,-0x1f84(%rbp)
jge    124d <main+0x10d>
movslq -0x1f84(%rbp),%rax
movsd  -0x1f80(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x1f98(%rbp),%xmm0
ff
movsd  %xmm0,-0x1f98(%rbp)
ff
mov    -0x1f84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f84(%rbp)
jmp    1209 <main+0xc9>
movsd  -0x1f98(%rbp),%xmm0
ff
movsd  0xda3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f90(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xd85(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xd6a(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd54(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  0xd47(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x1fa0(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
movsd  -0x1fa0(%rbp),%xmm1
ff
movsd  -0x1f90(%rbp),%xmm2
ff
lea    0xd27(%rip),%rdi
mov    $0x3e8,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1fa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1f60,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x68,%edi
mov    $0x1,%esi
mov    $0xc,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1050 <read_voltage@plt>
movsd  %xmm0,0x20(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1180 <main+0x40>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xorpd  %xmm2,%xmm2
mov    $0x7,%eax
cs nopw 0x0(%rax,%rax,1)
nop
addsd  -0x18(%rsp,%rax,8),%xmm2
addsd  -0x10(%rsp,%rax,8),%xmm2
addsd  -0x8(%rsp,%rax,8),%xmm2
addsd  (%rsp,%rax,8),%xmm2
addsd  0x8(%rsp,%rax,8),%xmm2
addsd  0x10(%rsp,%rax,8),%xmm2
addsd  0x18(%rsp,%rax,8),%xmm2
addsd  0x20(%rsp,%rax,8),%xmm2
add    $0x8,%rax
cmp    $0x3ef,%rax
jne    11d0 <main+0x90>
movsd  0xded(%rip),%xmm3
divsd  %xmm3,%xmm2
movsd  (%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm3,%xmm1
subsd  0x18(%rsp),%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm1
lea    0xdbb(%rip),%rdi
mov    $0x3e8,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1f60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [91 x i8] c"%d samples in %G ms.\0AThe sample rate was %G samples per second\0AThe average voltage was %Gv\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca double
%9 = alloca [1000 x double]
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @stdout
%15 = load i32, i32* @_IONBF
%16 = call i32 @setvbuf(i32 %14, i32* null, i32 %15, i32 0)
%17 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 0, i32* %10
br label %18
18: ; preds = %26, %2
%19 = load i32, i32* %10
%20 = icmp slt i32 %19, 1000
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = call double @read_voltage(i32 104, i32 1, i32 12, i32 1, i32 1)
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000 x double], [1000 x double]* %9, i64 0, i64 %24
store double %22, double* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
store i32 %28, i32* %10
br label %18
29: ; preds = %18
%30 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store i32 0, i32* %10
br label %31
31: ; preds = %41, %29
%32 = load i32, i32* %10
%33 = icmp slt i32 %32, 1000
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1000 x double], [1000 x double]* %9, i64 0, i64 %36
%38 = load double, double* %37
%39 = load double, double* %12
%40 = fadd double %39, %38
store double %40, double* %12
br label %41
41: ; preds = %34
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %31
44: ; preds = %31
%45 = load double, double* %12
%46 = fdiv double %45, 1.000000e+03
store double %46, double* %11
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%48 = load double, double* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%50 = load double, double* %49
%51 = fsub double %48, %50
%52 = fmul double %51, 1.000000e+03
store double %52, double* %8
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%54 = load double, double* %53
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%56 = load double, double* %55
%57 = fsub double %54, %56
%58 = fdiv double %57, 1.000000e+03
%59 = load double, double* %8
%60 = fadd double %59, %58
store double %60, double* %8
%61 = load double, double* %8
%62 = fdiv double 1.000000e+03, %61
%63 = fmul double %62, 1.000000e+03
store double %63, double* %13
%64 = load double, double* %8
%65 = load double, double* %13
%66 = load double, double* %11
%67 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 1000, double %64, double %65, double %66)
%68 = load i32, i32* %4
%69 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [91 x i8] c"%d samples in %G ms.\0AThe sample rate was %G samples per second\0AThe average voltage was %Gv\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca [1000 x double]
%6 = load i32, i32* @stdout
%7 = load i32, i32* @_IONBF
%8 = tail call i32 @setvbuf(i32 %6, i32* null, i32 %7, i32 0)
%9 = bitcast %struct.timeval* %3 to i8*
%10 = bitcast %struct.timeval* %4 to i8*
%11 = bitcast [1000 x double]* %5 to i8*
%12 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %13
13: ; preds = %2, %13
%14 = phi i64 [ 0, %2 ], [ %17, %13 ]
%15 = tail call double @read_voltage(i32 104, i32 1, i32 12, i32 1, i32 1)
%16 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %14
store double %15, double* %16
%17 = add nuw nsw i64 %14, 1
%18 = icmp eq i64 %17, 1000
br i1 %18, label %19, label %13
19: ; preds = %13
%20 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %55, %21 ]
%23 = phi double [ 0.000000e+00, %19 ], [ %54, %21 ]
%24 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %22
%25 = load double, double* %24
%26 = fadd double %23, %25
%27 = or i64 %22, 1
%28 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %27
%29 = load double, double* %28
%30 = fadd double %26, %29
%31 = or i64 %22, 2
%32 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %31
%33 = load double, double* %32
%34 = fadd double %30, %33
%35 = or i64 %22, 3
%36 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %35
%37 = load double, double* %36
%38 = fadd double %34, %37
%39 = or i64 %22, 4
%40 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %39
%41 = load double, double* %40
%42 = fadd double %38, %41
%43 = or i64 %22, 5
%44 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %43
%45 = load double, double* %44
%46 = fadd double %42, %45
%47 = or i64 %22, 6
%48 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %47
%49 = load double, double* %48
%50 = fadd double %46, %49
%51 = or i64 %22, 7
%52 = getelementptr inbounds [1000 x double], [1000 x double]* %5, i64 0, i64 %51
%53 = load double, double* %52
%54 = fadd double %50, %53
%55 = add nuw nsw i64 %22, 8
%56 = icmp eq i64 %55, 1000
br i1 %56, label %57, label %21
57: ; preds = %21
%58 = fdiv double %54, 1.000000e+03
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%60 = load double, double* %59
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%62 = load double, double* %61
%63 = fsub double %60, %62
%64 = fmul double %63, 1.000000e+03
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%66 = load double, double* %65
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%68 = load double, double* %67
%69 = fsub double %66, %68
%70 = fdiv double %69, 1.000000e+03
%71 = fadd double %64, %70
%72 = fdiv double 1.000000e+03, %71
%73 = fmul double %72, 1.000000e+03
%74 = tail call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 1000, double %71, double %73, double %58)
ret i32 0
}