#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;
};
struct rusage {
  struct timeval ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
double app_timer_user(int stop) {
  static struct timeval start;
  struct timeval elapsed;
  struct rusage now;
  getrusage(RUSAGE_SELF, &now);
  if (stop) {
    timersub(&now.ru_utime, &start, &elapsed);
    return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
  }
  start = now.ru_utime;
  return 0.0;
}


x86 assembly (clang, -O0):
<app_timer_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <getrusage@plt>
cmpl   $0x0,-0xc(%rbp)
je     117f <app_timer_user+0x5f>
lea    -0x30(%rbp),%rdi
lea    0x2ee6(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <timersub@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe93(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119d <app_timer_user+0x7d>
mov    -0x30(%rbp),%rax
mov    %rax,0x2eae(%rip)
mov    -0x28(%rbp),%rax
mov    %rax,0x2eab(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<app_timer_user>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <getrusage@plt>
test   %ebx,%ebx
je     1166 <app_timer_user+0x46>
lea    0x2ef5(%rip),%rsi
mov    %rsp,%rdi
lea    0x10(%rsp),%rdx
call   1040 <timersub@plt>
movsd  0x18(%rsp),%xmm0
divsd  0xea2(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
jmp    1177 <app_timer_user+0x57>
movupd (%rsp),%xmm0
movupd %xmm0,0x2ec5(%rip)
xorpd  %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
%struct.rusage = type { %struct.timeval }
@app_timer_user.start = internal global %struct.timeval zeroinitializer
@RUSAGE_SELF = global i32 0
define double @app_timer_user(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.rusage
store i32 %0, i32* %3
%6 = load i32, i32* @RUSAGE_SELF
%7 = call i32 @getrusage(i32 %6, %struct.rusage* %5)
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%12 = call i32 @timersub(%struct.timeval* %11, %struct.timeval* @app_timer_user.start, %struct.timeval* %4)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%14 = load double, double* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%16 = load double, double* %15
%17 = fdiv double %16, 1.000000e+06
%18 = fadd double %14, %17
store double %18, double* %2
br label %22
19: ; preds = %1
%20 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%21 = bitcast %struct.timeval* %20 to i8*
store double 0.000000e+00, double* %2
br label %22
22: ; preds = %19, %10
%23 = load double, double* %2
ret double %23
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
%struct.rusage = type { %struct.timeval }
@app_timer_user.start = internal global %struct.timeval zeroinitializer
@RUSAGE_SELF = global i32 0
define double @app_timer_user(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.rusage
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.rusage* %3 to i8*
%6 = load i32, i32* @RUSAGE_SELF
%7 = call i32 @getrusage(i32 %6, %struct.rusage* %3)
%8 = icmp eq i32 %0, 0
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0
%11 = call i32 @timersub(%struct.timeval* %10, %struct.timeval* @app_timer_user.start, %struct.timeval* %2)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load double, double* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%15 = load double, double* %14
%16 = fdiv double %15, 1.000000e+06
%17 = fadd double %13, %16
br label %19
18: ; preds = %1
br label %19
19: ; preds = %18, %9
%20 = phi double [ %17, %9 ], [ 0.000000e+00, %18 ]
ret double %20
}