#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_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ wlog(int, char *, double);
void calc_swap_time(int save, double iter_time) {
  static struct rusage r_s;
  struct rusage r;
  double te, tb;
  if (save) {
    getrusage(RUSAGE_SELF, &r_s);
    return;
  }
  getrusage(RUSAGE_SELF, &r);
  wlog(1, "ITER TIME: %.6f\n", iter_time);
  tb = (double)(r_s.ru_utime.tv_sec) +
       (double)(r_s.ru_utime.tv_usec) * (double)(1e-6);
  te = (double)(r.ru_utime.tv_sec) +
       (double)(r.ru_utime.tv_usec) * (double)(1e-6);
  wlog(1, "USER TIME: %.6f\n", te - tb);
  tb = (double)(r_s.ru_stime.tv_sec) +
       (double)(r_s.ru_stime.tv_usec) * (double)(1e-6);
  te = (double)(r.ru_stime.tv_sec) +
       (double)(r.ru_stime.tv_usec) * (double)(1e-6);
  wlog(1, "SYSTEM TIME: %.6f\n", te - tb);
  wlog(1, "CORRECTED ITER TIME: %.6f\n", iter_time - (te - tb));
}


x86 assembly (clang, -O0):
<calc_swap_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1154 <calc_swap_time+0x34>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0x2eee(%rip),%rsi
call   1040 <getrusage@plt>
jmp    1266 <calc_swap_time+0x146>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1040 <getrusage@plt>
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%edi
lea    0xebf(%rip),%rsi
call   1030 <wlog@plt>
cvtsi2sdq 0x2ecb(%rip),%xmm1
cvtsi2sdq 0x2eba(%rip),%xmm0
movsd  0xe6a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm1
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x1,%edi
lea    0xe2e(%rip),%rsi
call   1030 <wlog@plt>
cvtsi2sdq 0x2e58(%rip),%xmm1
cvtsi2sdq 0x2e47(%rip),%xmm0
movsd  0xe07(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm1
cvtsi2sdq -0x30(%rbp),%xmm0
movsd  0xde6(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    $0x1,%edi
lea    0xddc(%rip),%rsi
call   1030 <wlog@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    $0x1,%edi
lea    0xdcb(%rip),%rsi
call   1030 <wlog@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_swap_time>:
sub    $0x38,%rsp
mov    %edi,%eax
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     1143 <calc_swap_time+0x23>
lea    0x2efe(%rip),%rsi
add    $0x38,%rsp
jmp    1040 <getrusage@plt>
lea    0x18(%rsp),%rsi
movsd  %xmm0,0x8(%rsp)
call   1040 <getrusage@plt>
lea    0xedc(%rip),%rsi
mov    $0x1,%edi
movsd  0x8(%rsp),%xmm0
call   1030 <wlog@plt>
cvtsi2sdq 0x2edd(%rip),%xmm1
cvtsi2sdq 0x2ecc(%rip),%xmm2
movsd  0xe7c(%rip),%xmm4
mulsd  %xmm4,%xmm2
cvtsi2sdq 0x30(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sdq 0x28(%rsp),%xmm0
addsd  %xmm1,%xmm2
mulsd  %xmm4,%xmm0
addsd  %xmm3,%xmm0
subsd  %xmm2,%xmm0
lea    0xe58(%rip),%rsi
mov    $0x1,%edi
call   1030 <wlog@plt>
xorps  %xmm4,%xmm4
cvtsi2sdq 0x2e7a(%rip),%xmm4
xorps  %xmm1,%xmm1
cvtsi2sdq 0x2e66(%rip),%xmm1
movsd  0xe26(%rip),%xmm3
mulsd  %xmm3,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sdq 0x20(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sdq 0x18(%rsp),%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe0a(%rip),%rsi
mov    $0x1,%edi
call   1030 <wlog@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
lea    0xe00(%rip),%rsi
mov    $0x1,%edi
call   1030 <wlog@plt>
add    $0x38,%rsp
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 }
@calc_swap_time.r_s = internal global %struct.rusage zeroinitializer
@RUSAGE_SELF = global i32 0
@.str = [17 x i8] c"ITER TIME: %.6f\0A\00"
@.str.1 = [17 x i8] c"USER TIME: %.6f\0A\00"
@.str.2 = [19 x i8] c"SYSTEM TIME: %.6f\0A\00"
@.str.3 = [27 x i8] c"CORRECTED ITER TIME: %.6f\0A\00"
define void @calc_swap_time(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca %struct.rusage
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %3
store double %1, double* %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @RUSAGE_SELF
%12 = call i32 @getrusage(i32 %11, %struct.rusage* @calc_swap_time.r_s)
br label %60
13: ; preds = %2
%14 = load i32, i32* @RUSAGE_SELF
%15 = call i32 @getrusage(i32 %14, %struct.rusage* %5)
%16 = load double, double* %4
%17 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %16)
%18 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i32 0, i32 1, i32 1)
%19 = sitofp i64 %18 to double
%20 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i32 0, i32 1, i32 0)
%21 = sitofp i64 %20 to double
%22 = call double @llvm.fmuladd.f64(double %21, double 0x3EB0C6F7A0B5ED8D, double %19)
store double %22, double* %7
%23 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sitofp i64 %25 to double
%27 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = sitofp i64 %29 to double
%31 = call double @llvm.fmuladd.f64(double %30, double 0x3EB0C6F7A0B5ED8D, double %26)
store double %31, double* %6
%32 = load double, double* %6
%33 = load double, double* %7
%34 = fsub double %32, %33
%35 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), double %34)
%36 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i32 0, i32 0, i32 1)
%37 = sitofp i64 %36 to double
%38 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i32 0, i32 0, i32 0)
%39 = sitofp i64 %38 to double
%40 = call double @llvm.fmuladd.f64(double %39, double 0x3EB0C6F7A0B5ED8D, double %37)
store double %40, double* %7
%41 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = sitofp i64 %43 to double
%45 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = sitofp i64 %47 to double
%49 = call double @llvm.fmuladd.f64(double %48, double 0x3EB0C6F7A0B5ED8D, double %44)
store double %49, double* %6
%50 = load double, double* %6
%51 = load double, double* %7
%52 = fsub double %50, %51
%53 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %52)
%54 = load double, double* %4
%55 = load double, double* %6
%56 = load double, double* %7
%57 = fsub double %55, %56
%58 = fsub double %54, %57
%59 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %58)
br label %60
60: ; preds = %13, %10
ret void
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@calc_swap_time.r_s = internal global %struct.rusage zeroinitializer
@RUSAGE_SELF = global i32 0
@.str = [17 x i8] c"ITER TIME: %.6f\0A\00"
@.str.1 = [17 x i8] c"USER TIME: %.6f\0A\00"
@.str.2 = [19 x i8] c"SYSTEM TIME: %.6f\0A\00"
@.str.3 = [27 x i8] c"CORRECTED ITER TIME: %.6f\0A\00"
define void @calc_swap_time(i32 %0, double %1) {
%3 = alloca %struct.rusage
%4 = bitcast %struct.rusage* %3 to i8*
%5 = icmp eq i32 %0, 0
%6 = load i32, i32* @RUSAGE_SELF
br i1 %5, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @getrusage(i32 %6, %struct.rusage* @calc_swap_time.r_s)
br label %42
9: ; preds = %2
%10 = call i32 @getrusage(i32 %6, %struct.rusage* %3)
%11 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %1)
%12 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i64 0, i32 1, i32 1)
%13 = sitofp i64 %12 to double
%14 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i64 0, i32 1, i32 0)
%15 = sitofp i64 %14 to double
%16 = call double @llvm.fmuladd.f64(double %15, double 0x3EB0C6F7A0B5ED8D, double %13)
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 1, i32 1
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 1, i32 0
%21 = load i64, i64* %20
%22 = sitofp i64 %21 to double
%23 = call double @llvm.fmuladd.f64(double %22, double 0x3EB0C6F7A0B5ED8D, double %19)
%24 = fsub double %23, %16
%25 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), double %24)
%26 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i64 0, i32 0, i32 1)
%27 = sitofp i64 %26 to double
%28 = load i64, i64* getelementptr inbounds (%struct.rusage, %struct.rusage* @calc_swap_time.r_s, i64 0, i32 0, i32 0)
%29 = sitofp i64 %28 to double
%30 = call double @llvm.fmuladd.f64(double %29, double 0x3EB0C6F7A0B5ED8D, double %27)
%31 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 1
%32 = load i64, i64* %31
%33 = sitofp i64 %32 to double
%34 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 0
%35 = load i64, i64* %34
%36 = sitofp i64 %35 to double
%37 = call double @llvm.fmuladd.f64(double %36, double 0x3EB0C6F7A0B5ED8D, double %33)
%38 = fsub double %37, %30
%39 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %38)
%40 = fsub double %1, %38
%41 = call i32 @wlog(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %40)
br label %42
42: ; preds = %9, %7
ret void
}