#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__ {
  double tv_sec;
  int tv_usec;
};
struct TYPE_3__ {
  double tv_sec;
  int tv_usec;
};
struct rusage {
  float ru_maxrss;
  double ru_inblock;
  double ru_oublock;
  double ru_nvcsw;
  double ru_nivcsw;
  int /*<<< orphan*/ ru_majflt;
  int /*<<< orphan*/ ru_minflt;
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
void print_stats(void) {
  struct rusage usage;
  if (getrusage(RUSAGE_SELF, &usage) != 0) {
    fprintf(stdout, "Failed to get statistics: %s\n", strerror(errno));
  } else {
    fprintf(stdout, "CPU Time: %.3f s USER / %.3f s SYS\n",
            usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6,
            usage.ru_stime.tv_sec + usage.ru_stime.tv_usec / 1e6);
    fprintf(stdout,
            "Peak RAM Usage: %.3f MiB, %ld Soft Page Faults, %ld Hard Page "
            "Faults\n",
            usage.ru_maxrss / 1024.0f, usage.ru_minflt, usage.ru_majflt);
    fprintf(stdout, "Block IO: %ld In, %ld Out\n", usage.ru_inblock,
            usage.ru_oublock);
    fprintf(stdout, "Context Switches: %ld Voluntary, %ld Involuntary\n",
            usage.ru_nvcsw, usage.ru_nivcsw);
  }
}


x86 assembly (clang, -O0):
<print_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1040 <getrusage@plt>
cmp    $0x0,%rax
je     1187 <print_stats+0x57>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1246 <print_stats+0x116>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe66(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
cvtsi2sdl -0x18(%rbp),%xmm2
movsd  0xe4c(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
lea    0xe63(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
movss  -0x50(%rbp),%xmm0
movss  0xe18(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xe55(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xe7a(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe74(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stats>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <getrusage@plt>
mov    0x2e7f(%rip),%r14
mov    (%r14),%ebx
test   %rax,%rax
je     117f <print_stats+0x4f>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    121c <print_stats+0xec>
cvtsi2sdl 0x50(%rsp),%xmm0
movsd  0xe73(%rip),%xmm2
divsd  %xmm2,%xmm0
addsd  0x48(%rsp),%xmm0
cvtsi2sdl 0x40(%rsp),%xmm1
divsd  %xmm2,%xmm1
addsd  0x38(%rsp),%xmm1
lea    0xe7c(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%al
call   1030 <fprintf@plt>
movss  0x8(%rsp),%xmm0
mulss  0xe43(%rip),%xmm0
mov    (%r14),%edi
cvtss2sd %xmm0,%xmm0
mov    0x34(%rsp),%edx
mov    0x30(%rsp),%ecx
lea    0xe73(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    (%r14),%edi
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0xe9c(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
mov    (%r14),%edi
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
lea    0xe9a(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rusage = type { float, double, double, double, double, i32, i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { double, i32 }
%struct.TYPE_3__ = type { double, i32 }
@RUSAGE_SELF = global i32 0
@stdout = global i32 0
@.str = [30 x i8] c"Failed to get statistics: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"CPU Time: %.3f s USER / %.3f s SYS\0A\00"
@.str.2 = [70 x i8] c"Peak RAM Usage: %.3f MiB, %ld Soft Page Faults, %ld Hard Page Faults\0A\00"
@.str.3 = [27 x i8] c"Block IO: %ld In, %ld Out\0A\00"
@.str.4 = [50 x i8] c"Context Switches: %ld Voluntary, %ld Involuntary\0A\00"
define void @print_stats() {
%1 = alloca %struct.rusage
%2 = load i32, i32* @RUSAGE_SELF
%3 = call i64 @getrusage(i32 %2, %struct.rusage* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stdout
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %53
10: ; preds = %0
%11 = load i32, i32* @stdout
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 8
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %12, i32 0, i32 0
%14 = load double, double* %13
%15 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 8
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %14, %19
%21 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 7
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i32 0, i32 0
%23 = load double, double* %22
%24 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 7
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 1.000000e+06
%29 = fadd double %23, %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %20, double %29)
%31 = load i32, i32* @stdout
%32 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 0
%33 = load float, float* %32
%34 = fdiv float %33, 1.024000e+03
%35 = fpext float %34 to double
%36 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 6
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 5
%39 = load i32, i32* %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), double %35, i32 %37, i32 %39)
%41 = load i32, i32* @stdout
%42 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 1
%43 = load double, double* %42
%44 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 2
%45 = load double, double* %44
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %43, double %45)
%47 = load i32, i32* @stdout
%48 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 3
%49 = load double, double* %48
%50 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i32 0, i32 4
%51 = load double, double* %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), double %49, double %51)
br label %53
53: ; preds = %10, %5
ret void
}

LLVM IR (-O2):
%struct.rusage = type { float, double, double, double, double, i32, i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { double, i32 }
%struct.TYPE_3__ = type { double, i32 }
@RUSAGE_SELF = global i32 0
@stdout = global i32 0
@.str = [30 x i8] c"Failed to get statistics: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"CPU Time: %.3f s USER / %.3f s SYS\0A\00"
@.str.2 = [70 x i8] c"Peak RAM Usage: %.3f MiB, %ld Soft Page Faults, %ld Hard Page Faults\0A\00"
@.str.3 = [27 x i8] c"Block IO: %ld In, %ld Out\0A\00"
@.str.4 = [50 x i8] c"Context Switches: %ld Voluntary, %ld Involuntary\0A\00"
define void @print_stats() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i64 @getrusage(i32 %3, %struct.rusage* %1)
%5 = icmp eq i64 %4, 0
%6 = load i32, i32* @stdout
br i1 %5, label %11, label %7
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %49
11: ; preds = %0
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 8, i32 0
%13 = load double, double* %12
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 8, i32 1
%15 = load i32, i32* %14
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 1.000000e+06
%18 = fadd double %13, %17
%19 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 7, i32 0
%20 = load double, double* %19
%21 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 7, i32 1
%22 = load i32, i32* %21
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, 1.000000e+06
%25 = fadd double %20, %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %18, double %25)
%27 = load i32, i32* @stdout
%28 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0
%29 = load float, float* %28
%30 = fmul float %29, 0x3F50000000000000
%31 = fpext float %30 to double
%32 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 6
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 5
%35 = load i32, i32* %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), double %31, i32 %33, i32 %35)
%37 = load i32, i32* @stdout
%38 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1
%39 = load double, double* %38
%40 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 2
%41 = load double, double* %40
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %39, double %41)
%43 = load i32, i32* @stdout
%44 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 3
%45 = load double, double* %44
%46 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 4
%47 = load double, double* %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), double %45, double %47)
br label %49
49: ; preds = %11, %7
ret void
}