#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__ {
  long tv_sec;
  long tv_usec;
};
struct rusage {
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
double elapsed_seconds(void) {
  double answer;
  static struct rusage prog_rusage;
  static long prev_rusage_seconds = 0;
  static long prev_rusage_micro_seconds = 0;
  getrusage(0, &prog_rusage);
  answer =
      (double)(prog_rusage.ru_utime.tv_sec - prev_rusage_seconds) +
      ((double)(prog_rusage.ru_utime.tv_usec - prev_rusage_micro_seconds)) /
          1000000.0;
  prev_rusage_seconds = prog_rusage.ru_utime.tv_sec;
  prev_rusage_micro_seconds = prog_rusage.ru_utime.tv_usec;
  return answer;
}


x86 assembly (clang, -O0):
<elapsed_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    0x2f0f(%rip),%rsi
call   1030 <getrusage@plt>
mov    0x2f03(%rip),%rax
sub    0x2f0c(%rip),%rax
cvtsi2sd %rax,%xmm0
mov    0x2ef8(%rip),%rax
sub    0x2f01(%rip),%rax
cvtsi2sd %rax,%xmm1
movsd  0xeac(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    0x2ec8(%rip),%rax
mov    %rax,0x2ed1(%rip)
mov    0x2ec2(%rip),%rax
mov    %rax,0x2ecb(%rip)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_seconds>:
push   %rax
lea    0x2f18(%rip),%rsi
xor    %edi,%edi
call   1030 <getrusage@plt>
mov    0x2f0a(%rip),%rax
mov    %rax,%rcx
sub    0x2f10(%rip),%rcx
cvtsi2sd %rcx,%xmm1
mov    0x2efc(%rip),%rcx
mov    %rcx,%rdx
sub    0x2f02(%rip),%rdx
cvtsi2sd %rdx,%xmm0
divsd  0xead(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    %rax,0x2ee2(%rip)
mov    %rcx,0x2ee3(%rip)
pop    %rax
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@elapsed_seconds.prog_rusage = internal global %struct.rusage zeroinitializer
@elapsed_seconds.prev_rusage_seconds = internal global i64 0
@elapsed_seconds.prev_rusage_micro_seconds = internal global i64 0
define double @elapsed_seconds() {
%1 = alloca double
%2 = call i32 @getrusage(i32 0, %struct.rusage* @elapsed_seconds.prog_rusage)
%3 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @elapsed_seconds.prog_rusage, i32 0, i32 0, i32 0)
%4 = load i64, i64* @elapsed_seconds.prev_rusage_seconds
%5 = sub nsw i64 %3, %4
%6 = sitofp i64 %5 to double
%7 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @elapsed_seconds.prog_rusage, i32 0, i32 0, i32 1)
%8 = load i64, i64* @elapsed_seconds.prev_rusage_micro_seconds
%9 = sub nsw i64 %7, %8
%10 = sitofp i64 %9 to double
%11 = fdiv double %10, 1.000000e+06
%12 = fadd double %6, %11
store double %12, double* %1
%13 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @elapsed_seconds.prog_rusage, i32 0, i32 0, i32 0)
store i64 %13, i64* @elapsed_seconds.prev_rusage_seconds
%14 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @elapsed_seconds.prog_rusage, i32 0, i32 0, i32 1)
store i64 %14, i64* @elapsed_seconds.prev_rusage_micro_seconds
%15 = load double, double* %1
ret double %15
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@elapsed_seconds.prog_rusage = internal global %struct.rusage zeroinitializer
@elapsed_seconds.prev_rusage_seconds = internal unnamed_addr global i64 0
@elapsed_seconds.prev_rusage_micro_seconds = internal unnamed_addr global i64 0
define double @elapsed_seconds() {
%1 = tail call i32 @getrusage(i32 0, %struct.rusage* @elapsed_seconds.prog_rusage)
%2 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @elapsed_seconds.prog_rusage, i64 0, i32 0, i32 0)
%3 = load i64, i64* @elapsed_seconds.prev_rusage_seconds
%4 = sub nsw i64 %2, %3
%5 = sitofp i64 %4 to double
%6 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @elapsed_seconds.prog_rusage, i64 0, i32 0, i32 1)
%7 = load i64, i64* @elapsed_seconds.prev_rusage_micro_seconds
%8 = sub nsw i64 %6, %7
%9 = sitofp i64 %8 to double
%10 = fdiv double %9, 1.000000e+06
%11 = fadd double %10, %5
store i64 %2, i64* @elapsed_seconds.prev_rusage_seconds
store i64 %6, i64* @elapsed_seconds.prev_rusage_micro_seconds
ret double %11
}