#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct rusage {
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ nrerror(char *);
double cpu_time(void) {
  static double previous_measurement = 0.;
  double elapsed_secs, increment;
  struct rusage usage;
  if (getrusage(RUSAGE_SELF, &usage) == -1)
    nrerror("cpu_time(), getrusage error condition.");
  elapsed_secs =
      (double)usage.ru_utime.tv_sec + (double)usage.ru_utime.tv_usec / 1000000.;
  increment = elapsed_secs - previous_measurement;
  previous_measurement = elapsed_secs;
  return increment;
}


x86 assembly (clang, -O0):
<cpu_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <getrusage@plt>
cmp    $0xffffffff,%eax
jne    114f <cpu_time+0x2f>
lea    0xebe(%rip),%rdi
call   1030 <nrerror@plt>
cvtsi2sdq -0x18(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xe9d(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  0x2ebb(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2ea9(%rip)
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_time>:
sub    $0x18,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <getrusage@plt>
cmp    $0xffffffff,%eax
jne    1148 <cpu_time+0x28>
lea    0xec5(%rip),%rdi
call   1030 <nrerror@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
cvtsi2sdq 0x8(%rsp),%xmm1
divsd  0xea2(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
subsd  0x2eca(%rip),%xmm0
movsd  %xmm1,0x2ec2(%rip)
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@cpu_time.previous_measurement = internal global double 0.000000e+00
@RUSAGE_SELF = global i32 0
@.str = [39 x i8] c"cpu_time(), getrusage error condition.\00"
define double @cpu_time() {
%1 = alloca double
%2 = alloca double
%3 = alloca %struct.rusage
%4 = load i32, i32* @RUSAGE_SELF
%5 = call i32 @getrusage(i32 %4, %struct.rusage* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @nrerror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i32 0, i32 0
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = fdiv double %17, 1.000000e+06
%19 = fadd double %13, %18
store double %19, double* %1
%20 = load double, double* %1
%21 = load double, double* @cpu_time.previous_measurement
%22 = fsub double %20, %21
store double %22, double* %2
%23 = load double, double* %1
store double %23, double* @cpu_time.previous_measurement
%24 = load double, double* %2
ret double %24
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@cpu_time.previous_measurement = internal unnamed_addr global double 0.000000e+00
@RUSAGE_SELF = global i32 0
@.str = [39 x i8] c"cpu_time(), getrusage error condition.\00"
define double @cpu_time() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i32 @getrusage(i32 %3, %struct.rusage* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @nrerror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 1
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 0
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 1.000000e+06
%16 = fadd double %15, %11
%17 = load double, double* @cpu_time.previous_measurement
%18 = fsub double %16, %17
store double %16, double* @cpu_time.previous_measurement
ret double %18
}