// File: /workspace/github_c_makefile_star2_O0/sprt[P]lossless-transport/src/util.c
// Function: get_monotime
uint32_t get_monotime(void) {
	static bool first_call = true; /* whether this is the first call */
	static struct timeval first; /* unnormalized value returned by the first call */
	static struct timeval last; /* unnormalized value returned by the last call */

	struct timespec now_tp;
	if (clock_gettime(CLOCK_MONOTONIC, &now_tp) == -1) {
		exit_perror("clock_gettime");
	}

	/* Convert the timespec to a timeval */
	struct timeval now;
	now.tv_sec = now_tp.tv_sec;
	now.tv_usec = now_tp.tv_nsec / 1000;

	if (first_call) {
		/* Remember the value of the first call to normalize to 0 later */
		first = now;
		first_call = false;
	} else if (timercmp(&now, &last, <) || !timercmp(&now, &last, !=)) {
		/* Increment if not strictly greater than the last time returned */

		struct timeval us;
		us.tv_sec = 0;
		us.tv_usec = 1;

		struct timeval res;
		timeradd(&last, &us, &res);
		now = res;
	}

	/* Save the time we're returning for later calls */
	last = now;

	/* Normalize to start at 0 */
	struct timeval res;
	timersub(&now, &first, &res);
	now = res;

	/* Convert to microseconds */
	return now.tv_sec * 1000000 + now.tv_usec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x1, %edi
leaq -0x10(%rbp), %rsi
callq 0x1080
cmpl $-0x1, %eax
jne 0x23c7
leaq 0x1dd3(%rip), %rdi      # 0x4195
callq 0x1e50
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, -0x18(%rbp)
testb $0x1, 0x4d48(%rip)      # 0x7130
je 0x240c
movq -0x20(%rbp), %rax
movq %rax, 0x515b(%rip)      # 0x7550
movq -0x18(%rbp), %rax
movq %rax, 0x5158(%rip)      # 0x7558
movb $0x0, 0x4d29(%rip)      # 0x7130
jmp 0x24c4
movq -0x20(%rbp), %rax
cmpq 0x5149(%rip), %rax      # 0x7560
jne 0x2428
movq -0x18(%rbp), %rax
cmpq 0x5144(%rip), %rax      # 0x7568
jl 0x245e
jmp 0x2435
movq -0x20(%rbp), %rax
cmpq 0x512d(%rip), %rax      # 0x7560
jl 0x245e
movq -0x20(%rbp), %rax
cmpq 0x5120(%rip), %rax      # 0x7560
jne 0x2451
movq -0x18(%rbp), %rax
cmpq 0x511b(%rip), %rax      # 0x7568
jne 0x24c2
jmp 0x245e
movq -0x20(%rbp), %rax
cmpq 0x5104(%rip), %rax      # 0x7560
jne 0x24c2
movq $0x0, -0x30(%rbp)
movq $0x1, -0x28(%rbp)
movq 0x50eb(%rip), %rax      # 0x7560
addq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x50e4(%rip), %rax      # 0x7568
addq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0xf4240, -0x38(%rbp)   # imm = 0xF4240
jl 0x24b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq $0xf4240, %rax          # imm = 0xF4240
movq %rax, -0x38(%rbp)
jmp 0x24b2
movq -0x40(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x24c4
movq -0x20(%rbp), %rax
movq %rax, 0x5091(%rip)      # 0x7560
movq -0x18(%rbp), %rax
movq %rax, 0x508e(%rip)      # 0x7568
movq -0x20(%rbp), %rax
subq 0x506b(%rip), %rax      # 0x7550
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
subq 0x5064(%rip), %rax      # 0x7558
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jge 0x2519
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
addq $0xf4240, %rax          # imm = 0xF4240
movq %rax, -0x48(%rbp)
jmp 0x251b
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
imulq $0xf4240, -0x20(%rbp), %rax # imm = 0xF4240
addq -0x18(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)