#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 rusage {
  int /*<<< orphan*/ ru_stime;
  int /*<<< orphan*/ ru_utime;
  scalar_t__ ru_nivcsw;
  scalar_t__ ru_nvcsw;
};

/* Variables and functions */
int /*<<< orphan*/ timersub(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                            int /*<<< orphan*/ *);
void rusagesub(struct rusage *end, struct rusage *start, struct rusage *diff) {
  diff->ru_nvcsw = end->ru_nvcsw - start->ru_nvcsw;
  diff->ru_nivcsw = end->ru_nivcsw - start->ru_nivcsw;
  timersub(&end->ru_utime, &start->ru_utime, &diff->ru_utime);
  timersub(&end->ru_stime, &start->ru_stime, &diff->ru_stime);
}


x86 assembly (clang, -O0):
<rusagesub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x10(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    -0x18(%rbp),%rdx
add    $0x4,%rdx
call   1030 <timersub@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <timersub@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rusagesub>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movdqu 0x8(%rdi),%xmm0
movdqu 0x8(%rsi),%xmm1
psubq  %xmm1,%xmm0
movdqu %xmm0,0x8(%rdx)
add    $0x4,%rdi
add    $0x4,%rsi
add    $0x4,%rdx
call   1030 <timersub@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <timersub@plt>

LLVM IR (-O0):
%struct.rusage = type { i32, i32, i64, i64 }
define void @rusagesub(%struct.rusage* %0, %struct.rusage* %1, %struct.rusage* %2) {
%4 = alloca %struct.rusage*
%5 = alloca %struct.rusage*
%6 = alloca %struct.rusage*
store %struct.rusage* %0, %struct.rusage** %4
store %struct.rusage* %1, %struct.rusage** %5
store %struct.rusage* %2, %struct.rusage** %6
%7 = load %struct.rusage*, %struct.rusage** %4
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %7, i32 0, i32 3
%9 = load i64, i64* %8
%10 = load %struct.rusage*, %struct.rusage** %5
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %10, i32 0, i32 3
%12 = load i64, i64* %11
%13 = sub nsw i64 %9, %12
%14 = load %struct.rusage*, %struct.rusage** %6
%15 = getelementptr inbounds %struct.rusage, %struct.rusage* %14, i32 0, i32 3
store i64 %13, i64* %15
%16 = load %struct.rusage*, %struct.rusage** %4
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %16, i32 0, i32 2
%18 = load i64, i64* %17
%19 = load %struct.rusage*, %struct.rusage** %5
%20 = getelementptr inbounds %struct.rusage, %struct.rusage* %19, i32 0, i32 2
%21 = load i64, i64* %20
%22 = sub nsw i64 %18, %21
%23 = load %struct.rusage*, %struct.rusage** %6
%24 = getelementptr inbounds %struct.rusage, %struct.rusage* %23, i32 0, i32 2
store i64 %22, i64* %24
%25 = load %struct.rusage*, %struct.rusage** %4
%26 = getelementptr inbounds %struct.rusage, %struct.rusage* %25, i32 0, i32 1
%27 = load %struct.rusage*, %struct.rusage** %5
%28 = getelementptr inbounds %struct.rusage, %struct.rusage* %27, i32 0, i32 1
%29 = load %struct.rusage*, %struct.rusage** %6
%30 = getelementptr inbounds %struct.rusage, %struct.rusage* %29, i32 0, i32 1
%31 = call i32 @timersub(i32* %26, i32* %28, i32* %30)
%32 = load %struct.rusage*, %struct.rusage** %4
%33 = getelementptr inbounds %struct.rusage, %struct.rusage* %32, i32 0, i32 0
%34 = load %struct.rusage*, %struct.rusage** %5
%35 = getelementptr inbounds %struct.rusage, %struct.rusage* %34, i32 0, i32 0
%36 = load %struct.rusage*, %struct.rusage** %6
%37 = getelementptr inbounds %struct.rusage, %struct.rusage* %36, i32 0, i32 0
%38 = call i32 @timersub(i32* %33, i32* %35, i32* %37)
ret void
}

LLVM IR (-O2):
%struct.rusage = type { i32, i32, i64, i64 }
define void @rusagesub(%struct.rusage* %0, %struct.rusage* %1, %struct.rusage* %2) {
%4 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 2
%5 = bitcast i64* %4 to <2 x i64>*
%6 = load <2 x i64>, <2 x i64>* %5
%7 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 2
%8 = bitcast i64* %7 to <2 x i64>*
%9 = load <2 x i64>, <2 x i64>* %8
%10 = sub nsw <2 x i64> %6, %9
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i64 0, i32 2
%12 = bitcast i64* %11 to <2 x i64>*
store <2 x i64> %10, <2 x i64>* %12
%13 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 1
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1
%15 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i64 0, i32 1
%16 = tail call i32 @timersub(i32* %13, i32* %14, i32* %15)
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 0
%18 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0
%19 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i64 0, i32 0
%20 = tail call i32 @timersub(i32* %17, i32* %18, i32* %19)
ret void
}