#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*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_getres(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ format_time(struct timespec *);
int /*<<< orphan*/ format_timediff(struct timespec *, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ xtime(int /*<<< orphan*/, struct timespec *);
int main(int argc, const char **argv) {
  struct timespec res = {0};
  struct timespec now = {0};
  struct timespec then = {0};
  clock_getres(CLOCK_MONOTONIC, &res);
  fprintf(stdout, "monotonic clock res: ");
  format_time(&res);
  xtime(CLOCK_MONOTONIC, &then);
  for (;;) {
    xtime(CLOCK_MONOTONIC, &now);
    format_timediff(&now, &then);
    then = now;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <clock_getres@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1070 <format_time@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1080 <xtime@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1080 <xtime@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <format_timediff@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11e8 <main+0x88>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0x18(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2e70(%rip),%r15
mov    (%r15),%edi
lea    0x18(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <clock_getres@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <format_time@plt>
mov    (%r15),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1070 <xtime@plt>
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %rbx,%rsi
call   1070 <xtime@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <format_timediff@plt>
mov    0x10(%rsp),%eax
mov    %eax,0x8(%rsp)
jmp    11c0 <main+0x70>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@stdout = global i32 0
@.str = [22 x i8] c"monotonic clock res: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast %struct.timespec* %6 to i8*
%10 = bitcast %struct.timespec* %7 to i8*
%11 = bitcast %struct.timespec* %8 to i8*
%12 = load i32, i32* @CLOCK_MONOTONIC
%13 = call i32 @clock_getres(i32 %12, %struct.timespec* %6)
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @format_time(%struct.timespec* %6)
%17 = load i32, i32* @CLOCK_MONOTONIC
%18 = call i32 @xtime(i32 %17, %struct.timespec* %8)
br label %19
19: ; preds = %19, %2
%20 = load i32, i32* @CLOCK_MONOTONIC
%21 = call i32 @xtime(i32 %20, %struct.timespec* %7)
%22 = call i32 @format_timediff(%struct.timespec* %7, %struct.timespec* %8)
%23 = bitcast %struct.timespec* %8 to i8*
%24 = bitcast %struct.timespec* %7 to i8*
br label %19
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@stdout = global i32 0
@.str = [22 x i8] c"monotonic clock res: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = bitcast %struct.timespec* %3 to i8*
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 0, i32* %7
%8 = bitcast %struct.timespec* %4 to i8*
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
store i32 0, i32* %9
%10 = bitcast %struct.timespec* %5 to i8*
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
store i32 0, i32* %11
%12 = load i32, i32* @CLOCK_MONOTONIC
%13 = call i32 @clock_getres(i32 %12, %struct.timespec* %3)
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @format_time(%struct.timespec* %3)
%17 = load i32, i32* @CLOCK_MONOTONIC
%18 = call i32 @xtime(i32 %17, %struct.timespec* %5)
br label %19
19: ; preds = %19, %2
%20 = load i32, i32* @CLOCK_MONOTONIC
%21 = call i32 @xtime(i32 %20, %struct.timespec* %4)
%22 = call i32 @format_timediff(%struct.timespec* %4, %struct.timespec* %5)
%23 = load i32, i32* %9
store i32 %23, i32* %11
br label %19
}