#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_sec;
  int tv_nsec;
};
typedef int /*<<< orphan*/ cpumask;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ CPU_SET(unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ _SC_NPROCESSORS_CONF;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
struct timespec *malloc(unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sched_yield();
unsigned int sysconf(int /*<<< orphan*/);
int test_clock_jitter() {
  cpu_set_t cpumask;
  struct timespec *time;
  unsigned long nsec;
  unsigned slow_cpu, fast_cpu;
  double jitter;
  double largest_jitter = 0.0;
  unsigned cpu, num_cpus, iter;
  int failures = 0;
  num_cpus = sysconf(_SC_NPROCESSORS_CONF);
  if (num_cpus == 1) {
    printf("Single CPU detected. No clock jitter testing necessary.\n");
    return 0;
  }
  printf("Testing for clock jitter on %u cpus\n", num_cpus);
  time = malloc(num_cpus * sizeof(struct timespec));
  for (iter = 0; iter < 10000; iter++) {
    for (cpu = 0; cpu < num_cpus; cpu++) {
      CPU_ZERO(&cpumask);
      CPU_SET(cpu, &cpumask);
      if (sched_setaffinity(0, sizeof(cpumask), &cpumask) < 0) {
        perror("sched_setaffinity");
        return 1;
      }
      sched_yield();
      if (clock_gettime(CLOCK_REALTIME, &time[cpu]) < 0) {
        perror("clock_gettime");
        return 1;
      }
    }
    slow_cpu = fast_cpu = 0;
    for (cpu = 0; cpu < num_cpus; cpu++) {
      nsec = (time[cpu].tv_sec * 1000000000 + time[cpu].tv_nsec);
      if (nsec <
          (time[slow_cpu].tv_sec * 1000000000 + time[slow_cpu].tv_nsec)) {
        slow_cpu = cpu;
      }
      if (nsec >
          (time[fast_cpu].tv_sec * 1000000000 + time[fast_cpu].tv_nsec)) {
        fast_cpu = cpu;
      }
    }
    jitter = ((double)((time[fast_cpu].tv_sec * 1000000000 +
                        time[fast_cpu].tv_nsec) -
                       (time[slow_cpu].tv_sec * 1000000000 +
                        time[slow_cpu].tv_nsec)) /
              (double)1000000000);
    if (jitter > (double)0.2 || jitter < -(double)0.2) {
      printf("ERROR, jitter = %f\n", jitter);
      printf("iter = %u, cpus = %u,%u\n", iter, slow_cpu, fast_cpu);
      failures++;
    }
    if (jitter > largest_jitter)
      largest_jitter = jitter;
  }
  if (failures == 0)
    printf("PASSED, largest jitter seen was %lf\n", largest_jitter);
  else
    printf("FAILED, %u iterations failed\n", failures);
  return (failures > 0);
}


x86 assembly (clang, -O0):
<test_clock_jitter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jne    11dc <test_clock_jitter+0x4c>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    148b <test_clock_jitter+0x2fb>
mov    -0x38(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x2710,-0x3c(%rbp)
jae    1449 <test_clock_jitter+0x2b9>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jae    12c5 <test_clock_jitter+0x135>
lea    -0x8(%rbp),%rdi
call   1080 <CPU_ZERO@plt>
mov    -0x34(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   10b0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x8(%rbp),%rdx
call   1050 <sched_setaffinity@plt>
cmp    $0x0,%rax
jge    126d <test_clock_jitter+0xdd>
lea    0xe1a(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    148b <test_clock_jitter+0x2fb>
mov    $0x0,%al
call   1060 <sched_yield@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jge    12b2 <test_clock_jitter+0x122>
lea    0xde7(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    148b <test_clock_jitter+0x2fb>
jmp    12b7 <test_clock_jitter+0x127>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    121a <test_clock_jitter+0x8a>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jae    1376 <test_clock_jitter+0x1e6>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   $0x3b9aca00,(%rax,%rcx,8),%eax
mov    -0x10(%rbp),%rcx
mov    -0x34(%rbp),%edx
add    0x4(%rcx,%rdx,8),%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%edx
imul   $0x3b9aca00,(%rcx,%rdx,8),%ecx
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%esi
add    0x4(%rdx,%rsi,8),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1334 <test_clock_jitter+0x1a4>
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%edx
imul   $0x3b9aca00,(%rcx,%rdx,8),%ecx
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%esi
add    0x4(%rdx,%rsi,8),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jbe    1363 <test_clock_jitter+0x1d3>
mov    -0x34(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1368 <test_clock_jitter+0x1d8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12da <test_clock_jitter+0x14a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   $0x3b9aca00,(%rax,%rcx,8),%eax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%edx
add    0x4(%rcx,%rdx,8),%eax
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%edx
imul   $0x3b9aca00,(%rcx,%rdx,8),%ecx
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%esi
add    0x4(%rdx,%rsi,8),%ecx
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xc52(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xc34(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     13e9 <test_clock_jitter+0x259>
movsd  0xc32(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    141c <test_clock_jitter+0x28c>
movsd  -0x28(%rbp),%xmm0
lea    0xca1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xc9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1436 <test_clock_jitter+0x2a6>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    143b <test_clock_jitter+0x2ab>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1206 <test_clock_jitter+0x76>
cmpl   $0x0,-0x40(%rbp)
jne    146b <test_clock_jitter+0x2db>
movsd  -0x30(%rbp),%xmm0
lea    0xc64(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    147c <test_clock_jitter+0x2ec>
mov    -0x40(%rbp),%esi
lea    0xc73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x40(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_clock_jitter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
cmp    $0x1,%eax
jne    11d4 <test_clock_jitter+0x34>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1418 <test_clock_jitter+0x278>
mov    %eax,%ebx
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x0(,%rbx,8),%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %ebx,%r15d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
xor    %ebp,%ebp
mov    %rbx,0x10(%rsp)
jmp    1277 <test_clock_jitter+0xd7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe36(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
movsd  %xmm1,0x18(%rsp)
call   1050 <printf@plt>
lea    0xe32(%rip),%rdi
mov    0x4(%rsp),%ebp
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm1
addl   $0x1,(%rsp)
maxsd  0x8(%rsp),%xmm1
add    $0x1,%ebp
movsd  %xmm1,0x8(%rsp)
cmp    $0x2710,%ebp
je     13e6 <test_clock_jitter+0x246>
mov    %ebp,0x4(%rsp)
mov    $0x0,%r14d
mov    $0x0,%r12d
test   %ebx,%ebx
je     1370 <test_clock_jitter+0x1d0>
mov    %r13,%rbp
xor    %ebx,%ebx
lea    0x24(%rsp),%r14
mov    0x2d40(%rip),%r12
mov    %r14,%rdi
call   1090 <CPU_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   10c0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1060 <sched_setaffinity@plt>
test   %rax,%rax
js     13ca <test_clock_jitter+0x22a>
xor    %eax,%eax
call   1070 <sched_yield@plt>
mov    (%r12),%edi
mov    %rbp,%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     13d3 <test_clock_jitter+0x233>
add    $0x1,%rbx
add    $0x8,%rbp
cmp    %rbx,%r15
jne    12a0 <test_clock_jitter+0x100>
mov    $0x0,%r14d
mov    $0x0,%r12d
mov    0x10(%rsp),%rbx
test   %ebx,%ebx
je     1370 <test_clock_jitter+0x1d0>
xor    %eax,%eax
xor    %edx,%edx
xor    %ecx,%ecx
jmp    131f <test_clock_jitter+0x17f>
add    $0x1,%rax
mov    %r12d,%edx
mov    %r14d,%ecx
cmp    %rax,%r15
je     1370 <test_clock_jitter+0x1d0>
imul   $0x3b9aca00,0x0(%r13,%rax,8),%esi
9a 3b
add    0x4(%r13,%rax,8),%esi
mov    %edx,%edi
imul   $0x3b9aca00,0x0(%r13,%rdi,8),%ebp
9a 3b
add    0x4(%r13,%rdi,8),%ebp
mov    %eax,%r12d
cmp    %ebp,%esi
jb     1347 <test_clock_jitter+0x1a7>
mov    %edx,%r12d
mov    %ecx,%edx
imul   $0x3b9aca00,0x0(%r13,%rdx,8),%edi
9a 3b
add    0x4(%r13,%rdx,8),%edi
mov    %eax,%r14d
cmp    %edi,%esi
ja     1310 <test_clock_jitter+0x170>
mov    %ecx,%r14d
jmp    1310 <test_clock_jitter+0x170>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%eax
mov    0x0(%r13,%rax,8),%ecx
mov    0x4(%r13,%rax,8),%eax
mov    %r12d,%edx
sub    0x0(%r13,%rdx,8),%ecx
sub    0x4(%r13,%rdx,8),%eax
imul   $0x3b9aca00,%ecx,%ecx
add    %ecx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  0xc5f(%rip),%xmm1
ucomisd 0xc5f(%rip),%xmm1
ja     1220 <test_clock_jitter+0x80>
movsd  0xc59(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1220 <test_clock_jitter+0x80>
mov    0x4(%rsp),%ebp
jmp    125c <test_clock_jitter+0xbc>
lea    0xc6c(%rip),%rdi
jmp    13da <test_clock_jitter+0x23a>
lea    0xc75(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    1418 <test_clock_jitter+0x278>
mov    (%rsp),%ebx
test   %ebx,%ebx
je     13ff <test_clock_jitter+0x25f>
lea    0xcbb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1411 <test_clock_jitter+0x271>
lea    0xc84(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
test   %ebx,%ebx
setg   %al
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [57 x i8] c"Single CPU detected. No clock jitter testing necessary.\0A\00"
@.str.1 = [37 x i8] c"Testing for clock jitter on %u cpus\0A\00"
@.str.2 = [18 x i8] c"sched_setaffinity\00"
@CLOCK_REALTIME = global i32 0
@.str.3 = [14 x i8] c"clock_gettime\00"
@.str.4 = [20 x i8] c"ERROR, jitter = %f\0A\00"
@.str.5 = [25 x i8] c"iter = %u, cpus = %u,%u\0A\00"
@.str.6 = [37 x i8] c"PASSED, largest jitter seen was %lf\0A\00"
@.str.7 = [30 x i8] c"FAILED, %u iterations failed\0A\00"
define i32 @test_clock_jitter() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timespec*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double 0.000000e+00, double* %8
store i32 0, i32* %12
%13 = load i32, i32* @_SC_NPROCESSORS_CONF
%14 = call i32 @sysconf(i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %191
19: ; preds = %0
%20 = load i32, i32* %10
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %10
%23 = zext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call %struct.timespec* @malloc(i32 %25)
store %struct.timespec* %26, %struct.timespec** %3
store i32 0, i32* %11
br label %27
27: ; preds = %175, %19
%28 = load i32, i32* %11
%29 = icmp ult i32 %28, 10000
br i1 %29, label %30, label %178
30: ; preds = %27
store i32 0, i32* %9
br label %31
31: ; preds = %55, %30
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = icmp ult i32 %32, %33
br i1 %34, label %35, label %58
35: ; preds = %31
%36 = call i32 @CPU_ZERO(i32* %2)
%37 = load i32, i32* %9
%38 = call i32 @CPU_SET(i32 %37, i32* %2)
%39 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %2)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %191
43: ; preds = %35
%44 = call i32 (...) @sched_yield()
%45 = load i32, i32* @CLOCK_REALTIME
%46 = load %struct.timespec*, %struct.timespec** %3
%47 = load i32, i32* %9
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds %struct.timespec, %struct.timespec* %46, i64 %48
%50 = call i64 @clock_gettime(i32 %45, %struct.timespec* %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %43
%53 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %191
54: ; preds = %43
br label %55
55: ; preds = %54
%56 = load i32, i32* %9
%57 = add i32 %56, 1
store i32 %57, i32* %9
br label %31
58: ; preds = %31
store i32 0, i32* %6
store i32 0, i32* %5
store i32 0, i32* %9
br label %59
59: ; preds = %119, %58
%60 = load i32, i32* %9
%61 = load i32, i32* %10
%62 = icmp ult i32 %60, %61
br i1 %62, label %63, label %122
63: ; preds = %59
%64 = load %struct.timespec*, %struct.timespec** %3
%65 = load i32, i32* %9
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds %struct.timespec, %struct.timespec* %64, i64 %66
%68 = getelementptr inbounds %struct.timespec, %struct.timespec* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = mul nsw i32 %69, 1000000000
%71 = load %struct.timespec*, %struct.timespec** %3
%72 = load i32, i32* %9
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds %struct.timespec, %struct.timespec* %71, i64 %73
%75 = getelementptr inbounds %struct.timespec, %struct.timespec* %74, i32 0, i32 1
%76 = load i32, i32* %75
%77 = add nsw i32 %70, %76
%78 = sext i32 %77 to i64
store i64 %78, i64* %4
%79 = load i64, i64* %4
%80 = load %struct.timespec*, %struct.timespec** %3
%81 = load i32, i32* %5
%82 = zext i32 %81 to i64
%83 = getelementptr inbounds %struct.timespec, %struct.timespec* %80, i64 %82
%84 = getelementptr inbounds %struct.timespec, %struct.timespec* %83, i32 0, i32 0
%85 = load i32, i32* %84
%86 = mul nsw i32 %85, 1000000000
%87 = load %struct.timespec*, %struct.timespec** %3
%88 = load i32, i32* %5
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds %struct.timespec, %struct.timespec* %87, i64 %89
%91 = getelementptr inbounds %struct.timespec, %struct.timespec* %90, i32 0, i32 1
%92 = load i32, i32* %91
%93 = add nsw i32 %86, %92
%94 = sext i32 %93 to i64
%95 = icmp ult i64 %79, %94
br i1 %95, label %96, label %98
96: ; preds = %63
%97 = load i32, i32* %9
store i32 %97, i32* %5
br label %98
98: ; preds = %96, %63
%99 = load i64, i64* %4
%100 = load %struct.timespec*, %struct.timespec** %3
%101 = load i32, i32* %6
%102 = zext i32 %101 to i64
%103 = getelementptr inbounds %struct.timespec, %struct.timespec* %100, i64 %102
%104 = getelementptr inbounds %struct.timespec, %struct.timespec* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = mul nsw i32 %105, 1000000000
%107 = load %struct.timespec*, %struct.timespec** %3
%108 = load i32, i32* %6
%109 = zext i32 %108 to i64
%110 = getelementptr inbounds %struct.timespec, %struct.timespec* %107, i64 %109
%111 = getelementptr inbounds %struct.timespec, %struct.timespec* %110, i32 0, i32 1
%112 = load i32, i32* %111
%113 = add nsw i32 %106, %112
%114 = sext i32 %113 to i64
%115 = icmp ugt i64 %99, %114
br i1 %115, label %116, label %118
116: ; preds = %98
%117 = load i32, i32* %9
store i32 %117, i32* %6
br label %118
118: ; preds = %116, %98
br label %119
119: ; preds = %118
%120 = load i32, i32* %9
%121 = add i32 %120, 1
store i32 %121, i32* %9
br label %59
122: ; preds = %59
%123 = load %struct.timespec*, %struct.timespec** %3
%124 = load i32, i32* %6
%125 = zext i32 %124 to i64
%126 = getelementptr inbounds %struct.timespec, %struct.timespec* %123, i64 %125
%127 = getelementptr inbounds %struct.timespec, %struct.timespec* %126, i32 0, i32 0
%128 = load i32, i32* %127
%129 = mul nsw i32 %128, 1000000000
%130 = load %struct.timespec*, %struct.timespec** %3
%131 = load i32, i32* %6
%132 = zext i32 %131 to i64
%133 = getelementptr inbounds %struct.timespec, %struct.timespec* %130, i64 %132
%134 = getelementptr inbounds %struct.timespec, %struct.timespec* %133, i32 0, i32 1
%135 = load i32, i32* %134
%136 = add nsw i32 %129, %135
%137 = load %struct.timespec*, %struct.timespec** %3
%138 = load i32, i32* %5
%139 = zext i32 %138 to i64
%140 = getelementptr inbounds %struct.timespec, %struct.timespec* %137, i64 %139
%141 = getelementptr inbounds %struct.timespec, %struct.timespec* %140, i32 0, i32 0
%142 = load i32, i32* %141
%143 = mul nsw i32 %142, 1000000000
%144 = load %struct.timespec*, %struct.timespec** %3
%145 = load i32, i32* %5
%146 = zext i32 %145 to i64
%147 = getelementptr inbounds %struct.timespec, %struct.timespec* %144, i64 %146
%148 = getelementptr inbounds %struct.timespec, %struct.timespec* %147, i32 0, i32 1
%149 = load i32, i32* %148
%150 = add nsw i32 %143, %149
%151 = sub nsw i32 %136, %150
%152 = sitofp i32 %151 to double
%153 = fdiv double %152, 1.000000e+09
store double %153, double* %7
%154 = load double, double* %7
%155 = fcmp ogt double %154, 2.000000e-01
br i1 %155, label %159, label %156
156: ; preds = %122
%157 = load double, double* %7
%158 = fcmp olt double %157, -2.000000e-01
br i1 %158, label %159, label %168
159: ; preds = %156, %122
%160 = load double, double* %7
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %160)
%162 = load i32, i32* %11
%163 = load i32, i32* %5
%164 = load i32, i32* %6
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %162, i32 %163, i32 %164)
%166 = load i32, i32* %12
%167 = add nsw i32 %166, 1
store i32 %167, i32* %12
br label %168
168: ; preds = %159, %156
%169 = load double, double* %7
%170 = load double, double* %8
%171 = fcmp ogt double %169, %170
br i1 %171, label %172, label %174
172: ; preds = %168
%173 = load double, double* %7
store double %173, double* %8
br label %174
174: ; preds = %172, %168
br label %175
175: ; preds = %174
%176 = load i32, i32* %11
%177 = add i32 %176, 1
store i32 %177, i32* %11
br label %27
178: ; preds = %27
%179 = load i32, i32* %12
%180 = icmp eq i32 %179, 0
br i1 %180, label %181, label %184
181: ; preds = %178
%182 = load double, double* %8
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), double %182)
br label %187
184: ; preds = %178
%185 = load i32, i32* %12
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %185)
br label %187
187: ; preds = %184, %181
%188 = load i32, i32* %12
%189 = icmp sgt i32 %188, 0
%190 = zext i1 %189 to i32
store i32 %190, i32* %1
br label %191
191: ; preds = %187, %52, %41, %17
%192 = load i32, i32* %1
ret i32 %192
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@_SC_NPROCESSORS_CONF = global i32 0
@.str.1 = [37 x i8] c"Testing for clock jitter on %u cpus\0A\00"
@.str.2 = [18 x i8] c"sched_setaffinity\00"
@CLOCK_REALTIME = global i32 0
@.str.3 = [14 x i8] c"clock_gettime\00"
@.str.4 = [20 x i8] c"ERROR, jitter = %f\0A\00"
@.str.5 = [25 x i8] c"iter = %u, cpus = %u,%u\0A\00"
@.str.6 = [37 x i8] c"PASSED, largest jitter seen was %lf\0A\00"
@.str.7 = [30 x i8] c"FAILED, %u iterations failed\0A\00"
@str = [56 x i8] c"Single CPU detected. No clock jitter testing necessary.\00"
define i32 @test_clock_jitter() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @_SC_NPROCESSORS_CONF
%4 = tail call i32 @sysconf(i32 %3)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %112
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%10 = shl i32 %4, 3
%11 = tail call %struct.timespec* @malloc(i32 %10)
%12 = icmp eq i32 %4, 0
%13 = zext i32 %4 to i64
%14 = zext i32 %4 to i64
br label %15
15: ; preds = %8, %97
%16 = phi i32 [ 0, %8 ], [ %98, %97 ]
%17 = phi i32 [ 0, %8 ], [ %101, %97 ]
%18 = phi double [ 0.000000e+00, %8 ], [ %100, %97 ]
br i1 %12, label %71, label %22
19: ; preds = %31
%20 = icmp eq i64 %37, %13
br i1 %20, label %21, label %22
21: ; preds = %19
br i1 %12, label %71, label %40
22: ; preds = %15, %19
%23 = phi i64 [ %37, %19 ], [ 0, %15 ]
%24 = call i32 @CPU_ZERO(i32* %1)
%25 = trunc i64 %23 to i32
%26 = call i32 @CPU_SET(i32 %25, i32* %1)
%27 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %1)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %112
31: ; preds = %22
%32 = call i32 (...) @sched_yield()
%33 = load i32, i32* @CLOCK_REALTIME
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %23
%35 = call i64 @clock_gettime(i32 %33, %struct.timespec* %34)
%36 = icmp slt i64 %35, 0
%37 = add nuw nsw i64 %23, 1
br i1 %36, label %38, label %19
38: ; preds = %31
%39 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %112
40: ; preds = %21, %40
%41 = phi i64 [ %69, %40 ], [ 0, %21 ]
%42 = phi i32 [ %59, %40 ], [ 0, %21 ]
%43 = phi i32 [ %68, %40 ], [ 0, %21 ]
%44 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %41, i32 0
%45 = load i32, i32* %44
%46 = mul nsw i32 %45, 1000000000
%47 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %41, i32 1
%48 = load i32, i32* %47
%49 = add nsw i32 %46, %48
%50 = zext i32 %42 to i64
%51 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %50, i32 0
%52 = load i32, i32* %51
%53 = mul nsw i32 %52, 1000000000
%54 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %50, i32 1
%55 = load i32, i32* %54
%56 = add nsw i32 %53, %55
%57 = icmp ult i32 %49, %56
%58 = trunc i64 %41 to i32
%59 = select i1 %57, i32 %58, i32 %42
%60 = zext i32 %43 to i64
%61 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %60, i32 0
%62 = load i32, i32* %61
%63 = mul nsw i32 %62, 1000000000
%64 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %60, i32 1
%65 = load i32, i32* %64
%66 = add nsw i32 %63, %65
%67 = icmp ugt i32 %49, %66
%68 = select i1 %67, i32 %58, i32 %43
%69 = add nuw nsw i64 %41, 1
%70 = icmp eq i64 %69, %14
br i1 %70, label %71, label %40
71: ; preds = %40, %15, %21
%72 = phi i32 [ 0, %21 ], [ 0, %15 ], [ %68, %40 ]
%73 = phi i32 [ 0, %21 ], [ 0, %15 ], [ %59, %40 ]
%74 = zext i32 %72 to i64
%75 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %74, i32 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %74, i32 1
%78 = load i32, i32* %77
%79 = zext i32 %73 to i64
%80 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %79, i32 0
%81 = load i32, i32* %80
%82 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 %79, i32 1
%83 = load i32, i32* %82
%84 = sub i32 %76, %81
%85 = mul i32 %84, 1000000000
%86 = sub i32 %78, %83
%87 = add i32 %86, %85
%88 = sitofp i32 %87 to double
%89 = fdiv double %88, 1.000000e+09
%90 = fcmp ogt double %89, 2.000000e-01
%91 = fcmp olt double %89, -2.000000e-01
%92 = or i1 %90, %91
br i1 %92, label %93, label %97
93: ; preds = %71
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %89)
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 %73, i32 %72)
%96 = add nsw i32 %16, 1
br label %97
97: ; preds = %71, %93
%98 = phi i32 [ %96, %93 ], [ %16, %71 ]
%99 = fcmp ogt double %89, %18
%100 = select i1 %99, double %89, double %18
%101 = add nuw nsw i32 %17, 1
%102 = icmp eq i32 %101, 10000
br i1 %102, label %103, label %15
103: ; preds = %97
%104 = icmp eq i32 %98, 0
br i1 %104, label %105, label %107
105: ; preds = %103
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), double %100)
br label %109
107: ; preds = %103
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %98)
br label %109
109: ; preds = %107, %105
%110 = icmp sgt i32 %98, 0
%111 = zext i1 %110 to i32
br label %112
112: ; preds = %109, %38, %29, %6
%113 = phi i32 [ 0, %6 ], [ 1, %29 ], [ 1, %38 ], [ %111, %109 ]
ret i32 %113
}