#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*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double foo(void *inPtr, unsigned int n) {
  struct timeval tvBeginLoop, tvEndLoop;
  double loopTime;
  int *a = (int *)inPtr;
  int b, i;
  gettimeofday(&tvBeginLoop, NULL);
  for (i = 0; i < n; i++) {
    b = *a;
  }
  gettimeofday(&tvEndLoop, NULL);
  loopTime = tvEndLoop.tv_sec + (tvEndLoop.tv_usec * 0.000001) -
             tvBeginLoop.tv_sec - (tvBeginLoop.tv_usec * 0.000001);
  return loopTime;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    115e <foo+0x4e>
mov    -0x40(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    113b <foo+0x2b>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe83(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
subsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
sub    $0x28,%rsp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0xecc(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm1
subsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
define double @foo(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca double
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = load i8*, i8** %3
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %8
%13 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 0, i32* %10
br label %14
14: ; preds = %21, %2
%15 = load i32, i32* %10
%16 = load i32, i32* %4
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32*, i32** %8
%20 = load i32, i32* %19
store i32 %20, i32* %9
br label %21
21: ; preds = %18
%22 = load i32, i32* %10
%23 = add nsw i32 %22, 1
store i32 %23, i32* %10
br label %14
24: ; preds = %14
%25 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%27 = load double, double* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%29 = load double, double* %28
%30 = call double @llvm.fmuladd.f64(double %29, double 0x3EB0C6F7A0B5ED8D, double %27)
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%32 = load double, double* %31
%33 = fsub double %30, %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%35 = load double, double* %34
%36 = fneg double %35
%37 = call double @llvm.fmuladd.f64(double %36, double 0x3EB0C6F7A0B5ED8D, double %33)
store double %37, double* %7
%38 = load double, double* %7
ret double %38
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
define double @foo(i8* nocapture readnone %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%10 = load double, double* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%12 = load double, double* %11
%13 = tail call double @llvm.fmuladd.f64(double %12, double 0x3EB0C6F7A0B5ED8D, double %10)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%15 = load double, double* %14
%16 = fsub double %13, %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%18 = load double, double* %17
%19 = fneg double %18
%20 = tail call double @llvm.fmuladd.f64(double %19, double 0x3EB0C6F7A0B5ED8D, double %16)
ret double %20
}