#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 scalar_t__ clockid_t;

/* Variables and functions */
scalar_t__ CLOCK_MONOTONIC;
scalar_t__ CLOCK_PROCESS_CPUTIME_ID;
scalar_t__ CLOCK_REALTIME;
scalar_t__ CLOCK_THREAD_CPUTIME_ID;
int clock_gettime(scalar_t__, struct timespec *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__, int /*<<< orphan*/,
                          int /*<<< orphan*/);
void time_resolutions(void) {
  clockid_t clocks[] = {CLOCK_REALTIME, CLOCK_MONOTONIC,
                        CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID,
                        (clockid_t)-1};
  int i;
  for (i = 0; clocks[i] != (clockid_t)-1; i++) {
    struct timespec ts;
    int ret;
    ret = clock_gettime(clocks[i], &ts);
    if (ret) {
      perror("clock_getres");
    } else {
      printf("clock=%d sec=%ld nsec=%ld\n", clocks[i], ts.tv_sec, ts.tv_nsec);
    }
  }
}


x86 assembly (clang, -O0):
<time_resolutions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmpq   $0xffffffffffffffff,-0x30(%rbp,%rax,8)
je     11ed <time_resolutions+0xbd>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     11bf <time_resolutions+0x8f>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
jmp    11da <time_resolutions+0xaa>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    11df <time_resolutions+0xaf>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117f <time_resolutions+0x4f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_resolutions>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%r13
mov    %r13,0x10(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
movq   $0xffffffffffffffff,0x30(%rsp)
ff ff
cmp    $0xffffffffffffffff,%r13
je     11db <time_resolutions+0xab>
lea    0x18(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xe74(%rip),%r15
lea    0xe60(%rip),%r12
mov    %r13,%rdi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
test   %eax,%eax
jne    11d1 <time_resolutions+0xa1>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    (%rbx),%r13
add    $0x8,%rbx
cmp    $0xffffffffffffffff,%r13
jne    11a0 <time_resolutions+0x70>
jmp    11db <time_resolutions+0xab>
mov    %r12,%rdi
call   1050 <perror@plt>
jmp    11c2 <time_resolutions+0x92>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i64 0
@CLOCK_MONOTONIC = global i64 0
@CLOCK_PROCESS_CPUTIME_ID = global i64 0
@CLOCK_THREAD_CPUTIME_ID = global i64 0
@.str = [13 x i8] c"clock_getres\00"
@.str.1 = [27 x i8] c"clock=%d sec=%ld nsec=%ld\0A\00"
define void @time_resolutions() {
%1 = alloca [5 x i64]
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 0
%6 = load i64, i64* @CLOCK_REALTIME
store i64 %6, i64* %5
%7 = getelementptr inbounds i64, i64* %5, i64 1
%8 = load i64, i64* @CLOCK_MONOTONIC
store i64 %8, i64* %7
%9 = getelementptr inbounds i64, i64* %7, i64 1
%10 = load i64, i64* @CLOCK_PROCESS_CPUTIME_ID
store i64 %10, i64* %9
%11 = getelementptr inbounds i64, i64* %9, i64 1
%12 = load i64, i64* @CLOCK_THREAD_CPUTIME_ID
store i64 %12, i64* %11
%13 = getelementptr inbounds i64, i64* %11, i64 1
store i64 -1, i64* %13
store i32 0, i32* %2
br label %14
14: ; preds = %41, %0
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 %16
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, -1
br i1 %19, label %20, label %44
20: ; preds = %14
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 %22
%24 = load i64, i64* %23
%25 = call i32 @clock_gettime(i64 %24, %struct.timespec* %3)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %40
30: ; preds = %20
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 %32
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %34, i32 %36, i32 %38)
br label %40
40: ; preds = %30, %28
br label %41
41: ; preds = %40
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %14
44: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i64 0
@CLOCK_MONOTONIC = global i64 0
@CLOCK_PROCESS_CPUTIME_ID = global i64 0
@CLOCK_THREAD_CPUTIME_ID = global i64 0
@.str = [13 x i8] c"clock_getres\00"
@.str.1 = [27 x i8] c"clock=%d sec=%ld nsec=%ld\0A\00"
define void @time_resolutions() {
%1 = alloca [5 x i64]
%2 = alloca %struct.timespec
%3 = bitcast [5 x i64]* %1 to i8*
%4 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 0
%5 = load i64, i64* @CLOCK_REALTIME
store i64 %5, i64* %4
%6 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 1
%7 = load i64, i64* @CLOCK_MONOTONIC
store i64 %7, i64* %6
%8 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 2
%9 = load i64, i64* @CLOCK_PROCESS_CPUTIME_ID
store i64 %9, i64* %8
%10 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 3
%11 = load i64, i64* @CLOCK_THREAD_CPUTIME_ID
store i64 %11, i64* %10
%12 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 4
store i64 -1, i64* %12
%13 = icmp eq i64 %5, -1
br i1 %13, label %34, label %14
14: ; preds = %0
%15 = bitcast %struct.timespec* %2 to i8*
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
br label %18
18: ; preds = %14, %29
%19 = phi i64 [ 0, %14 ], [ %30, %29 ]
%20 = phi i64 [ %5, %14 ], [ %32, %29 ]
%21 = call i32 @clock_gettime(i64 %20, %struct.timespec* %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %18
%26 = load i32, i32* %16
%27 = load i32, i32* %17
%28 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %20, i32 %26, i32 %27)
br label %29
29: ; preds = %25, %23
%30 = add nuw i64 %19, 1
%31 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i64 0, i64 %30
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, -1
br i1 %33, label %34, label %18
34: ; preds = %29, %0
ret void
}