#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

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

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int errno;
scalar_t__ getrusage(int /*<<< orphan*/, struct rusage *);
int getrusage_helper_sub(double *ru_stime, double *ru_utime,
                         double ru_stime_sub, double ru_utime_sub) {
  struct rusage usage;
  if (getrusage(RUSAGE_SELF, &usage))
    return -errno;
  *ru_stime = (double)usage.ru_stime.tv_sec +
              (double)usage.ru_stime.tv_usec / 1000000.0 - ru_stime_sub;
  *ru_utime = (double)usage.ru_utime.tv_sec +
              (double)usage.ru_utime.tv_usec / 1000000.0 - ru_utime_sub;
  return 0;
}


x86 assembly (clang, -O0):
<getrusage_helper_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1030 <getrusage@plt>
cmp    $0x0,%rax
je     1159 <getrusage_helper_sub+0x49>
xor    %eax,%eax
mov    0x2e91(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <getrusage_helper_sub+0xa2>
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x38(%rbp),%xmm1
movsd  0xe93(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
cvtsi2sdq -0x40(%rbp),%xmm0
cvtsi2sdq -0x48(%rbp),%xmm1
movsd  0xe6a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
subsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrusage_helper_sub>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
call   1030 <getrusage@plt>
test   %rax,%rax
je     114e <getrusage_helper_sub+0x3e>
mov    0x2e98(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    11a5 <getrusage_helper_sub+0x95>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x30(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x28(%rsp),%xmm1
movsd  0xe96(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movsd  %xmm1,(%rbx)
xorps  %xmm0,%xmm0
cvtsi2sdq 0x20(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x18(%rsp),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
movsd  %xmm1,(%r14)
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@RUSAGE_SELF = global i32 0
@errno = global i32 0
define i32 @getrusage_helper_sub(double* %0, double* %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca %struct.rusage
store double* %0, double** %6
store double* %1, double** %7
store double %2, double* %8
store double %3, double* %9
%11 = load i32, i32* @RUSAGE_SELF
%12 = call i64 @getrusage(i32 %11, %struct.rusage* %10)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @errno
%16 = sub nsw i32 0, %15
store i32 %16, i32* %5
br label %44
17: ; preds = %4
%18 = getelementptr inbounds %struct.rusage, %struct.rusage* %10, i32 0, i32 1
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = sitofp i64 %20 to double
%22 = getelementptr inbounds %struct.rusage, %struct.rusage* %10, i32 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = sitofp i64 %24 to double
%26 = fdiv double %25, 1.000000e+06
%27 = fadd double %21, %26
%28 = load double, double* %8
%29 = fsub double %27, %28
%30 = load double*, double** %6
store double %29, double* %30
%31 = getelementptr inbounds %struct.rusage, %struct.rusage* %10, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %31, i32 0, i32 1
%33 = load i64, i64* %32
%34 = sitofp i64 %33 to double
%35 = getelementptr inbounds %struct.rusage, %struct.rusage* %10, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to double
%39 = fdiv double %38, 1.000000e+06
%40 = fadd double %34, %39
%41 = load double, double* %9
%42 = fsub double %40, %41
%43 = load double*, double** %7
store double %42, double* %43
store i32 0, i32* %5
br label %44
44: ; preds = %17, %14
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@RUSAGE_SELF = global i32 0
@errno = global i32 0
define i32 @getrusage_helper_sub(double* nocapture writeonly %0, double* nocapture writeonly %1, double %2, double %3) {
%5 = alloca %struct.rusage
%6 = bitcast %struct.rusage* %5 to i8*
%7 = load i32, i32* @RUSAGE_SELF
%8 = call i64 @getrusage(i32 %7, %struct.rusage* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = load i32, i32* @errno
%12 = sub nsw i32 0, %11
br label %32
13: ; preds = %4
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 1, i32 1
%15 = load i64, i64* %14
%16 = sitofp i64 %15 to double
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 1, i32 0
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = fdiv double %19, 1.000000e+06
%21 = fadd double %20, %16
%22 = fsub double %21, %2
store double %22, double* %0
%23 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 0, i32 1
%24 = load i64, i64* %23
%25 = sitofp i64 %24 to double
%26 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 0, i32 0
%27 = load i64, i64* %26
%28 = sitofp i64 %27 to double
%29 = fdiv double %28, 1.000000e+06
%30 = fadd double %29, %25
%31 = fsub double %30, %3
store double %31, double* %1
br label %32
32: ; preds = %13, %10
%33 = phi i32 [ %12, %10 ], [ 0, %13 ]
ret i32 %33
}