#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 timeval {
  double tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  double tv_sec;
  scalar_t__ tv_usec;
};
struct rusage {
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void gettime(double *cpu, double *wall) {
  struct timeval tv;
  struct rusage ru;
  if (cpu != NULL) {
    getrusage(RUSAGE_SELF, &ru);
    *cpu = ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec * 1e-6;
  }
  if (wall != NULL) {
    gettimeofday(&tv, NULL);
    *wall = tv.tv_sec + (double)tv.tv_usec * 1e-6;
  }
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1170 <gettime+0x50>
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1040 <getrusage@plt>
movsd  -0x30(%rbp),%xmm1
cvtsi2sdq -0x28(%rbp),%xmm0
movsd  0xea0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11ab <gettime+0x8b>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movsd  -0x20(%rbp),%xmm1
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xe65(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
test   %rdi,%rdi
je     115e <gettime+0x3e>
mov    %rdi,%rbx
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <getrusage@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
mulsd  0xeac(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
test   %r14,%r14
je     118c <gettime+0x6c>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x20(%rsp),%xmm0
mulsd  0xe7f(%rip),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { double, i64 }
@RUSAGE_SELF = global i32 0
define void @gettime(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca %struct.timeval
%6 = alloca %struct.rusage
store double* %0, double** %3
store double* %1, double** %4
%7 = load double*, double** %3
%8 = icmp ne double* %7, null
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = load i32, i32* @RUSAGE_SELF
%11 = call i32 @getrusage(i32 %10, %struct.rusage* %6)
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %6, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
%14 = load double, double* %13
%15 = getelementptr inbounds %struct.rusage, %struct.rusage* %6, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = call double @llvm.fmuladd.f64(double %18, double 0x3EB0C6F7A0B5ED8D, double %14)
%20 = load double*, double** %3
store double %19, double* %20
br label %21
21: ; preds = %9, %2
%22 = load double*, double** %4
%23 = icmp ne double* %22, null
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%27 = load double, double* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%29 = load i64, i64* %28
%30 = sitofp i64 %29 to double
%31 = call double @llvm.fmuladd.f64(double %30, double 0x3EB0C6F7A0B5ED8D, double %27)
%32 = load double*, double** %4
store double %31, double* %32
br label %33
33: ; preds = %24, %21
ret void
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { double, i64 }
@RUSAGE_SELF = global i32 0
define void @gettime(double* writeonly %0, double* writeonly %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.rusage
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.rusage* %4 to i8*
%7 = icmp eq double* %0, null
br i1 %7, label %17, label %8
8: ; preds = %2
%9 = load i32, i32* @RUSAGE_SELF
%10 = call i32 @getrusage(i32 %9, %struct.rusage* %4)
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %4, i64 0, i32 0, i32 0
%12 = load double, double* %11
%13 = getelementptr inbounds %struct.rusage, %struct.rusage* %4, i64 0, i32 0, i32 1
%14 = load i64, i64* %13
%15 = sitofp i64 %14 to double
%16 = call double @llvm.fmuladd.f64(double %15, double 0x3EB0C6F7A0B5ED8D, double %12)
store double %16, double* %0
br label %17
17: ; preds = %8, %2
%18 = icmp eq double* %1, null
br i1 %18, label %27, label %19
19: ; preds = %17
%20 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%22 = load double, double* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%24 = load i64, i64* %23
%25 = sitofp i64 %24 to double
%26 = call double @llvm.fmuladd.f64(double %25, double 0x3EB0C6F7A0B5ED8D, double %22)
store double %26, double* %1
br label %27
27: ; preds = %19, %17
ret void
}