#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 tv_nsec;
  scalar_t__ tv_sec;
};
typedef int clockid_t;

/* Variables and functions */
scalar_t__ clock_getres(int, struct timespec *);
scalar_t__ clock_gettime(int, struct timespec *);
scalar_t__ memcmp(struct timespec *, struct timespec *, int);
int /*<<< orphan*/ memset(struct timespec *, char, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, ...);
int clock_test(clockid_t cl) {
  struct timespec old_ts;
  struct timespec ts;
  struct timespec waitit;
  int result = 0;
  int i;
  memset(&ts, '\0', sizeof ts);
  waitit.tv_sec = 0;
  waitit.tv_nsec = 500000000;
  if (clock_getres(cl, &ts) == 0) {
    if (ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000) {
      printf("clock %d: nanosecond value of resolution wrong\n", cl);
      result = 1;
    } else
      printf("clock %d: resolution = %ld.%09ld secs\n", cl, ts.tv_sec,
             ts.tv_nsec);
  } else {
    printf("clock %d: cannot get resolution\n", cl);
    result = 1;
  }
  memset(&ts, '\0', sizeof ts);
  memset(&old_ts, '\0', sizeof old_ts);
  for (i = 0; i < 10; ++i) {
    if (clock_gettime(cl, &ts) == 0) {
      if (ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000) {
        printf("clock %d: nanosecond value of time wrong (try %d)\n", cl, i);
        result = 1;
      } else {
        printf("clock %d: time = %ld.%09ld secs\n", cl, ts.tv_sec, ts.tv_nsec);
        if (memcmp(&ts, &old_ts, sizeof ts) == 0) {
          printf("clock %d: time hasn't changed (try %d)\n", cl, i);
          result = 1;
          old_ts = ts;
        }
      }
    } else {
      printf("clock %d: cannot get time (try %d)\n", cl, i);
      result = 1;
    }
    nanosleep(&waitit, NULL);
  }
  return result;
}


