// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]spiped/tests/nc-server/main.c
// Function: write_bps
static int
write_bps(int sock, uint8_t * buf, size_t buflen, size_t bps)
{
	size_t remaining = buflen;
	size_t goal_send;
	size_t actual_sent = 0;
	size_t to_send;
	struct timeval orig, now;

	/* Get initial time. */
	if (monoclock_get(&orig)) {
		warn0("monoclock_get");
		goto err0;
	}

	do {
		/* Wait 10ms. */
		millisleep(10);

		/* How much data should we have sent by now? */
		if (monoclock_get(&now)) {
			warn0("monoclock_get");
			goto err0;
		}
		goal_send = (size_t)((double)bps * timeval_diff(orig, now));

		/* If clocks did something really weird, loop again. */
		if (goal_send <= actual_sent)
			continue;

		/* How data should we send to reach the time-based goal? */
		to_send = goal_send - actual_sent;
		if (to_send > remaining)
			to_send = remaining;

		/* Send a burst. */
		if (write(sock, buf, to_send) == -1) {
			warnp("write");
			goto err0;
		}

		/* Record effect of sending. */
		remaining -= to_send;
		buf += to_send;
		actual_sent += to_send;
	} while (remaining > 0);

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5c20
cmpl $0x0, %eax
je 0x2b25
jmp 0x2b07
leaq 0x76ab(%rip), %rdi      # 0xa1b9
movb $0x0, %al
callq 0x7df0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2c9b
jmp 0x2b27
movl $0xa, %edi
callq 0x2cb0
leaq -0x60(%rbp), %rdi
callq 0x5c20
cmpl $0x0, %eax
je 0x2b5f
jmp 0x2b41
leaq 0x7671(%rip), %rdi      # 0xa1b9
movb $0x0, %al
callq 0x7df0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2c9b
movaps 0x74ba(%rip), %xmm1     # 0xa020
movq -0x20(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x74b9(%rip), %xmm1     # 0xa030
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rcx
subq %rsi, %rdx
cvtsi2sd %rdx, %xmm2
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x746a(%rip), %xmm3     # 0xa018
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x743f(%rip), %xmm1     # 0xa010
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x2bf3
jmp 0x2c87
movq -0x30(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jbe 0x2c11
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x2110
cmpq $-0x1, %rax
jne 0x2c60
jmp 0x2c29
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2c4e
leaq 0x7579(%rip), %rdi      # 0xa1b3
movb $0x0, %al
callq 0x7ba0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2c5c
leaq 0x755e(%rip), %rdi      # 0xa1b3
movb $0x0, %al
callq 0x7df0
jmp 0x2c5e
jmp 0x2c9b
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
ja 0x2b27
movl $0x0, -0x4(%rbp)
jmp 0x2ca2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)