#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;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ TIMER_ABSTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/,
                                   struct timespec *, int /*<<< orphan*/ *);
scalar_t__ frames_to_sample_list();
int /*<<< orphan*/ init_realtime();
int /*<<< orphan*/ send_decimations();
void *run(void *data) {
  (void)data;
  init_realtime();
  struct timespec deadline;
  clock_gettime(CLOCK_MONOTONIC, &deadline);
  for (;;) {
    if (0 < frames_to_sample_list()) {
      send_decimations();
    }
    deadline.tv_nsec += 1E6;
    if (deadline.tv_nsec >= 1000000000) {
      deadline.tv_nsec -= 1000000000;
      deadline.tv_sec++;
    }
    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline, NULL);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <init_realtime@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1040 <frames_to_sample_list@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    1191 <run+0x41>
mov    $0x0,%al
call   1070 <send_decimations@plt>
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x3b9aca00,-0x10(%rbp)
jl     11ca <run+0x7a>
mov    -0x10(%rbp),%eax
sub    $0x3b9aca00,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <clock_nanosleep@plt>
jmp    1175 <run+0x25>

x86 assembly (clang, -O2):
<run>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <init_realtime@plt>
mov    0x2e79(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   1030 <clock_gettime@plt>
mov    0x2e6a(%rip),%rbx
jmp    118f <run+0x3f>
mov    (%r14),%edi
mov    (%rbx),%esi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1060 <clock_nanosleep@plt>
xor    %eax,%eax
call   1040 <frames_to_sample_list@plt>
test   %rax,%rax
jle    11a2 <run+0x52>
xor    %eax,%eax
call   1070 <send_decimations@plt>
mov    0x8(%rsp),%eax
lea    0xf4240(%rax),%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x3b9aca00,%ecx
jl     1180 <run+0x30>
add    $0xc4747840,%eax
mov    %eax,0x8(%rsp)
addl   $0x1,0xc(%rsp)
jmp    1180 <run+0x30>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
define i8* @run(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timespec
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (...) @init_realtime()
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %3)
br label %8
8: ; preds = %29, %1
%9 = call i64 (...) @frames_to_sample_list()
%10 = icmp slt i64 0, %9
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (...) @send_decimations()
br label %13
13: ; preds = %11, %8
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sitofp i32 %15 to double
%17 = fadd double %16, 1.000000e+06
%18 = fptosi double %17 to i32
store i32 %18, i32* %14
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = icmp sge i32 %20, 1000000000
br i1 %21, label %22, label %29
22: ; preds = %13
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = sub nsw i32 %24, 1000000000
store i32 %25, i32* %23
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
br label %29
29: ; preds = %22, %13
%30 = load i32, i32* @CLOCK_MONOTONIC
%31 = load i32, i32* @TIMER_ABSTIME
%32 = call i32 @clock_nanosleep(i32 %30, i32 %31, %struct.timespec* %3, i32* null)
br label %8
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
define noalias i8* @run(i8* nocapture readnone %0) {
%2 = alloca %struct.timespec
%3 = tail call i32 (...) @init_realtime()
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %2)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
br label %9
9: ; preds = %22, %1
%10 = call i64 (...) @frames_to_sample_list()
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 (...) @send_decimations()
br label %14
14: ; preds = %12, %9
%15 = load i32, i32* %7
%16 = add i32 %15, 1000000
store i32 %16, i32* %7
%17 = icmp sgt i32 %16, 999999999
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = add i32 %15, -999000000
store i32 %19, i32* %7
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
br label %22
22: ; preds = %18, %14
%23 = load i32, i32* @CLOCK_MONOTONIC
%24 = load i32, i32* @TIMER_ABSTIME
%25 = call i32 @clock_nanosleep(i32 %23, i32 %24, %struct.timespec* %2, i32* null)
br label %9
}