#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int tv_sec;
  long tv_usec;
};
struct rusage {
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
long time_this(void (*proc)(), unsigned count) {
  struct rusage start, end;
  getrusage(RUSAGE_SELF, &start);
  while (count--)
    proc();
  getrusage(RUSAGE_SELF, &end);
  return (end.ru_utime.tv_sec - start.ru_utime.tv_sec) * 1000000 +
         (end.ru_utime.tv_usec - start.ru_utime.tv_usec);
}


x86 assembly (clang, -O0):
<time_this>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eba(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <getrusage@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     114f <time_this+0x3f>
mov    $0x0,%al
call   *-0x8(%rbp)
jmp    1131 <time_this+0x21>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <getrusage@plt>
mov    -0x30(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0xf4240,%eax,%eax
cltq
mov    -0x28(%rbp),%rcx
sub    -0x18(%rbp),%rcx
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_this>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2ebb(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
call   1030 <getrusage@plt>
test   %ebx,%ebx
je     114a <time_this+0x3a>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   *%r14
add    $0xffffffff,%ebx
jne    1140 <time_this+0x30>
mov    (%r15),%edi
mov    %rsp,%rsi
call   1030 <getrusage@plt>
movslq (%rsp),%rax
movslq 0x10(%rsp),%rcx
sub    %rcx,%rax
imul   $0xf4240,%rax,%rcx
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i64 }
@RUSAGE_SELF = global i32 0
define i64 @time_this(void (...)* %0, i32 %1) {
%3 = alloca void (...)*
%4 = alloca i32
%5 = alloca %struct.rusage
%6 = alloca %struct.rusage
store void (...)* %0, void (...)** %3
store i32 %1, i32* %4
%7 = load i32, i32* @RUSAGE_SELF
%8 = call i32 @getrusage(i32 %7, %struct.rusage* %5)
br label %9
9: ; preds = %13, %2
%10 = load i32, i32* %4
%11 = add i32 %10, -1
store i32 %11, i32* %4
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load void (...)*, void (...)** %3
br label %9
15: ; preds = %9
%16 = load i32, i32* @RUSAGE_SELF
%17 = call i32 @getrusage(i32 %16, %struct.rusage* %6)
%18 = getelementptr inbounds %struct.rusage, %struct.rusage* %6, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %20, %23
%25 = mul nsw i32 %24, 1000000
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds %struct.rusage, %struct.rusage* %6, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 1
%32 = load i64, i64* %31
%33 = sub nsw i64 %29, %32
%34 = add nsw i64 %26, %33
ret i64 %34
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i64 }
@RUSAGE_SELF = global i32 0
define i64 @time_this(void (...)* nocapture %0, i32 %1) {
%3 = alloca %struct.rusage
%4 = alloca %struct.rusage
%5 = bitcast %struct.rusage* %3 to i8*
%6 = bitcast %struct.rusage* %4 to i8*
%7 = load i32, i32* @RUSAGE_SELF
%8 = call i32 @getrusage(i32 %7, %struct.rusage* %3)
%9 = icmp eq i32 %1, 0
br i1 %9, label %14, label %10
10: ; preds = %2, %10
%11 = phi i32 [ %12, %10 ], [ %1, %2 ]
%12 = add i32 %11, -1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10, %2
%15 = load i32, i32* @RUSAGE_SELF
%16 = call i32 @getrusage(i32 %15, %struct.rusage* %4)
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %4, i64 0, i32 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sub nsw i32 %18, %20
%22 = mul nsw i32 %21, 1000000
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.rusage, %struct.rusage* %4, i64 0, i32 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 1
%27 = load i64, i64* %26
%28 = sub i64 %25, %27
%29 = add nsw i64 %28, %23
ret i64 %29
}