x86 assembly (clang, -O0):
<clock_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movq   $0x0,-0x30(%rbp)
movl   $0x1dcd6500,-0x38(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1080 <clock_getres@plt>
cmp    $0x0,%rax
jne    11f8 <clock_test+0x98>
cmpl   $0x0,-0x28(%rbp)
jl     11be <clock_test+0x5e>
cmpl   $0x3b9aca00,-0x28(%rbp)
jl     11db <clock_test+0x7b>
mov    -0x4(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
jmp    11f3 <clock_test+0x93>
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%ecx
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1210 <clock_test+0xb0>
mov    -0x4(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movl   $0x0,-0x40(%rbp)
cmpl   $0xa,-0x40(%rbp)
jge    132d <clock_test+0x1cd>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jne    12f7 <clock_test+0x197>
cmpl   $0x0,-0x28(%rbp)
jl     126e <clock_test+0x10e>
cmpl   $0x3b9aca00,-0x28(%rbp)
jl     128e <clock_test+0x12e>
mov    -0x4(%rbp),%esi
mov    -0x40(%rbp),%edx
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
jmp    12f2 <clock_test+0x192>
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%ecx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    12ed <clock_test+0x18d>
mov    -0x4(%rbp),%esi
mov    -0x40(%rbp),%edx
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    12f2 <clock_test+0x192>
jmp    1312 <clock_test+0x1b2>
mov    -0x4(%rbp),%esi
mov    -0x40(%rbp),%edx
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1237 <clock_test+0xd7>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movq   $0x0,0x30(%rsp)
movl   $0x1dcd6500,0x28(%rsp)
1d
mov    %ebx,%edi
mov    %rbp,%rsi
call   1080 <clock_getres@plt>
test   %rax,%rax
je     11ab <clock_test+0x4b>
lea    0xeae(%rip),%rdi
jmp    11bd <clock_test+0x5d>
mov    (%rsp),%ecx
cmp    $0x3b9aca00,%ecx
jb     11cd <clock_test+0x6d>
lea    0xe43(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    11e4 <clock_test+0x84>
mov    0x8(%rsp),%rdx
lea    0xe57(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0x28(%rsp),%r12
lea    0xee1(%rip),%r13
xor    %r15d,%r15d
jmp    1248 <clock_test+0xe8>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <nanosleep@plt>
add    $0x1,%r15d
cmp    $0xa,%r15d
je     12b8 <clock_test+0x158>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    1220 <clock_test+0xc0>
mov    (%rsp),%ecx
cmp    $0x3b9aca00,%ecx
jb     126b <clock_test+0x10b>
lea    0xe0f(%rip),%rdi
jmp    1223 <clock_test+0xc3>
mov    0x8(%rsp),%rdx
lea    0xe34(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1234 <clock_test+0xd4>
lea    0xe2e(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movups (%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
jmp    122f <clock_test+0xcf>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [48 x i8] c"clock %d: nanosecond value of resolution wrong\0A\00"
@.str.1 = [39 x i8] c"clock %d: resolution = %ld.%09ld secs\0A\00"
@.str.2 = [33 x i8] c"clock %d: cannot get resolution\0A\00"
@.str.3 = [51 x i8] c"clock %d: nanosecond value of time wrong (try %d)\0A\00"
@.str.4 = [33 x i8] c"clock %d: time = %ld.%09ld secs\0A\00"
@.str.5 = [40 x i8] c"clock %d: time hasn't changed (try %d)\0A\00"
@.str.6 = [36 x i8] c"clock %d: cannot get time (try %d)\0A\00"
define i32 @clock_test(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %6
%8 = call i32 @memset(%struct.timespec* %4, i8 signext 0, i32 16)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i32 500000000, i32* %10
%11 = load i32, i32* %2
%12 = call i64 @clock_getres(i32 %11, %struct.timespec* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %1
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp slt i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = icmp sge i32 %20, 1000000000
br i1 %21, label %22, label %25
22: ; preds = %18, %14
%23 = load i32, i32* %2
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 1, i32* %6
br label %32
25: ; preds = %18
%26 = load i32, i32* %2
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %26, i64 %28, i32 %30)
br label %32
32: ; preds = %25, %22
br label %36
33: ; preds = %1
%34 = load i32, i32* %2
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %34)
store i32 1, i32* %6
br label %36
36: ; preds = %33, %32
%37 = call i32 @memset(%struct.timespec* %4, i8 signext 0, i32 16)
%38 = call i32 @memset(%struct.timespec* %3, i8 signext 0, i32 16)
store i32 0, i32* %7
br label %39
39: ; preds = %81, %36
%40 = load i32, i32* %7
%41 = icmp slt i32 %40, 10
br i1 %41, label %42, label %84
42: ; preds = %39
%43 = load i32, i32* %2
%44 = call i64 @clock_gettime(i32 %43, %struct.timespec* %4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %75
46: ; preds = %42
%47 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%48 = load i32, i32* %47
%49 = icmp slt i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%52 = load i32, i32* %51
%53 = icmp sge i32 %52, 1000000000
br i1 %53, label %54, label %58
54: ; preds = %50, %46
%55 = load i32, i32* %2
%56 = load i32, i32* %7
%57 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %55, i32 %56)
store i32 1, i32* %6
br label %74
58: ; preds = %50
%59 = load i32, i32* %2
%60 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%61 = load i64, i64* %60
%62 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %59, i64 %61, i32 %63)
%65 = call i64 @memcmp(%struct.timespec* %4, %struct.timespec* %3, i32 16)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %58
%68 = load i32, i32* %2
%69 = load i32, i32* %7
%70 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %68, i32 %69)
store i32 1, i32* %6
%71 = bitcast %struct.timespec* %3 to i8*
%72 = bitcast %struct.timespec* %4 to i8*
br label %73
73: ; preds = %67, %58
br label %74
74: ; preds = %73, %54
br label %79
75: ; preds = %42
%76 = load i32, i32* %2
%77 = load i32, i32* %7
%78 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %76, i32 %77)
store i32 1, i32* %6
br label %79
79: ; preds = %75, %74
%80 = call i32 @nanosleep(%struct.timespec* %5, i32* null)
br label %81
81: ; preds = %79
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 1
store i32 %83, i32* %7
br label %39
84: ; preds = %39
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [48 x i8] c"clock %d: nanosecond value of resolution wrong\0A\00"
@.str.1 = [39 x i8] c"clock %d: resolution = %ld.%09ld secs\0A\00"
@.str.2 = [33 x i8] c"clock %d: cannot get resolution\0A\00"
@.str.3 = [51 x i8] c"clock %d: nanosecond value of time wrong (try %d)\0A\00"
@.str.4 = [33 x i8] c"clock %d: time = %ld.%09ld secs\0A\00"
@.str.5 = [40 x i8] c"clock %d: time hasn't changed (try %d)\0A\00"
@.str.6 = [36 x i8] c"clock %d: cannot get time (try %d)\0A\00"
define i32 @clock_test(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %2 to i8*
%6 = bitcast %struct.timespec* %3 to i8*
%7 = bitcast %struct.timespec* %4 to i8*
%8 = call i32 @memset(%struct.timespec* %3, i8 signext 0, i32 16)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
store i32 500000000, i32* %10
%11 = call i64 @clock_getres(i32 %0, %struct.timespec* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = icmp ugt i32 %15, 999999999
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %25
19: ; preds = %13
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%21 = load i64, i64* %20
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %0, i64 %21, i32 %15)
br label %25
23: ; preds = %1
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %25
25: ; preds = %17, %19, %23
%26 = phi i32 [ 1, %17 ], [ 0, %19 ], [ 1, %23 ]
%27 = call i32 @memset(%struct.timespec* %3, i8 signext 0, i32 16)
%28 = call i32 @memset(%struct.timespec* %2, i8 signext 0, i32 16)
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
br label %31
31: ; preds = %25, %50
%32 = phi i32 [ 0, %25 ], [ %53, %50 ]
%33 = phi i32 [ %26, %25 ], [ %51, %50 ]
%34 = call i64 @clock_gettime(i32 %0, %struct.timespec* %3)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %31
%37 = load i32, i32* %29
%38 = icmp ugt i32 %37, 999999999
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %32)
br label %50
41: ; preds = %36
%42 = load i64, i64* %30
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %0, i64 %42, i32 %37)
%44 = call i64 @memcmp(%struct.timespec* %3, %struct.timespec* %2, i32 16)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %0, i32 %32)
br label %50
48: ; preds = %31
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %0, i32 %32)
br label %50
50: ; preds = %39, %46, %41, %48
%51 = phi i32 [ 1, %39 ], [ 1, %46 ], [ %33, %41 ], [ 1, %48 ]
%52 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
%53 = add nuw nsw i32 %32, 1
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %31
55: ; preds = %50
ret i32 %51
}