#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 timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
int /*<<< orphan*/ clock_getres(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ clock_overhead(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, ...);
void measure_clock(const char *ctype, clockid_t clock) {
  struct timespec t;
  printf("\n- %s -\n", ctype);
  clock_getres(clock, &t);
  printf("clock_getres: %ld seconds | %ld nanoseconds\n", t.tv_sec, t.tv_nsec);
  clock_overhead(clock);
}


x86 assembly (clang, -O0):
<measure_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <clock_getres@plt>
movslq -0x14(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1030 <clock_overhead@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure_clock>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1050 <clock_getres@plt>
movslq 0xc(%rsp),%rsi
mov    0x8(%rsp),%edx
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1030 <clock_overhead@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [9 x i8] c"\0A- %s -\0A\00"
@.str.1 = [45 x i8] c"clock_getres: %ld seconds | %ld nanoseconds\0A\00"
define void @measure_clock(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.timespec
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* %4
%9 = call i32 @clock_getres(i32 %8, %struct.timespec* %5)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %15)
%17 = load i32, i32* %4
%18 = call i32 @clock_overhead(i32 %17)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [9 x i8] c"\0A- %s -\0A\00"
@.str.1 = [45 x i8] c"clock_getres: %ld seconds | %ld nanoseconds\0A\00"
define void @measure_clock(i8* %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32 @clock_getres(i32 %1, %struct.timespec* %3)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%8 = load i32, i32* %7
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %12)
%14 = call i32 @clock_overhead(i32 %1)
ret void
}