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

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_CHILDREN;
int /*<<< orphan*/ errno;
scalar_t__ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
void print_rusage(struct timeval *start_tv, struct timeval *stop_tv) {
  struct rusage child;
  if (getrusage(RUSAGE_CHILDREN, &child) != 0) {
    printf("rusage children error: %s", strerror(errno));
    return;
  }
  double start = start_tv->tv_sec + start_tv->tv_usec / 1000000.0;
  double stop = stop_tv->tv_sec + stop_tv->tv_usec / 1000000.0;
  double uchild = child.ru_utime.tv_sec + child.ru_utime.tv_usec / 1000000.0;
  double schild = child.ru_stime.tv_sec + child.ru_stime.tv_usec / 1000000.0;
  double total = stop - start;
  printf("%.2fs (%d%% user, %d%% sys)", total,
         (int)(100.0 * uchild / total + 0.5),
         (int)(100.0 * schild / total + 0.5));
}


x86 assembly (clang, -O0):
<print_rusage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1040 <getrusage@plt>
cmp    $0x0,%rax
je     1180 <print_rusage+0x50>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1270 <print_rusage+0x140>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xe77(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xe51(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe32(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe13(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  0xde2(%rip),%xmm1
mulsd  -0x48(%rbp),%xmm1
divsd  -0x58(%rbp),%xmm1
movsd  0xdc8(%rip),%xmm2
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%esi
movsd  0xdc0(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
divsd  -0x58(%rbp),%xmm1
movsd  0xda6(%rip),%xmm2
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edx
lea    0xdc9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_rusage>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <getrusage@plt>
test   %rax,%rax
je     1179 <print_rusage+0x49>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xebe(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    120b <print_rusage+0xdb>
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
movhpd 0x8(%r14),%xmm1
divpd  0xe70(%rip),%xmm1
movhpd (%r14),%xmm0
addpd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
movsd  0xe63(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  0x18(%rsp),%xmm2
divsd  %xmm3,%xmm1
addsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
subsd  %xmm3,%xmm0
movsd  0xe43(%rip),%xmm3
mulsd  %xmm3,%xmm2
divsd  %xmm0,%xmm2
movsd  0xe3b(%rip),%xmm4
addsd  %xmm4,%xmm2
cvttsd2si %xmm2,%esi
mulsd  %xmm3,%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm4,%xmm1
cvttsd2si %xmm1,%edx
lea    0xe3e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { double, double }
%struct.TYPE_3__ = type { double, double }
@RUSAGE_CHILDREN = global i32 0
@.str = [26 x i8] c"rusage children error: %s\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"%.2fs (%d%% user, %d%% sys)\00"
define void @print_rusage(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.rusage
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%11 = load i32, i32* @RUSAGE_CHILDREN
%12 = call i64 @getrusage(i32 %11, %struct.rusage* %5)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %68
18: ; preds = %2
%19 = load %struct.timeval*, %struct.timeval** %3
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%21 = load double, double* %20
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load double, double* %23
%25 = fdiv double %24, 1.000000e+06
%26 = fadd double %21, %25
store double %26, double* %6
%27 = load %struct.timeval*, %struct.timeval** %4
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%29 = load double, double* %28
%30 = load %struct.timeval*, %struct.timeval** %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 1
%32 = load double, double* %31
%33 = fdiv double %32, 1.000000e+06
%34 = fadd double %29, %33
store double %34, double* %7
%35 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load double, double* %36
%38 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load double, double* %39
%41 = fdiv double %40, 1.000000e+06
%42 = fadd double %37, %41
store double %42, double* %8
%43 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %43, i32 0, i32 0
%45 = load double, double* %44
%46 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %46, i32 0, i32 1
%48 = load double, double* %47
%49 = fdiv double %48, 1.000000e+06
%50 = fadd double %45, %49
store double %50, double* %9
%51 = load double, double* %7
%52 = load double, double* %6
%53 = fsub double %51, %52
store double %53, double* %10
%54 = load double, double* %10
%55 = load double, double* %8
%56 = fmul double 1.000000e+02, %55
%57 = load double, double* %10
%58 = fdiv double %56, %57
%59 = fadd double %58, 5.000000e-01
%60 = fptosi double %59 to i32
%61 = load double, double* %9
%62 = fmul double 1.000000e+02, %61
%63 = load double, double* %10
%64 = fdiv double %62, %63
%65 = fadd double %64, 5.000000e-01
%66 = fptosi double %65 to i32
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %54, i32 %60, i32 %66)
br label %68
68: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { double, double }
%struct.TYPE_3__ = type { double, double }
@RUSAGE_CHILDREN = global i32 0
@.str = [26 x i8] c"rusage children error: %s\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"%.2fs (%d%% user, %d%% sys)\00"
define void @print_rusage(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = alloca %struct.rusage
%4 = bitcast %struct.rusage* %3 to i8*
%5 = load i32, i32* @RUSAGE_CHILDREN
%6 = call i64 @getrusage(i32 %5, %struct.rusage* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %51
12: ; preds = %2
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%14 = load double, double* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%16 = load double, double* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%18 = load double, double* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%20 = load double, double* %19
%21 = insertelement <2 x double> poison, double %20, i64 0
%22 = insertelement <2 x double> %21, double %16, i64 1
%23 = fdiv <2 x double> %22, <double 1.000000e+06, double 1.000000e+06>
%24 = insertelement <2 x double> poison, double %18, i64 0
%25 = insertelement <2 x double> %24, double %14, i64 1
%26 = fadd <2 x double> %25, %23
%27 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 1, i32 0
%28 = load double, double* %27
%29 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 1, i32 1
%30 = load double, double* %29
%31 = fdiv double %30, 1.000000e+06
%32 = fadd double %28, %31
%33 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 0
%34 = load double, double* %33
%35 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 1
%36 = load double, double* %35
%37 = fdiv double %36, 1.000000e+06
%38 = fadd double %34, %37
%39 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%40 = fsub <2 x double> %26, %39
%41 = extractelement <2 x double> %40, i64 0
%42 = fmul double %32, 1.000000e+02
%43 = fdiv double %42, %41
%44 = fadd double %43, 5.000000e-01
%45 = fptosi double %44 to i32
%46 = fmul double %38, 1.000000e+02
%47 = fdiv double %46, %41
%48 = fadd double %47, 5.000000e-01
%49 = fptosi double %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %41, i32 %45, i32 %49)
br label %51
51: ; preds = %12, %8
ret void
}