// File: /workspace/github_c_makefile_star2_O3/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 0x2280
xorl %edi, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2030
testl %eax, %eax
jns 0x3e5f
callq 0x2070
movl (%rax), %edi
leaq 0x18e4(%rip), %rsi      # 0x572e
leaq 0x1416(%rip), %rdx      # 0x5267
leaq 0x18ed(%rip), %rcx      # 0x5745
xorl %eax, %eax
callq 0x418c
movl $0xba, %edi
xorl %eax, %eax
callq 0x2240
movl %eax, 0x8(%rbx)
movl 0x459b(%rip), %r14d     # 0x8410
leaq 0x10(%rsp), %rsi
movl $0x1, %edi
callq 0x20e0
testl %eax, %eax
je 0x3ea6
leaq 0x18bd(%rip), %rsi      # 0x574c
leaq 0x13d1(%rip), %rdx      # 0x5267
leaq 0x18a8(%rip), %rcx      # 0x5745
movl %eax, %edi
xorl %eax, %eax
callq 0x418c
movdqu 0x10(%rsp), %xmm0
movdqa %xmm0, (%rsp)
cmpl $0x0, 0x45fc(%rip)      # 0x84b4
jne 0x409c
imulq $0x3e8, %r14, %r15      # imm = 0x3E8
leaq 0x20(%rsp), %r13
leaq 0x1396(%rip), %rbp      # 0x5267
leaq 0x186d(%rip), %r12      # 0x5745
movq (%rsp), %rcx
movq 0x8(%rsp), %rsi
addq %r15, %rsi
cmpq $0x3b9aca00, %rsi       # imm = 0x3B9ACA00
jl 0x3f34
movq %rsi, %rax
subq $0x773593ff, %rax       # imm = 0x773593FF
movl $0x0, %edx
cmovbq %rdx, %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 0x23d0
testl %eax, %eax
je 0x3f6b
movl %eax, %edi
leaq 0x1807(%rip), %rsi      # 0x5765
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x418c
movl $0x1, %edi
leaq 0x10(%rsp), %rsi
callq 0x20e0
testl %eax, %eax
je 0x3f94
movl %eax, %edi
leaq 0x17c5(%rip), %rsi      # 0x574c
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x418c
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, 0x4473(%rip)      # 0x842c
movl $0x3e8, %ecx            # imm = 0x3E8
movl $0x1, %edx
cmovneq %rdx, %rcx
cqto
idivq %rcx
movq %rax, %r14
cmpq 0x10(%rbx), %rax
jbe 0x3fd9
movq %r14, 0x10(%rbx)
cmpq 0x18(%rbx), %r14
jae 0x3fe3
movq %r14, 0x18(%rbx)
movdqu 0x38(%rbx), %xmm0
movq %r14, %xmm1
shufpd $0x2, 0x105a(%rip), %xmm1 # xmm1 = xmm1[0],mem[1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x38(%rbx)
movl 0x28(%rbx), %eax
cmpq %rax, %r14
jae 0x400f
movq 0x30(%rbx), %rax
incq (%rax,%r14,8)
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x402a
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
callq 0x410f
cmpq 0x43d7(%rip), %r14      # 0x8408
jbe 0x407e
movl $0x80, %esi
movq %r13, %rdi
leaq 0x173e(%rip), %rdx      # 0x5780
movq %r14, %rcx
xorl %eax, %eax
callq 0x2160
movl 0x43c2(%rip), %edi      # 0x8414
movslq %eax, %rdx
movq %r13, %rsi
callq 0x20f0
movl 0x43b5(%rip), %edi      # 0x8418
movl $0x2, %edx
leaq 0x1721(%rip), %rsi      # 0x5790
callq 0x20f0
movl $0x1, 0x4436(%rip)      # 0x84b4
movl 0x43a4(%rip), %eax      # 0x8428
testq %rax, %rax
je 0x408f
cmpq %rax, 0x40(%rbx)
jae 0x409c
cmpl $0x0, 0x441e(%rip)      # 0x84b4
je 0x3ed8
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq