// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]spiped/perftests/send-zeros/main.c
// Function: main
int
main(int argc, char ** argv)
{
	/* Command-line parameters. */
	const char * addr;
	size_t buflen;
	size_t count;

	/* Working variables. */
	struct sock_addr ** sas_t;
	struct timeval begin, end;
	double duration_s;
	char * buffer;
	int socket;
	size_t to_send;

	WARNP_INIT;

	/* Parse command-line arguments. */
	if (argc != 4) {
		warn0("usage: %s ADDRESS BUFLEN COUNT", argv[0]);
		goto err0;
	}
	addr = argv[1];
	if (PARSENUM(&buflen, argv[2], 1, SSIZE_MAX)) {
		warnp("parsenum");
		goto err0;
	}
	if (PARSENUM(&count, argv[3], 1, SIZE_MAX)) {
		warnp("parsenum");
		goto err0;
	}

	/* Allocate and fill buffer to send. */
	if ((buffer = malloc(buflen)) == NULL) {
		warnp("Out of memory");
		goto err0;
	}
	memset(buffer, 0, buflen);

	/* Initialize count. */
	to_send = count;

	/* Resolve target address. */
	if ((sas_t = sock_resolve(addr)) == NULL) {
		warnp("Error resolving socket address: %s", addr);
		goto err1;
	}
	if (sas_t[0] == NULL) {
		warn0("No addresses found for %s", addr);
		goto err2;
	}

	/* Connect to target. */
	if ((socket = sock_connect(sas_t)) == -1) {
		warnp("sock_connect");
		goto err2;
	}

	/* Make it blocking. */
	if (fcntl(socket, F_SETFL,
	    fcntl(socket, F_GETFL, 0) & (~O_NONBLOCK)) == -1) {
		warnp("Cannot make connection blocking");
		goto err3;
	}

	/* Get beginning time. */
	if (monoclock_get(&begin)) {
		warn0("monoclock_get");
		goto err3;
	}

	/* Send data. */
	while (to_send > 0) {
		if (write(socket, buffer, buflen) != (ssize_t)buflen) {
			warnp("write failed");
			goto err3;
		}
		to_send--;
	}

	/* We're not going to send anything else. */
	if (shutdown(socket, SHUT_WR)) {
		warnp("shutdown");
		goto err3;
	}

	/*
	 * The server should not send any data back, but attempting to read
	 * will detect when the other end of the socket is closed.
	 */
	if (read(socket, buffer, 1) != 0) {
		warnp("read");
		goto err3;
	}

	/* Get ending time. */
	if (monoclock_get(&end)) {
		warn0("monoclock_get");
		goto err3;
	}

	/* Print duration and speed. */
	duration_s = timeval_diff(begin, end);
	printf("%zu\t%zu\t%.4f\t%.2f\n", buflen, count, duration_s,
	    (double)(buflen * count) / duration_s / 1e6);

	/* Clean up. */
	if (close(socket)) {
		warnp("close");
		goto err2;
	}
	sock_addr_freelist(sas_t);
	free(buffer);

	/* Success! */
	exit(0);

err3:
	if (close(socket))
		warnp("close");
err2:
	sock_addr_freelist(sas_t);
err1:
	free(buffer);
err0:
	/* Failure! */
	exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x241c
callq 0x3844
cmpl $0x4, %ebp
jne 0x2485
movq 0x8(%rbx), %rbp
callq 0x2080
movq %rax, %r14
andl $0x0, (%rax)
movq 0x10(%rbx), %rdi
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
callq 0x2750
cmpl $0x0, (%r14)
jne 0x24a0
movq %rax, %r12
movq 0x18(%rbx), %rdi
pushq $-0x1
popq %r15
movq %r15, %rsi
callq 0x2750
cmpl $0x0, (%r14)
jne 0x24a0
movq %rax, %r13
pushq $0x1
popq %rdi
movq %r12, %rsi
callq 0x21b0
testq %rax, %rax
jne 0x24ba
leaq 0x1bec(%rip), %rdi      # 0x4068
xorl %eax, %eax
callq 0x3a50
jmp 0x24b2
movq (%rbx), %rsi
leaq 0x1bb1(%rip), %rdi      # 0x4040
xorl %eax, %eax
callq 0x3a50
callq 0x2080
andl $0x0, (%rax)
jmp 0x24b2
leaq 0x1bb8(%rip), %rdi      # 0x405f
xorl %eax, %eax
callq 0x38c1
andl $0x0, (%r14)
pushq $0x1
popq %rdi
callq 0x2280
movq %rax, %rbx
movq %rbp, %rdi
callq 0x29cc
testq %rax, %rax
jne 0x24e6
cmpl $0x0, (%r14)
jne 0x2506
leaq 0x1b9f(%rip), %rdi      # 0x4076
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3a50
jmp 0x26fb
cmpq $0x0, (%rax)
movq %rax, (%rsp)
jne 0x2520
leaq 0x1ba2(%rip), %rdi      # 0x4099
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3a50
jmp 0x26ee
leaq 0x1b69(%rip), %rdi      # 0x4076
movq %rbp, %rsi
xorl %eax, %eax
callq 0x38c1
andl $0x0, (%r14)
jmp 0x26fb
movq %rax, %rdi
callq 0x31a5
cmpl $-0x1, %eax
jne 0x253f
cmpl $0x0, (%r14)
jne 0x2580
leaq 0x1b79(%rip), %rdi      # 0x40b3
jmp 0x26d7
movl %eax, %ebp
pushq $0x3
popq %rsi
movl %eax, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20c0
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
pushq $0x4
popq %rsi
movl %ebp, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x20c0
cmpl $-0x1, %eax
jne 0x258c
cmpl $0x0, (%r14)
jne 0x25cb
leaq 0x1b4c(%rip), %rdi      # 0x40c0
xorl %eax, %eax
callq 0x3a50
jmp 0x26bf
leaq 0x1b2c(%rip), %rdi      # 0x40b3
jmp 0x26e7
leaq 0x18(%rsp), %rdi
callq 0x27d0
testl %eax, %eax
jne 0x26ad
incq %r15
cmpq %r15, %r13
je 0x25de
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x20e0
cmpq %r12, %rax
je 0x259e
cmpl $0x0, (%r14)
jne 0x271a
leaq 0x1b25(%rip), %rdi      # 0x40ee
jmp 0x2574
leaq 0x1aee(%rip), %rdi      # 0x40c0
xorl %eax, %eax
callq 0x38c1
jmp 0x26bb
pushq $0x1
popq %rsi
movl %ebp, %edi
callq 0x20f0
testl %eax, %eax
jne 0x2708
pushq $0x1
popq %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x21a0
testq %rax, %rax
jne 0x2726
leaq 0x8(%rsp), %rdi
callq 0x27d0
testl %eax, %eax
jne 0x26ad
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
subq 0x18(%rsp), %rax
cvtsi2sd %rax, %xmm1
subq 0x20(%rsp), %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x19ca(%rip), %xmm0     # 0x4008
addsd %xmm1, %xmm0
movq %r13, %rax
imulq %r12, %rax
movq %rax, %xmm2
punpckldq 0x19ca(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x19d2(%rip), %xmm2     # 0x4030
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm0, %xmm1
divsd 0x199a(%rip), %xmm1     # 0x4010
leaq 0x1a8c(%rip), %rdi      # 0x4109
movq %r12, %rsi
movq %r13, %rdx
movb $0x2, %al
callq 0x2120
movl %ebp, %edi
callq 0x2170
testl %eax, %eax
jne 0x26ca
movq (%rsp), %rdi
callq 0x2fcb
movq %rbx, %rdi
callq 0x2040
xorl %edi, %edi
callq 0x2280
leaq 0x1a2c(%rip), %rdi      # 0x40e0
xorl %eax, %eax
callq 0x3a50
andl $0x0, (%r14)
movl %ebp, %edi
callq 0x2170
testl %eax, %eax
je 0x26f2
cmpl $0x0, (%r14)
jne 0x26e0
leaq 0x1a45(%rip), %rdi      # 0x411c
xorl %eax, %eax
callq 0x3a50
jmp 0x26f2
leaq 0x1a35(%rip), %rdi      # 0x411c
xorl %eax, %eax
callq 0x38c1
andl $0x0, (%r14)
movq (%rsp), %rdi
callq 0x2fcb
movq %rbx, %rdi
callq 0x2040
jmp 0x24b2
cmpl $0x0, (%r14)
jne 0x2738
leaq 0x19e6(%rip), %rdi      # 0x40fb
jmp 0x2574
leaq 0x19cd(%rip), %rdi      # 0x40ee
jmp 0x25d2
cmpl $0x0, (%r14)
jne 0x2744
leaq 0x19d1(%rip), %rdi      # 0x4104
jmp 0x2574
leaq 0x19bc(%rip), %rdi      # 0x40fb
jmp 0x25d2
leaq 0x19b9(%rip), %rdi      # 0x4104
jmp 0x25d2