// File: /workspace/github_c_makefile_star2_O1/igaw[P]jitterdebugger/jitterdebugger.c
// Function: worker
static void *worker(void *arg)
{
	struct stats *s = arg;
	struct timespec now, next, interval;
	sigset_t mask;
	uint64_t diff;
	int err;

	/* Don't handle any signals */
	sigfillset(&mask);
	if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0)
		err_handler(errno, "sigprocmask()");

	s->tid = __gettid();

	interval.tv_sec = 0;
	interval.tv_nsec = sleep_interval_us * NSEC_PER_US;

	err = clock_gettime(CLOCK_MONOTONIC, &now);
	if (err)
		err_handler(err, "clock_gettime()");

	next = now;

	while (!READ_ONCE(jd_shutdown)) {
		next = ts_add(next, interval);

		err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
					&next, NULL);
		if (err)
			err_handler(err, "clock_nanosleep()");

		err = clock_gettime(CLOCK_MONOTONIC, &now);
		if (err)
			err_handler(err, "clock_gettime()");

		/* Update the statistics */
		diff = ts_sub(now, next);
		if (diff > s->max)
			s->max = diff;

		if (diff < s->min)
			s->min = diff;

		s->count++;
		s->total += diff;

		if (diff < s->hist_size)
			s->hist[diff]++;

		if (s->rb)
			ringbuffer_write(s->rb, now, diff);

		if (diff > break_val) {
			stop_tracer(diff);
			WRITE_ONCE(jd_shutdown, 1);
		}

		if (max_loops > 0 && s->count >= max_loops)
			break;
	}

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
callq 0x2290
xorl %edi, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2030
testl %eax, %eax
jns 0x3e6d
callq 0x2070
movl (%rax), %edi
leaq 0x18a6(%rip), %rsi      # 0x56fe
leaq 0x13d8(%rip), %rdx      # 0x5237
leaq 0x18af(%rip), %rcx      # 0x5715
xorl %eax, %eax
callq 0x4184
movl $0xba, %edi
xorl %eax, %eax
callq 0x2250
movl %eax, 0x8(%rbx)
movl 0x458d(%rip), %r14d     # 0x8410
leaq 0x10(%rsp), %rsi
movl $0x1, %edi
callq 0x20f0
testl %eax, %eax
je 0x3eb4
leaq 0x187f(%rip), %rsi      # 0x571c
leaq 0x1393(%rip), %rdx      # 0x5237
leaq 0x186a(%rip), %rcx      # 0x5715
movl %eax, %edi
xorl %eax, %eax
callq 0x4184
movups 0x10(%rsp), %xmm0
movaps %xmm0, (%rsp)
cmpl $0x0, 0x45f0(%rip)      # 0x84b4
jne 0x4094
imulq $0x3e8, %r14, %r15      # imm = 0x3E8
leaq 0x20(%rsp), %r13
leaq 0x135a(%rip), %rbp      # 0x5237
leaq 0x1831(%rip), %r12      # 0x5715
movq (%rsp), %rcx
movq 0x8(%rsp), %rsi
addq %r15, %rsi
cmpq $0x3b9aca00, %rsi       # imm = 0x3B9ACA00
jl 0x3f40
movl $0x773593ff, %eax       # imm = 0x773593FF
cmpq %rax, %rsi
cmovlq %rsi, %rax
negq %rax
addq %rsi, %rax
addq $0x3b9ac9ff, %rax       # imm = 0x3B9AC9FF
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
shrq $0xb, %rdx
imulq $-0x3b9aca00, %rdx, %rax # imm = 0xC4653600
movq $-0x3b9aca00, %rdi      # imm = 0xC4653600
addq %rdi, %rsi
addq %rax, %rsi
addq %rdx, %rcx
incq %rcx
movq %rcx, (%rsp)
movq %rsi, 0x8(%rsp)
movl $0x1, %edi
movl $0x1, %esi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x23e0
testl %eax, %eax
je 0x3f77
movl %eax, %edi
leaq 0x17cb(%rip), %rsi      # 0x5735
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x4184
movl $0x1, %edi
leaq 0x10(%rsp), %rsi
callq 0x20f0
testl %eax, %eax
je 0x3fa0
movl %eax, %edi
leaq 0x1789(%rip), %rsi      # 0x571c
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x4184
movl 0x10(%rsp), %eax
movl 0x18(%rsp), %ecx
subl (%rsp), %eax
cltq
imulq $0x3b9aca00, %rax, %rdx # imm = 0x3B9ACA00
subl 0x8(%rsp), %ecx
movslq %ecx, %rax
addq %rdx, %rax
cmpb $0x0, 0x4467(%rip)      # 0x842c
movl $0x3e8, %ecx            # imm = 0x3E8
movl $0x1, %edx
cmovneq %rdx, %rcx
cqto
idivq %rcx
movq %rax, %r14
cmpq 0x10(%rbx), %rax
jbe 0x3fe5
movq %r14, 0x10(%rbx)
cmpq 0x18(%rbx), %r14
jae 0x3fef
movq %r14, 0x18(%rbx)
incq 0x40(%rbx)
addq %r14, 0x38(%rbx)
movl 0x28(%rbx), %eax
cmpq %rax, %r14
jae 0x4007
movq 0x30(%rbx), %rax
incq (%rax,%r14,8)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4022
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
callq 0x4107
cmpq 0x43df(%rip), %r14      # 0x8408
jbe 0x4076
movl $0x80, %esi
movq %r13, %rdi
leaq 0x1716(%rip), %rdx      # 0x5750
movq %r14, %rcx
xorl %eax, %eax
callq 0x2170
movl 0x43ca(%rip), %edi      # 0x8414
movslq %eax, %rdx
movq %r13, %rsi
callq 0x2100
movl 0x43bd(%rip), %edi      # 0x8418
movl $0x2, %edx
leaq 0x16f9(%rip), %rsi      # 0x5760
callq 0x2100
movl $0x1, 0x443e(%rip)      # 0x84b4
movl 0x43ac(%rip), %eax      # 0x8428
testq %rax, %rax
je 0x4087
cmpq %rax, 0x40(%rbx)
jae 0x4094
cmpl $0x0, 0x4426(%rip)      # 0x84b4
je 0x3ee4
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq