#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 {
  long tv_nsec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ TIMER_ABSTIME;
long atol(char *);
long calcdiff_us(struct timespec, struct timespec);
int *calloc(int, int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/,
                                   struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setSchedPrio_noerrcheck();
int /*<<< orphan*/ tsnorm(struct timespec *);
int main(int argc, char *argv[]) {
  struct timespec t1, tm1, tm2, tabs, tabs2;
  long period_us, duration;
  if (argc > 2) {
    period_us = atol(argv[1]);
    duration = atol(argv[2]);
  } else {
    period_us = 500;
    duration = 5;
  }
  printf("period: %ldus, total test time: %ld\n", period_us, duration);
  setSchedPrio_noerrcheck();
  double i, i_max, i_min, sum = 0;
  long min = 1E9L, max = 0, diff;
  double lim = (1E6F / (double)period_us) * duration;
  int *jit;
  printf("testing for %ld seconds\n ...\n", duration);
  if (lim < 0x7fffffff && 4 == 4) {
    jit = calloc((int)lim, sizeof(int));
    if (jit == NULL) {
      printf("not enough memory\n");
      return -1;
    }
  } else {
    printf("too much steps\n");
    return -1;
  }
  clock_gettime(CLOCK_REALTIME, &t1);
  tm2.tv_sec = 0;
  tm2.tv_nsec = 1E9L - t1.tv_nsec - 300;
  nanosleep(&tm2, NULL);
  clock_gettime(CLOCK_MONOTONIC, &t1);
  for (i = 0; i < lim; i++) {
    t1.tv_nsec += period_us * 1E3;
    tsnorm(&t1);
    tm2 = tm1;
    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t1, NULL);
    clock_gettime(CLOCK_MONOTONIC, &tm1);
    tabs2 = tabs;
    clock_gettime(CLOCK_REALTIME, &tabs);
    if (i == 0) {
      continue;
    }
    *(jit + (int)i) = (int)(calcdiff_us(tabs, tabs2) - period_us);
    diff = period_us - calcdiff_us(tm1, tm2);
    if (diff > max) {
      max = diff;
      i_max = i;
    }
    if (diff < min) {
      min = diff;
      i_min = i;
    }
    sum += (double)diff;
    if (sum > ((double)1.79769313486231570814527423731704357e+308L) / 10)
      break;
  }
  printf("loops: [%.0f], avg: %lfus, min: %ldus @ %.3fs, max: %ldus @ %.3fs\n",
         i, sum / i, min, i_min / i * (double)duration, max,
         i_max / i * (double)duration);
  int bins = (int)(max - min + 1);
  int *hist = calloc(bins, sizeof(int));
  if (hist == NULL) {
    printf("not enough memory\n");
    return -1;
  }
  int j, in;
  for (j = 0; j < (int)lim; j++) {
    in = *(jit + j) - (int)min + 1;
    *(hist + in) = *(hist + in) + 1;
  }
  FILE *fp;
  fp = fopen("/home/pi/rpilogger/test/nanosleep.json", "w");
  fprintf(fp, "");
  for (in = 0; in < lim - 1; in++)
    fprintf(fp, "%d,", *(jit + in));
  fprintf(fp, "%d\n", *(jit + in));
  fclose(fp);
  free(jit);
  printf("histogram saved in %s\n", "/home/pi/rpilogger/test/nanosleep.json");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    121a <main+0x4a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atol@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atol@plt>
mov    %rax,-0x70(%rbp)
jmp    122a <main+0x5a>
movq   $0x1f4,-0x68(%rbp)
movq   $0x5,-0x70(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10a0 <setSchedPrio_noerrcheck@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movq   $0x3b9aca00,-0x98(%rbp)
movq   $0x0,-0xa0(%rbp)
cvtsi2sdq -0x68(%rbp),%xmm1
movsd  0xd92(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsi2sdq -0x70(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0x70(%rbp),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsd  0xd5a(%rip),%xmm0
ucomisd -0xb0(%rbp),%xmm0
ff
jbe    12fa <main+0x12a>
cvttsd2si -0xb0(%rbp),%edi
ff
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    12f5 <main+0x125>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a0 <main+0x5d0>
jmp    1314 <main+0x144>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a0 <main+0x5d0>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <clock_gettime@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0xe8(%rbp)
fildll -0xe8(%rbp)
flds   0xce3(%rip)
fsubp  %st,%st(1)
flds   0xcdf(%rip)
faddp  %st,%st(1)
fnstcw -0xea(%rbp)
movzwl -0xea(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0xec(%rbp)
fldcw  -0xec(%rbp)
fistpll -0xe0(%rbp)
fldcw  -0xea(%rbp)
mov    -0xe0(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <nanosleep@plt>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <clock_gettime@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
ucomisd %xmm1,%xmm0
jbe    1581 <main+0x3b1>
cvtsi2sdq -0x68(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xc39(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   10b0 <tsnorm@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2bd8(%rip),%rax
mov    (%rax),%edi
mov    0x2bd7(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   10e0 <clock_nanosleep@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1040 <clock_gettime@plt>
movsd  -0x78(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1471 <main+0x2a1>
jp     1471 <main+0x2a1>
jmp    156a <main+0x39a>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rcx
call   10f0 <calcdiff_us@plt>
sub    -0x68(%rbp),%rax
mov    %eax,%edx
mov    -0xb8(%rbp),%rax
cvttsd2si -0x78(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x68(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   10f0 <calcdiff_us@plt>
mov    %rax,%rcx
mov    -0xf8(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
cmp    -0xa0(%rbp),%rax
jle    14fe <main+0x32e>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0xa8(%rbp),%rax
cmp    -0x98(%rbp),%rax
jge    152d <main+0x35d>
mov    -0xa8(%rbp),%rax
mov    %rax,-0x98(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
cvtsi2sdq -0xa8(%rbp),%xmm0
ff ff
addsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  0xac2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1565 <main+0x395>
jmp    1581 <main+0x3b1>
jmp    156a <main+0x39a>
movsd  0xaae(%rip),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    13ac <main+0x1dc>
movsd  -0x78(%rbp),%xmm0
movsd  -0x90(%rbp),%xmm1
ff
divsd  -0x78(%rbp),%xmm1
mov    -0x98(%rbp),%rsi
movsd  -0x88(%rbp),%xmm2
ff
divsd  -0x78(%rbp),%xmm2
cvtsi2sdq -0x70(%rbp),%xmm3
mulsd  %xmm3,%xmm2
mov    -0xa0(%rbp),%rdx
movsd  -0x80(%rbp),%xmm3
divsd  -0x78(%rbp),%xmm3
cvtsi2sdq -0x70(%rbp),%xmm4
mulsd  %xmm4,%xmm3
lea    0xac3(%rip),%rdi
mov    $0x4,%al
call   1060 <printf@plt>
mov    -0xa0(%rbp),%rax
sub    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0xbc(%rbp)
mov    -0xbc(%rbp),%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    1631 <main+0x461>
lea    0xa55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a0 <main+0x5d0>
movl   $0x0,-0xcc(%rbp)
mov    -0xcc(%rbp),%eax
cvttsd2si -0xb0(%rbp),%ecx
ff
cmp    %ecx,%eax
jge    16ad <main+0x4dd>
mov    -0xb8(%rbp),%rax
movslq -0xcc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x98(%rbp),%rcx
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0xd0(%rbp)
mov    -0xc8(%rbp),%rax
movslq -0xd0(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    -0xc8(%rbp),%rax
movslq -0xd0(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xcc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xcc(%rbp)
jmp    163b <main+0x46b>
lea    0xa25(%rip),%rdi
lea    0xa45(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
lea    0x99d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0xd0(%rbp)
cvtsi2sdl -0xd0(%rbp),%xmm1
ff
movsd  -0xb0(%rbp),%xmm0
ff
movsd  0x922(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1746 <main+0x576>
mov    -0xd8(%rbp),%rdi
mov    -0xb8(%rbp),%rax
movslq -0xd0(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0x9d7(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0xd0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd0(%rbp)
jmp    16e6 <main+0x516>
mov    -0xd8(%rbp),%rdi
mov    -0xb8(%rbp),%rax
movslq -0xd0(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0x9a1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0xd8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0xb8(%rbp),%rdi
call   1030 <free@plt>
lea    0x97f(%rip),%rdi
lea    0x947(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
cmp    $0x3,%edi
jl     1213 <main+0x33>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10d0 <atol@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
call   10d0 <atol@plt>
mov    %rax,%rbx
jmp    121e <main+0x3e>
mov    $0x1f4,%r15d
mov    $0x5,%ebx
lea    0xe1b(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10b0 <setSchedPrio_noerrcheck@plt>
cvtsi2sd %r15,%xmm0
movsd  0xdba(%rip),%xmm1
movsd  %xmm0,0x28(%rsp)
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x88(%rsp)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xdf3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movsd  0x10(%rsp),%xmm1
movsd  0xd7e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1511 <main+0x331>
cvttsd2si %xmm1,%ebx
mov    %ebx,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
test   %rax,%rax
je     15a1 <main+0x3c1>
mov    %rax,%r14
mov    %ebx,0x3c(%rsp)
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0x78(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <clock_gettime@plt>
movq   $0x0,0x48(%rsp)
mov    0x78(%rsp),%rax
mov    %rax,0x98(%rsp)
fildll 0x98(%rsp)
fsubrs 0xd4b(%rip)
fadds  0xd49(%rip)
fnstcw 0xc(%rsp)
movzwl 0xc(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0xe(%rsp)
fldcw  0xe(%rsp)
fistpll 0xa0(%rsp)
fldcw  0xc(%rsp)
mov    0xa0(%rsp),%rax
mov    %rax,0x40(%rsp)
xor    %ebp,%ebp
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1080 <nanosleep@plt>
mov    0x2ca9(%rip),%r12
mov    (%r12),%edi
mov    %rbx,%rsi
call   1050 <clock_gettime@plt>
xorpd  %xmm4,%xmm4
movsd  0x10(%rsp),%xmm0
ucomisd %xmm4,%xmm0
jbe    151d <main+0x33d>
mov    %r15,0x90(%rsp)
mov    $0x3b9aca00,%eax
mov    %rax,0x20(%rsp)
xor    %ebp,%ebp
movsd  0x28(%rsp),%xmm0
mulsd  0xc97(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
lea    0x78(%rsp),%r13
xorpd  %xmm4,%xmm4
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
jmp    13d0 <main+0x1f0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x60(%rsp),%xmm2
movsd  0x58(%rsp),%xmm3
addsd  0xc6c(%rip),%xmm4
movsd  0x10(%rsp),%xmm0
ucomisd %xmm4,%xmm0
movsd  %xmm3,0x58(%rsp)
movsd  %xmm2,0x60(%rsp)
jbe    1531 <main+0x351>
movsd  %xmm4,0x30(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sdq 0x78(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,0x78(%rsp)
mov    %r13,%rdi
call   10c0 <tsnorm@plt>
movupd 0xa8(%rsp),%xmm0
movapd %xmm0,0x40(%rsp)
mov    (%r12),%edi
mov    0x2bd6(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdx
xor    %ecx,%ecx
call   10f0 <clock_nanosleep@plt>
mov    (%r12),%edi
lea    0xa8(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x68(%rsp),%rbx
mov    0x70(%rsp),%r15
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
lea    0x68(%rsp),%rsi
call   1050 <clock_gettime@plt>
movsd  0x30(%rsp),%xmm4
ucomisd 0xbd6(%rip),%xmm4
jne    1462 <main+0x282>
jnp    13a0 <main+0x1c0>
mov    0x68(%rsp),%rdi
mov    0x70(%rsp),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1100 <calcdiff_us@plt>
mov    0x90(%rsp),%rbx
sub    %ebx,%eax
cvttsd2si 0x30(%rsp),%ecx
movslq %ecx,%rcx
mov    %eax,(%r14,%rcx,4)
mov    0xa8(%rsp),%rdi
mov    0xb0(%rsp),%rsi
mov    0x40(%rsp),%rdx
mov    0x48(%rsp),%rcx
call   1100 <calcdiff_us@plt>
movsd  0x30(%rsp),%xmm4
mov    %rbx,%rcx
sub    %rax,%rcx
movapd %xmm4,%xmm3
cmp    %rbp,%rcx
cmovg  %rcx,%rbp
jg     14cc <main+0x2ec>
movsd  0x58(%rsp),%xmm3
movapd %xmm4,%xmm2
mov    0x20(%rsp),%rax
cmp    %rax,%rcx
cmovl  %rcx,%rax
mov    %rax,0x20(%rsp)
jl     14e9 <main+0x309>
movsd  0x60(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
ucomisd 0xb0f(%rip),%xmm1
jbe    13ac <main+0x1cc>
jmp    1531 <main+0x351>
lea    0xbf6(%rip),%rdi
jmp    15a8 <main+0x3c8>
mov    $0x3b9aca00,%eax
mov    %rax,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x18(%rsp),%xmm1
divsd  %xmm4,%xmm1
divsd  %xmm4,%xmm2
movsd  0x88(%rsp),%xmm0
mulsd  %xmm0,%xmm2
divsd  %xmm4,%xmm3
mulsd  %xmm0,%xmm3
lea    0xb28(%rip),%rdi
movapd %xmm4,%xmm0
mov    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    $0x4,%al
call   1070 <printf@plt>
sub    %ebx,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
test   %rax,%rax
je     15a1 <main+0x3c1>
mov    0x3c(%rsp),%esi
test   %esi,%esi
jle    1604 <main+0x424>
mov    $0x1,%ecx
sub    %ebx,%ecx
mov    %esi,%edx
cmp    $0x1,%esi
jne    15c8 <main+0x3e8>
xor    %esi,%esi
jmp    15f4 <main+0x414>
lea    0xb75(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%edi
and    $0xfffffffe,%edi
xor    %esi,%esi
nop
mov    (%r14,%rsi,4),%ebp
add    %ecx,%ebp
movslq %ebp,%rbp
addl   $0x1,(%rax,%rbp,4)
mov    0x4(%r14,%rsi,4),%ebp
add    %ecx,%ebp
movslq %ebp,%rbp
addl   $0x1,(%rax,%rbp,4)
add    $0x2,%rsi
cmp    %rsi,%rdi
jne    15d0 <main+0x3f0>
test   $0x1,%dl
je     1604 <main+0x424>
add    (%r14,%rsi,4),%ecx
movslq %ecx,%rcx
addl   $0x1,(%rax,%rcx,4)
lea    0xabb(%rip),%rdi
lea    0xadb(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbp
movsd  0x10(%rsp),%xmm1
addsd  0xa00(%rip),%xmm1
xor    %r15d,%r15d
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    167c <main+0x49c>
lea    0xab3(%rip),%r12
xor    %ebx,%ebx
movsd  %xmm1,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,4),%edx
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movsd  0x10(%rsp),%xmm1
add    $0x1,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
ucomisd %xmm0,%xmm1
ja     1650 <main+0x470>
mov    %ebx,%eax
jmp    167e <main+0x49e>
xor    %eax,%eax
mov    (%r14,%rax,4),%edx
lea    0xa6a(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xa4d(%rip),%rdi
lea    0xa15(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    15b3 <main+0x3d3>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [37 x i8] c"period: %ldus, total test time: %ld\0A\00"
@.str.1 = [30 x i8] c"testing for %ld seconds\0A ...\0A\00"
@.str.2 = [19 x i8] c"not enough memory\0A\00"
@.str.3 = [16 x i8] c"too much steps\0A\00"
@CLOCK_REALTIME = global i32 0
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
@.str.4 = [67 x i8] c"loops: [%.0f], avg: %lfus, min: %ldus @ %.3fs, max: %ldus @ %.3fs\0A\00"
@.str.5 = [39 x i8] c"/home/pi/rpilogger/test/nanosleep.json\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [4 x i8] c"%d,\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [23 x i8] c"histogram saved in %s\0A\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
%9 = alloca %struct.timespec
%10 = alloca %struct.timespec
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca double
%21 = alloca i32*
%22 = alloca i32
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 2
br i1 %28, label %29, label %38
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @atol(i8* %32)
store i64 %33, i64* %11
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i64 @atol(i8* %36)
store i64 %37, i64* %12
br label %39
38: ; preds = %2
store i64 500, i64* %11
store i64 5, i64* %12
br label %39
39: ; preds = %38, %29
%40 = load i64, i64* %11
%41 = load i64, i64* %12
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %40, i64 %41)
%43 = call i32 (...) @setSchedPrio_noerrcheck()
store double 0.000000e+00, double* %16
store i64 1000000000, i64* %17
store i64 0, i64* %18
%44 = load i64, i64* %11
%45 = sitofp i64 %44 to double
%46 = fdiv double 1.000000e+06, %45
%47 = load i64, i64* %12
%48 = sitofp i64 %47 to double
%49 = fmul double %46, %48
store double %49, double* %20
%50 = load i64, i64* %12
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %50)
%52 = load double, double* %20
%53 = fcmp olt double %52, 0x41DFFFFFFFC00000
br i1 %53, label %54, label %63
54: ; preds = %39
%55 = load double, double* %20
%56 = fptosi double %55 to i32
%57 = call i32* @calloc(i32 %56, i32 4)
store i32* %57, i32** %21
%58 = load i32*, i32** %21
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %258
62: ; preds = %54
br label %65
63: ; preds = %39
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %258
65: ; preds = %62
%66 = load i32, i32* @CLOCK_REALTIME
%67 = call i32 @clock_gettime(i32 %66, %struct.timespec* %6)
%68 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
store i64 0, i64* %68
%69 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%70 = load i64, i64* %69
%71 = sitofp i64 %70 to x86_fp80
%72 = fsub x86_fp80 0xK401CEE6B280000000000, %71
%73 = fsub x86_fp80 %72, 0xK40079600000000000000
%74 = fptosi x86_fp80 %73 to i64
%75 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
store i64 %74, i64* %75
%76 = call i32 @nanosleep(%struct.timespec* %8, i32* null)
%77 = load i32, i32* @CLOCK_MONOTONIC
%78 = call i32 @clock_gettime(i32 %77, %struct.timespec* %6)
store double 0.000000e+00, double* %13
br label %79
79: ; preds = %161, %65
%80 = load double, double* %13
%81 = load double, double* %20
%82 = fcmp olt double %80, %81
br i1 %82, label %83, label %164
83: ; preds = %79
%84 = load i64, i64* %11
%85 = sitofp i64 %84 to double
%86 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%87 = load i64, i64* %86
%88 = sitofp i64 %87 to double
%89 = call double @llvm.fmuladd.f64(double %85, double 1.000000e+03, double %88)
%90 = fptosi double %89 to i64
store i64 %90, i64* %86
%91 = call i32 @tsnorm(%struct.timespec* %6)
%92 = bitcast %struct.timespec* %8 to i8*
%93 = bitcast %struct.timespec* %7 to i8*
%94 = load i32, i32* @CLOCK_MONOTONIC
%95 = load i32, i32* @TIMER_ABSTIME
%96 = call i32 @clock_nanosleep(i32 %94, i32 %95, %struct.timespec* %6, i32* null)
%97 = load i32, i32* @CLOCK_MONOTONIC
%98 = call i32 @clock_gettime(i32 %97, %struct.timespec* %7)
%99 = bitcast %struct.timespec* %10 to i8*
%100 = bitcast %struct.timespec* %9 to i8*
%101 = load i32, i32* @CLOCK_REALTIME
%102 = call i32 @clock_gettime(i32 %101, %struct.timespec* %9)
%103 = load double, double* %13
%104 = fcmp oeq double %103, 0.000000e+00
br i1 %104, label %105, label %106
105: ; preds = %83
br label %161
106: ; preds = %83
%107 = bitcast %struct.timespec* %9 to { i64, i64 }*
%108 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %107, i32 0, i32 0
%109 = load i64, i64* %108
%110 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %107, i32 0, i32 1
%111 = load i64, i64* %110
%112 = bitcast %struct.timespec* %10 to { i64, i64 }*
%113 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %112, i32 0, i32 0
%114 = load i64, i64* %113
%115 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %112, i32 0, i32 1
%116 = load i64, i64* %115
%117 = call i64 @calcdiff_us(i64 %109, i64 %111, i64 %114, i64 %116)
%118 = load i64, i64* %11
%119 = sub nsw i64 %117, %118
%120 = trunc i64 %119 to i32
%121 = load i32*, i32** %21
%122 = load double, double* %13
%123 = fptosi double %122 to i32
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i32, i32* %121, i64 %124
store i32 %120, i32* %125
%126 = load i64, i64* %11
%127 = bitcast %struct.timespec* %7 to { i64, i64 }*
%128 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %127, i32 0, i32 0
%129 = load i64, i64* %128
%130 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %127, i32 0, i32 1
%131 = load i64, i64* %130
%132 = bitcast %struct.timespec* %8 to { i64, i64 }*
%133 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %132, i32 0, i32 0
%134 = load i64, i64* %133
%135 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %132, i32 0, i32 1
%136 = load i64, i64* %135
%137 = call i64 @calcdiff_us(i64 %129, i64 %131, i64 %134, i64 %136)
%138 = sub nsw i64 %126, %137
store i64 %138, i64* %19
%139 = load i64, i64* %19
%140 = load i64, i64* %18
%141 = icmp sgt i64 %139, %140
br i1 %141, label %142, label %145
142: ; preds = %106
%143 = load i64, i64* %19
store i64 %143, i64* %18
%144 = load double, double* %13
store double %144, double* %14
br label %145
145: ; preds = %142, %106
%146 = load i64, i64* %19
%147 = load i64, i64* %17
%148 = icmp slt i64 %146, %147
br i1 %148, label %149, label %152
149: ; preds = %145
%150 = load i64, i64* %19
store i64 %150, i64* %17
%151 = load double, double* %13
store double %151, double* %15
br label %152
152: ; preds = %149, %145
%153 = load i64, i64* %19
%154 = sitofp i64 %153 to double
%155 = load double, double* %16
%156 = fadd double %155, %154
store double %156, double* %16
%157 = load double, double* %16
%158 = fcmp ogt double %157, 0x7FB9999999999999
br i1 %158, label %159, label %160
159: ; preds = %152
br label %164
160: ; preds = %152
br label %161
161: ; preds = %160, %105
%162 = load double, double* %13
%163 = fadd double %162, 1.000000e+00
store double %163, double* %13
br label %79
164: ; preds = %159, %79
%165 = load double, double* %13
%166 = load double, double* %16
%167 = load double, double* %13
%168 = fdiv double %166, %167
%169 = load i64, i64* %17
%170 = load double, double* %15
%171 = load double, double* %13
%172 = fdiv double %170, %171
%173 = load i64, i64* %12
%174 = sitofp i64 %173 to double
%175 = fmul double %172, %174
%176 = load i64, i64* %18
%177 = load double, double* %14
%178 = load double, double* %13
%179 = fdiv double %177, %178
%180 = load i64, i64* %12
%181 = sitofp i64 %180 to double
%182 = fmul double %179, %181
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), double %165, double %168, i64 %169, double %175, i64 %176, double %182)
%184 = load i64, i64* %18
%185 = load i64, i64* %17
%186 = sub nsw i64 %184, %185
%187 = add nsw i64 %186, 1
%188 = trunc i64 %187 to i32
store i32 %188, i32* %22
%189 = load i32, i32* %22
%190 = call i32* @calloc(i32 %189, i32 4)
store i32* %190, i32** %23
%191 = load i32*, i32** %23
%192 = icmp eq i32* %191, null
br i1 %192, label %193, label %195
193: ; preds = %164
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %258
195: ; preds = %164
store i32 0, i32* %24
br label %196
196: ; preds = %221, %195
%197 = load i32, i32* %24
%198 = load double, double* %20
%199 = fptosi double %198 to i32
%200 = icmp slt i32 %197, %199
br i1 %200, label %201, label %224
201: ; preds = %196
%202 = load i32*, i32** %21
%203 = load i32, i32* %24
%204 = sext i32 %203 to i64
%205 = getelementptr inbounds i32, i32* %202, i64 %204
%206 = load i32, i32* %205
%207 = load i64, i64* %17
%208 = trunc i64 %207 to i32
%209 = sub nsw i32 %206, %208
%210 = add nsw i32 %209, 1
store i32 %210, i32* %25
%211 = load i32*, i32** %23
%212 = load i32, i32* %25
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds i32, i32* %211, i64 %213
%215 = load i32, i32* %214
%216 = add nsw i32 %215, 1
%217 = load i32*, i32** %23
%218 = load i32, i32* %25
%219 = sext i32 %218 to i64
%220 = getelementptr inbounds i32, i32* %217, i64 %219
store i32 %216, i32* %220
br label %221
221: ; preds = %201
%222 = load i32, i32* %24
%223 = add nsw i32 %222, 1
store i32 %223, i32* %24
br label %196
224: ; preds = %196
%225 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %225, i32** %26
%226 = load i32*, i32** %26
%227 = call i32 (i32*, i8*, ...) @fprintf(i32* %226, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %25
br label %228
228: ; preds = %242, %224
%229 = load i32, i32* %25
%230 = sitofp i32 %229 to double
%231 = load double, double* %20
%232 = fsub double %231, 1.000000e+00
%233 = fcmp olt double %230, %232
br i1 %233, label %234, label %245
234: ; preds = %228
%235 = load i32*, i32** %26
%236 = load i32*, i32** %21
%237 = load i32, i32* %25
%238 = sext i32 %237 to i64
%239 = getelementptr inbounds i32, i32* %236, i64 %238
%240 = load i32, i32* %239
%241 = call i32 (i32*, i8*, ...) @fprintf(i32* %235, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %240)
br label %242
242: ; preds = %234
%243 = load i32, i32* %25
%244 = add nsw i32 %243, 1
store i32 %244, i32* %25
br label %228
245: ; preds = %228
%246 = load i32*, i32** %26
%247 = load i32*, i32** %21
%248 = load i32, i32* %25
%249 = sext i32 %248 to i64
%250 = getelementptr inbounds i32, i32* %247, i64 %249
%251 = load i32, i32* %250
%252 = call i32 (i32*, i8*, ...) @fprintf(i32* %246, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %251)
%253 = load i32*, i32** %26
%254 = call i32 @fclose(i32* %253)
%255 = load i32*, i32** %21
%256 = call i32 @free(i32* %255)
%257 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %258
258: ; preds = %245, %193, %63, %60
%259 = load i32, i32* %3
ret i32 %259
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [37 x i8] c"period: %ldus, total test time: %ld\0A\00"
@.str.1 = [30 x i8] c"testing for %ld seconds\0A ...\0A\00"
@CLOCK_REALTIME = global i32 0
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
@.str.4 = [67 x i8] c"loops: [%.0f], avg: %lfus, min: %ldus @ %.3fs, max: %ldus @ %.3fs\0A\00"
@.str.5 = [39 x i8] c"/home/pi/rpilogger/test/nanosleep.json\00"
@.str.6 = [2 x i8] c"w\00"
@.str.8 = [4 x i8] c"%d,\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [23 x i8] c"histogram saved in %s\0A\00"
@str = [15 x i8] c"too much steps\00"
@str.12 = [18 x i8] c"not enough memory\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = bitcast %struct.timespec* %3 to i8*
%8 = bitcast %struct.timespec* %4 to i8*
%9 = bitcast %struct.timespec* %5 to i8*
%10 = bitcast %struct.timespec* %6 to i8*
%11 = icmp sgt i32 %0, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @atol(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @atol(i8* %17)
br label %19
19: ; preds = %2, %12
%20 = phi i64 [ %18, %12 ], [ 5, %2 ]
%21 = phi i64 [ %15, %12 ], [ 500, %2 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %21, i64 %20)
%23 = tail call i32 (...) @setSchedPrio_noerrcheck()
%24 = sitofp i64 %21 to double
%25 = fdiv double 1.000000e+06, %24
%26 = sitofp i64 %20 to double
%27 = fmul double %25, %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %20)
%29 = fcmp olt double %27, 0x41DFFFFFFFC00000
br i1 %29, label %30, label %36
30: ; preds = %19
%31 = fptosi double %27 to i32
%32 = tail call i32* @calloc(i32 %31, i32 4)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
br label %197
36: ; preds = %19
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %197
38: ; preds = %30
%39 = load i32, i32* @CLOCK_REALTIME
%40 = call i32 @clock_gettime(i32 %39, %struct.timespec* %3)
%41 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
store i64 0, i64* %41
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%43 = load i64, i64* %42
%44 = sitofp i64 %43 to x86_fp80
%45 = fsub x86_fp80 0xK401CEE6B280000000000, %44
%46 = fadd x86_fp80 %45, 0xKC0079600000000000000
%47 = fptosi x86_fp80 %46 to i64
%48 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
store i64 %47, i64* %48
%49 = call i32 @nanosleep(%struct.timespec* %5, i32* null)
%50 = load i32, i32* @CLOCK_MONOTONIC
%51 = call i32 @clock_gettime(i32 %50, %struct.timespec* %3)
%52 = fcmp ogt double %27, 0.000000e+00
br i1 %52, label %53, label %112
53: ; preds = %38
%54 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
%55 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 1
%56 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%57 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
br label %58
58: ; preds = %53, %104
%59 = phi double [ 0.000000e+00, %53 ], [ %110, %104 ]
%60 = phi double [ undef, %53 ], [ %109, %104 ]
%61 = phi double [ undef, %53 ], [ %108, %104 ]
%62 = phi i64 [ 0, %53 ], [ %107, %104 ]
%63 = phi i64 [ 1000000000, %53 ], [ %106, %104 ]
%64 = phi double [ 0.000000e+00, %53 ], [ %105, %104 ]
%65 = load i64, i64* %42
%66 = sitofp i64 %65 to double
%67 = call double @llvm.fmuladd.f64(double %24, double 1.000000e+03, double %66)
%68 = fptosi double %67 to i64
store i64 %68, i64* %42
%69 = call i32 @tsnorm(%struct.timespec* %3)
%70 = load i32, i32* @CLOCK_MONOTONIC
%71 = load i32, i32* @TIMER_ABSTIME
%72 = call i32 @clock_nanosleep(i32 %70, i32 %71, %struct.timespec* %3, i32* null)
%73 = load i32, i32* @CLOCK_MONOTONIC
%74 = call i32 @clock_gettime(i32 %73, %struct.timespec* %4)
%75 = load i64, i64* %54
%76 = load i64, i64* %55
%77 = load i32, i32* @CLOCK_REALTIME
%78 = call i32 @clock_gettime(i32 %77, %struct.timespec* %6)
%79 = fcmp oeq double %59, 0.000000e+00
br i1 %79, label %104, label %80
80: ; preds = %58
%81 = load i64, i64* %54
%82 = load i64, i64* %55
%83 = call i64 @calcdiff_us(i64 %81, i64 %82, i64 %75, i64 %76)
%84 = sub nsw i64 %83, %21
%85 = trunc i64 %84 to i32
%86 = fptosi double %59 to i32
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %32, i64 %87
store i32 %85, i32* %88
%89 = load i64, i64* %56
%90 = load i64, i64* %57
%91 = load i64, i64* %48
%92 = load i64, i64* %41
%93 = call i64 @calcdiff_us(i64 %89, i64 %90, i64 %91, i64 %92)
%94 = sub nsw i64 %21, %93
%95 = icmp sgt i64 %94, %62
%96 = select i1 %95, i64 %94, i64 %62
%97 = select i1 %95, double %59, double %60
%98 = icmp slt i64 %94, %63
%99 = select i1 %98, i64 %94, i64 %63
%100 = select i1 %98, double %59, double %61
%101 = sitofp i64 %94 to double
%102 = fadd double %64, %101
%103 = fcmp ogt double %102, 0x7FB9999999999999
br i1 %103, label %112, label %104
104: ; preds = %80, %58
%105 = phi double [ %64, %58 ], [ %102, %80 ]
%106 = phi i64 [ %63, %58 ], [ %99, %80 ]
%107 = phi i64 [ %62, %58 ], [ %96, %80 ]
%108 = phi double [ %61, %58 ], [ %100, %80 ]
%109 = phi double [ %60, %58 ], [ %97, %80 ]
%110 = fadd double %59, 1.000000e+00
%111 = fcmp olt double %110, %27
br i1 %111, label %58, label %112
112: ; preds = %104, %80, %38
%113 = phi double [ 0.000000e+00, %38 ], [ %59, %80 ], [ %110, %104 ]
%114 = phi double [ 0.000000e+00, %38 ], [ %102, %80 ], [ %105, %104 ]
%115 = phi i64 [ 1000000000, %38 ], [ %99, %80 ], [ %106, %104 ]
%116 = phi i64 [ 0, %38 ], [ %96, %80 ], [ %107, %104 ]
%117 = phi double [ undef, %38 ], [ %100, %80 ], [ %108, %104 ]
%118 = phi double [ undef, %38 ], [ %97, %80 ], [ %109, %104 ]
%119 = fdiv double %114, %113
%120 = fdiv double %117, %113
%121 = fmul double %120, %26
%122 = fdiv double %118, %113
%123 = fmul double %122, %26
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), double %113, double %119, i64 %115, double %121, i64 %116, double %123)
%125 = sub nsw i64 %116, %115
%126 = trunc i64 %125 to i32
%127 = add i32 %126, 1
%128 = call i32* @calloc(i32 %127, i32 4)
%129 = icmp eq i32* %128, null
br i1 %129, label %140, label %130
130: ; preds = %112
%131 = icmp sgt i32 %31, 0
br i1 %131, label %132, label %174
132: ; preds = %130
%133 = trunc i64 %115 to i32
%134 = sub i32 1, %133
%135 = zext i32 %31 to i64
%136 = and i64 %135, 1
%137 = icmp eq i32 %31, 1
br i1 %137, label %163, label %138
138: ; preds = %132
%139 = and i64 %135, 4294967294
br label %142
140: ; preds = %112
%141 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
br label %197
142: ; preds = %142, %138
%143 = phi i64 [ 0, %138 ], [ %160, %142 ]
%144 = phi i64 [ 0, %138 ], [ %161, %142 ]
%145 = getelementptr inbounds i32, i32* %32, i64 %143
%146 = load i32, i32* %145
%147 = add i32 %134, %146
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds i32, i32* %128, i64 %148
%150 = load i32, i32* %149
%151 = add nsw i32 %150, 1
store i32 %151, i32* %149
%152 = or i64 %143, 1
%153 = getelementptr inbounds i32, i32* %32, i64 %152
%154 = load i32, i32* %153
%155 = add i32 %134, %154
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i32, i32* %128, i64 %156
%158 = load i32, i32* %157
%159 = add nsw i32 %158, 1
store i32 %159, i32* %157
%160 = add nuw nsw i64 %143, 2
%161 = add i64 %144, 2
%162 = icmp eq i64 %161, %139
br i1 %162, label %163, label %142
163: ; preds = %142, %132
%164 = phi i64 [ 0, %132 ], [ %160, %142 ]
%165 = icmp eq i64 %136, 0
br i1 %165, label %174, label %166
166: ; preds = %163
%167 = getelementptr inbounds i32, i32* %32, i64 %164
%168 = load i32, i32* %167
%169 = add i32 %134, %168
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds i32, i32* %128, i64 %170
%172 = load i32, i32* %171
%173 = add nsw i32 %172, 1
store i32 %173, i32* %171
br label %174
174: ; preds = %166, %163, %130
%175 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%176 = fadd double %27, -1.000000e+00
%177 = fcmp ogt double %176, 0.000000e+00
br i1 %177, label %178, label %189
178: ; preds = %174, %178
%179 = phi i64 [ %183, %178 ], [ 0, %174 ]
%180 = getelementptr inbounds i32, i32* %32, i64 %179
%181 = load i32, i32* %180
%182 = call i32 (i32*, i8*, ...) @fprintf(i32* %175, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %181)
%183 = add nuw i64 %179, 1
%184 = trunc i64 %183 to i32
%185 = sitofp i32 %184 to double
%186 = fcmp ogt double %176, %185
br i1 %186, label %178, label %187
187: ; preds = %178
%188 = and i64 %183, 4294967295
br label %189
189: ; preds = %187, %174
%190 = phi i64 [ 0, %174 ], [ %188, %187 ]
%191 = getelementptr inbounds i32, i32* %32, i64 %190
%192 = load i32, i32* %191
%193 = call i32 (i32*, i8*, ...) @fprintf(i32* %175, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %192)
%194 = call i32 @fclose(i32* %175)
%195 = call i32 @free(i32* %32)
%196 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
br label %197
197: ; preds = %140, %189, %36, %34
%198 = phi i32 [ -1, %34 ], [ -1, %36 ], [ -1, %140 ], [ 0, %189 ]
ret i32 %198
}