#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*/ exit(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open_adc();
int /*<<< orphan*/ printf(char *, ...);
double read_adc_voltage(int, int /*<<< orphan*/);
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);
  if (open_adc() != 1) {
    exit(1);
  }
  struct timeval t1, t2;
  double elapsedTime;
  double samplearray[100000];
  printf("Starting speed test...");
  gettimeofday(&t1, NULL);
  int x;
  for (x = 0; x < 100000; x++) {
    samplearray[x] = read_adc_voltage(1, 0);
  }
  gettimeofday(&t2, NULL);
  double average = 0;
  double sum = 0;
  for (x = 0; x < 100000; x++) {
    sum += samplearray[x];
  }
  average = sum / 100000;
  elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
  elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
  double samplerate = (100000 / elapsedTime) * 1000;
  printf("%d samples in %G ms.\nThe sample rate was %G samples per second\nThe "
         "average voltage was %Gv",
         100000, elapsedTime, samplerate, average);
  (void)argc;
  (void)argv;
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc3560,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
mov    $0x0,%al
call   1080 <open_adc@plt>
cmp    $0x1,%eax
je     11b0 <main+0x50>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0xc3544(%rbp)
cmpl   $0x186a0,-0xc3544(%rbp)
jge    1215 <main+0xb5>
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <read_adc_voltage@plt>
movslq -0xc3544(%rbp),%rax
movsd  %xmm0,-0xc3540(%rbp,%rax,8)
f3 ff
mov    -0xc3544(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc3544(%rbp)
jmp    11d5 <main+0x75>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xc3550(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xc3558(%rbp)
ff
movl   $0x0,-0xc3544(%rbp)
cmpl   $0x186a0,-0xc3544(%rbp)
jge    1286 <main+0x126>
movslq -0xc3544(%rbp),%rax
movsd  -0xc3540(%rbp,%rax,8),%xmm0
f3 ff
addsd  -0xc3558(%rbp),%xmm0
ff
movsd  %xmm0,-0xc3558(%rbp)
ff
mov    -0xc3544(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc3544(%rbp)
jmp    1242 <main+0xe2>
movsd  -0xc3558(%rbp),%xmm0
ff
movsd  0xd72(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xc3550(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xd4c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xd31(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd23(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  0xd0e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xc3560(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
movsd  -0xc3560(%rbp),%xmm1
ff
movsd  -0xc3550(%rbp),%xmm2
ff
lea    0xd0d(%rip),%rdi
mov    $0x186a0,%esi
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc3560,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xc3520,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <setvbuf@plt>
xor    %eax,%eax
call   1080 <open_adc@plt>
cmp    $0x1,%eax
jne    1288 <main+0x128>
lea    0xe76(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
nop
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <read_adc_voltage@plt>
movsd  %xmm0,0x20(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x186a0,%rbx
jne    11b0 <main+0x50>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xorpd  %xmm2,%xmm2
mov    $0x7,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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    $0x186a7,%rax
jne    11f0 <main+0x90>
movsd  0xdcd(%rip),%xmm1
divsd  %xmm1,%xmm2
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm3
movsd  0xdb8(%rip),%xmm4
mulsd  %xmm4,%xmm3
subsd  0x18(%rsp),%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm3,%xmm0
divsd  %xmm0,%xmm1
mulsd  %xmm4,%xmm1
lea    0xdb6(%rip),%rdi
mov    $0x186a0,%esi
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xc3520,%rsp
pop    %rbx
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [23 x i8] c"Starting speed test...\00"
@.str.1 = [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 [100000 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 (...) @open_adc()
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 0, i32* %10
br label %24
24: ; preds = %32, %21
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 100000
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = call double @read_adc_voltage(i32 1, i32 0)
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100000 x double], [100000 x double]* %9, i64 0, i64 %30
store double %28, double* %31
br label %32
32: ; preds = %27
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
br label %24
35: ; preds = %24
%36 = 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 %37
37: ; preds = %47, %35
%38 = load i32, i32* %10
%39 = icmp slt i32 %38, 100000
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100000 x double], [100000 x double]* %9, i64 0, i64 %42
%44 = load double, double* %43
%45 = load double, double* %12
%46 = fadd double %45, %44
store double %46, double* %12
br label %47
47: ; preds = %40
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %37
50: ; preds = %37
%51 = load double, double* %12
%52 = fdiv double %51, 1.000000e+05
store double %52, double* %11
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%54 = load double, double* %53
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%56 = load double, double* %55
%57 = fsub double %54, %56
%58 = fmul double %57, 1.000000e+03
store double %58, double* %8
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%60 = load double, double* %59
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%62 = load double, double* %61
%63 = fsub double %60, %62
%64 = fdiv double %63, 1.000000e+03
%65 = load double, double* %8
%66 = fadd double %65, %64
store double %66, double* %8
%67 = load double, double* %8
%68 = fdiv double 1.000000e+05, %67
%69 = fmul double %68, 1.000000e+03
store double %69, double* %13
%70 = load double, double* %8
%71 = load double, double* %13
%72 = load double, double* %11
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0), i32 100000, double %70, double %71, double %72)
%74 = load i32, i32* %4
%75 = load i8**, i8*** %5
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [23 x i8] c"Starting speed test...\00"
@.str.1 = [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 [100000 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 = tail call i32 (...) @open_adc()
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = bitcast %struct.timeval* %3 to i8*
%15 = bitcast %struct.timeval* %4 to i8*
%16 = bitcast [100000 x double]* %5 to i8*
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %19
19: ; preds = %13, %19
%20 = phi i64 [ 0, %13 ], [ %23, %19 ]
%21 = tail call double @read_adc_voltage(i32 1, i32 0)
%22 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %20
store double %21, double* %22
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, 100000
br i1 %24, label %25, label %19
25: ; preds = %19
%26 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %61, %27 ]
%29 = phi double [ 0.000000e+00, %25 ], [ %60, %27 ]
%30 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %28
%31 = load double, double* %30
%32 = fadd double %29, %31
%33 = or i64 %28, 1
%34 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %33
%35 = load double, double* %34
%36 = fadd double %32, %35
%37 = or i64 %28, 2
%38 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %37
%39 = load double, double* %38
%40 = fadd double %36, %39
%41 = or i64 %28, 3
%42 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %41
%43 = load double, double* %42
%44 = fadd double %40, %43
%45 = or i64 %28, 4
%46 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %45
%47 = load double, double* %46
%48 = fadd double %44, %47
%49 = or i64 %28, 5
%50 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %49
%51 = load double, double* %50
%52 = fadd double %48, %51
%53 = or i64 %28, 6
%54 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %53
%55 = load double, double* %54
%56 = fadd double %52, %55
%57 = or i64 %28, 7
%58 = getelementptr inbounds [100000 x double], [100000 x double]* %5, i64 0, i64 %57
%59 = load double, double* %58
%60 = fadd double %56, %59
%61 = add nuw nsw i64 %28, 8
%62 = icmp eq i64 %61, 100000
br i1 %62, label %63, label %27
63: ; preds = %27
%64 = fdiv double %60, 1.000000e+05
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%66 = load double, double* %65
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%68 = load double, double* %67
%69 = fsub double %66, %68
%70 = fmul double %69, 1.000000e+03
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%72 = load double, double* %71
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%74 = load double, double* %73
%75 = fsub double %72, %74
%76 = fdiv double %75, 1.000000e+03
%77 = fadd double %70, %76
%78 = fdiv double 1.000000e+05, %77
%79 = fmul double %78, 1.000000e+03
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0), i32 100000, double %77, double %79, double %64)
ret i32 0
}